HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Files
Path handling utilities.

Files

file  glob.hpp
 Defines utilities for handling glob patterns.
 
file  path_location.hpp
 functions to locate files and directories.
 

Detailed Description

This module contains file handling utilities:

Path locations

The path-locations functions are used to find files and directories based on the context of the operating system, the user account and application.

For example fonts are located in multiple places:

To iterate over all the font directories:

for (auto const &path : hi::get_paths(path_location::font_dirs)) {
std::cout << path.string() << std::endl;
}
path_location
File and Directory locations.
Definition path_location_intf.hpp:24
generator< std::filesystem::path > get_paths(path_location location)
Get a set of paths.
@ font_dirs
The directories where the fonts for the system and resource fonts are located.
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
T endl(T... args)

To find the first matching file in one of the font directories:

if (auto const &path : hi::find_path(path_location::font_dirs, "arial.ttf")) {
std::cout << path->string() << std::endl;
}
std::optional< std::filesystem::path > find_path(path_location location, std::filesystem::path const &ref) noexcept
Find a path.
Definition path_location_intf.hpp:86

glob

To find files based on a pattern using wild cards like * you can use the glob utilities.

The constructor of the glob_pattern object parses a string or std::filesystem::path which contain one or more of the following tokens:

Token Description
foo Matches the text "foo".
? Matches any single character except '/'.
[abcd] Matches a single character that is 'a', 'b', 'c' or 'd'.
[a-d] Matches a single character that is 'a', 'b', 'c' or 'd'.
[-a-d] Matches a single character that is '-', 'a', 'b', 'c' or 'd'.
{foo,bar,baz} Matches the text "foo", "bar" or "baz".
* Matches zero or more character except '/'.
/‍**‍/ Matches one or more directories. A single slash or zero or more characters between two slashes.

Then the glob() function will search for files and directories matching this pattern. glob() is also overloaded to directly parse a pattern and combine it with path_location.

For example to find all the files in the font directories:

for (auto const &path : hi::glob(path_location::font_dirs, "**&zwj;/&zwj;
*.ttf ")) {
<< path.string() << std::endl;
}
generator< std::filesystem::path > glob(glob_pattern pattern)
Find paths on the filesystem that match the glob pattern.
Definition glob.hpp:879

URL / URI

The URI, URL and URN terms can be confusing, here is a short explanation.

HikoGUI currently implements dereferencing of the following types of URLs:

Both file: and resource: URLs may be implicitly converted to a std::filesystem::path.