BSB Developer Docs
Loading...
Searching...
No Matches
path.h File Reference

Filesystem path utilities. More...

#include <core/string.h>

Go to the source code of this file.

Functions

void path_extract_filename_no_ext (const char *path, FuriString *filename)
 Extract filename without extension from path.
 
void path_extract_filename (FuriString *path, FuriString *filename, bool trim_ext)
 Extract filename string from path.
 
void path_extract_extension (FuriString *path, char *ext, size_t ext_len_max)
 Extract file extension from path.
 
void path_extract_basename (const char *path, FuriString *basename)
 Extract last path component.
 
void path_extract_dirname (const char *path, FuriString *dirname)
 Extract path, except for last component.
 
void path_append (FuriString *path, const char *suffix)
 Appends new component to path, adding path delimiter.
 
void path_concat (const char *path, const char *suffix, FuriString *out_path)
 Appends new component to path, adding path delimiter.
 
bool path_contains_only_ascii (const char *path)
 Check that path contains only ascii characters.
 
void path_normalize (const char *path, FuriString *out_path, bool allow_escape_root)
 Normalizes path (resolves current and parent directory references).
 
bool path_replace_prefix (const char *path, const char *old_prefix, const char *new_prefix, FuriString *out_path)
 Replaces an old path prefix with a new one.
 

Detailed Description

Filesystem path utilities.

Function Documentation

◆ path_append()

void path_append ( FuriString * path,
const char * suffix )

Appends new component to path, adding path delimiter.

Parameters
pathpath string
suffixpath part to apply

◆ path_concat()

void path_concat ( const char * path,
const char * suffix,
FuriString * out_path )

Appends new component to path, adding path delimiter.

Parameters
pathfirst path part
suffixsecond path part
out_pathoutput string to combine parts into. Must be initialized

◆ path_contains_only_ascii()

bool path_contains_only_ascii ( const char * path)

Check that path contains only ascii characters.

Parameters
path
Returns
true if the paths contains only ASCII characters, false otherwise

◆ path_extract_basename()

void path_extract_basename ( const char * path,
FuriString * basename )

Extract last path component.

Parameters
pathpath string
basenameoutput string. Must be initialized before.

◆ path_extract_dirname()

void path_extract_dirname ( const char * path,
FuriString * dirname )

Extract path, except for last component.

Parameters
pathpath string
dirnameoutput string. Must be initialized before.

◆ path_extract_extension()

void path_extract_extension ( FuriString * path,
char * ext,
size_t ext_len_max )

Extract file extension from path.

Parameters
pathpath string
extoutput extension string
ext_len_maxmaximum extension string length

◆ path_extract_filename()

void path_extract_filename ( FuriString * path,
FuriString * filename,
bool trim_ext )

Extract filename string from path.

Parameters
pathpath string
filenameoutput filename string. Must be initialized before.
trim_exttrue - get filename without extension

◆ path_extract_filename_no_ext()

void path_extract_filename_no_ext ( const char * path,
FuriString * filename )

Extract filename without extension from path.

Parameters
pathpath string
filenameoutput filename string. Must be initialized before.

◆ path_normalize()

void path_normalize ( const char * path,
FuriString * out_path,
bool allow_escape_root )

Normalizes path (resolves current and parent directory references).

Parameters
pathpath to normalize
out_pathoutput string to normalize path into. Must be initialized
allow_escape_rootif true, resulting paths can reference parents of current directory.
path_normalize("a/../../b", out_path, true); // produces "../b"
path_normalize("a/../../b", out_path, false); // produces "b"

◆ path_replace_prefix()

bool path_replace_prefix ( const char * path,
const char * old_prefix,
const char * new_prefix,
FuriString * out_path )

Replaces an old path prefix with a new one.

Parameters
[in]pathinput path
[in]old_prefixprefix to be replaced
[in]new_prefixnew prefix to be used
[in,out]out_pathpointer to the path output string (must be allocated)
Returns
true on success, false if path does not start with old_prefix
path_replace_prefix("/a/b/c/foo", "/a/b", "/g", out_path); // produces "/g/c/foo"
path_replace_prefix("/a/bar/c/foo", "/a/b", "/g", out_path); // returns false