M*LIB: non-inlined strings, FuriString primitive (#1795)
* Quicksave 1 * Header stage complete * Source stage complete * Lint & merge fixes * Includes * Documentation step 1 * FBT: output free size considering BT STACK * Documentation step 2 * py lint * Fix music player plugin * unit test stage 1: string allocator, mem, getters, setters, appends, compare, search. * unit test: string equality * unit test: string replace * unit test: string start_with, end_with * unit test: string trim * unit test: utf-8 * Rename * Revert fw_size changes * Simplify CLI backspace handling * Simplify CLI character insert * Merge fixes * Furi: correct filenaming and spelling * Bt: remove furi string include Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -1,86 +1,85 @@
|
||||
#include "path.h"
|
||||
#include "m-string.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void path_extract_filename_no_ext(const char* path, string_t filename) {
|
||||
string_set(filename, path);
|
||||
void path_extract_filename_no_ext(const char* path, FuriString* filename) {
|
||||
furi_string_set(filename, path);
|
||||
|
||||
size_t start_position = string_search_rchar(filename, '/');
|
||||
size_t end_position = string_search_rchar(filename, '.');
|
||||
size_t start_position = furi_string_search_rchar(filename, '/');
|
||||
size_t end_position = furi_string_search_rchar(filename, '.');
|
||||
|
||||
if(start_position == STRING_FAILURE) {
|
||||
if(start_position == FURI_STRING_FAILURE) {
|
||||
start_position = 0;
|
||||
} else {
|
||||
start_position += 1;
|
||||
}
|
||||
|
||||
if(end_position == STRING_FAILURE) {
|
||||
end_position = string_size(filename);
|
||||
if(end_position == FURI_STRING_FAILURE) {
|
||||
end_position = furi_string_size(filename);
|
||||
}
|
||||
|
||||
string_mid(filename, start_position, end_position - start_position);
|
||||
furi_string_mid(filename, start_position, end_position - start_position);
|
||||
}
|
||||
|
||||
void path_extract_filename(string_t path, string_t name, bool trim_ext) {
|
||||
size_t filename_start = string_search_rchar(path, '/');
|
||||
void path_extract_filename(FuriString* path, FuriString* name, bool trim_ext) {
|
||||
size_t filename_start = furi_string_search_rchar(path, '/');
|
||||
if(filename_start > 0) {
|
||||
filename_start++;
|
||||
string_set_n(name, path, filename_start, string_size(path) - filename_start);
|
||||
furi_string_set_n(name, path, filename_start, furi_string_size(path) - filename_start);
|
||||
}
|
||||
if(trim_ext) {
|
||||
size_t dot = string_search_rchar(name, '.');
|
||||
size_t dot = furi_string_search_rchar(name, '.');
|
||||
if(dot > 0) {
|
||||
string_left(name, dot);
|
||||
furi_string_left(name, dot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void path_extract_extension(string_t path, char* ext, size_t ext_len_max) {
|
||||
size_t dot = string_search_rchar(path, '.');
|
||||
size_t filename_start = string_search_rchar(path, '/');
|
||||
void path_extract_extension(FuriString* path, char* ext, size_t ext_len_max) {
|
||||
size_t dot = furi_string_search_rchar(path, '.');
|
||||
size_t filename_start = furi_string_search_rchar(path, '/');
|
||||
|
||||
if((dot > 0) && (filename_start < dot)) {
|
||||
strlcpy(ext, &(string_get_cstr(path))[dot], ext_len_max);
|
||||
strlcpy(ext, &(furi_string_get_cstr(path))[dot], ext_len_max);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void path_cleanup(string_t path) {
|
||||
string_strim(path);
|
||||
while(string_end_with_str_p(path, "/")) {
|
||||
string_left(path, string_size(path) - 1);
|
||||
static inline void path_cleanup(FuriString* path) {
|
||||
furi_string_trim(path);
|
||||
while(furi_string_end_with(path, "/")) {
|
||||
furi_string_left(path, furi_string_size(path) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void path_extract_basename(const char* path, string_t basename) {
|
||||
string_set(basename, path);
|
||||
void path_extract_basename(const char* path, FuriString* basename) {
|
||||
furi_string_set(basename, path);
|
||||
path_cleanup(basename);
|
||||
size_t pos = string_search_rchar(basename, '/');
|
||||
if(pos != STRING_FAILURE) {
|
||||
string_right(basename, pos + 1);
|
||||
size_t pos = furi_string_search_rchar(basename, '/');
|
||||
if(pos != FURI_STRING_FAILURE) {
|
||||
furi_string_right(basename, pos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void path_extract_dirname(const char* path, string_t dirname) {
|
||||
string_set(dirname, path);
|
||||
void path_extract_dirname(const char* path, FuriString* dirname) {
|
||||
furi_string_set(dirname, path);
|
||||
path_cleanup(dirname);
|
||||
size_t pos = string_search_rchar(dirname, '/');
|
||||
if(pos != STRING_FAILURE) {
|
||||
string_left(dirname, pos);
|
||||
size_t pos = furi_string_search_rchar(dirname, '/');
|
||||
if(pos != FURI_STRING_FAILURE) {
|
||||
furi_string_left(dirname, pos);
|
||||
}
|
||||
}
|
||||
|
||||
void path_append(string_t path, const char* suffix) {
|
||||
void path_append(FuriString* path, const char* suffix) {
|
||||
path_cleanup(path);
|
||||
string_t suffix_str;
|
||||
string_init_set(suffix_str, suffix);
|
||||
string_strim(suffix_str);
|
||||
string_strim(suffix_str, "/");
|
||||
string_cat_printf(path, "/%s", string_get_cstr(suffix_str));
|
||||
string_clear(suffix_str);
|
||||
FuriString* suffix_str;
|
||||
suffix_str = furi_string_alloc_set(suffix);
|
||||
furi_string_trim(suffix_str);
|
||||
furi_string_trim(suffix_str, "/");
|
||||
furi_string_cat_printf(path, "/%s", furi_string_get_cstr(suffix_str));
|
||||
furi_string_free(suffix_str);
|
||||
}
|
||||
|
||||
void path_concat(const char* path, const char* suffix, string_t out_path) {
|
||||
string_set(out_path, path);
|
||||
void path_concat(const char* path, const char* suffix, FuriString* out_path) {
|
||||
furi_string_set(out_path, path);
|
||||
path_append(out_path, suffix);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user