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:
Sergey Gavrilov
2022-10-06 01:15:23 +10:00
committed by GitHub
parent 0f9ea925d3
commit 4bf29827f8
370 changed files with 5597 additions and 3963 deletions

View File

@@ -5,7 +5,7 @@ LIST_DEF(DirIndexList, uint32_t);
struct DirWalk {
File* file;
string_t path;
FuriString* path;
DirIndexList_t index_list;
uint32_t current_index;
bool recursive;
@@ -15,7 +15,7 @@ struct DirWalk {
DirWalk* dir_walk_alloc(Storage* storage) {
DirWalk* dir_walk = malloc(sizeof(DirWalk));
string_init(dir_walk->path);
dir_walk->path = furi_string_alloc();
dir_walk->file = storage_file_alloc(storage);
DirIndexList_init(dir_walk->index_list);
dir_walk->recursive = true;
@@ -25,7 +25,7 @@ DirWalk* dir_walk_alloc(Storage* storage) {
void dir_walk_free(DirWalk* dir_walk) {
storage_file_free(dir_walk->file);
string_clear(dir_walk->path);
furi_string_free(dir_walk->path);
DirIndexList_clear(dir_walk->index_list);
free(dir_walk);
}
@@ -40,7 +40,7 @@ void dir_walk_set_filter_cb(DirWalk* dir_walk, DirWalkFilterCb cb, void* context
}
bool dir_walk_open(DirWalk* dir_walk, const char* path) {
string_set(dir_walk->path, path);
furi_string_set(dir_walk->path, path);
dir_walk->current_index = 0;
return storage_dir_open(dir_walk->file, path);
}
@@ -53,7 +53,8 @@ static bool dir_walk_filter(DirWalk* dir_walk, const char* name, FileInfo* filei
}
}
static DirWalkResult dir_walk_iter(DirWalk* dir_walk, string_t return_path, FileInfo* fileinfo) {
static DirWalkResult
dir_walk_iter(DirWalk* dir_walk, FuriString* return_path, FileInfo* fileinfo) {
DirWalkResult result = DirWalkError;
char* name = malloc(256); // FIXME: remove magic number
FileInfo info;
@@ -68,7 +69,8 @@ static DirWalkResult dir_walk_iter(DirWalk* dir_walk, string_t return_path, File
if(dir_walk_filter(dir_walk, name, &info)) {
if(return_path != NULL) {
string_printf(return_path, "%s/%s", string_get_cstr(dir_walk->path), name);
furi_string_printf(
return_path, "%s/%s", furi_string_get_cstr(dir_walk->path), name);
}
if(fileinfo != NULL) {
@@ -84,8 +86,8 @@ static DirWalkResult dir_walk_iter(DirWalk* dir_walk, string_t return_path, File
dir_walk->current_index = 0;
storage_dir_close(dir_walk->file);
string_cat_printf(dir_walk->path, "/%s", name);
storage_dir_open(dir_walk->file, string_get_cstr(dir_walk->path));
furi_string_cat_printf(dir_walk->path, "/%s", name);
storage_dir_open(dir_walk->file, furi_string_get_cstr(dir_walk->path));
}
} else if(storage_file_get_error(dir_walk->file) == FSE_NOT_EXIST) {
if(DirIndexList_size(dir_walk->index_list) == 0) {
@@ -100,12 +102,12 @@ static DirWalkResult dir_walk_iter(DirWalk* dir_walk, string_t return_path, File
storage_dir_close(dir_walk->file);
size_t last_char = string_search_rchar(dir_walk->path, '/');
if(last_char != STRING_FAILURE) {
string_left(dir_walk->path, last_char);
size_t last_char = furi_string_search_rchar(dir_walk->path, '/');
if(last_char != FURI_STRING_FAILURE) {
furi_string_left(dir_walk->path, last_char);
}
storage_dir_open(dir_walk->file, string_get_cstr(dir_walk->path));
storage_dir_open(dir_walk->file, furi_string_get_cstr(dir_walk->path));
// rewind
while(true) {
@@ -137,7 +139,7 @@ FS_Error dir_walk_get_error(DirWalk* dir_walk) {
return storage_file_get_error(dir_walk->file);
}
DirWalkResult dir_walk_read(DirWalk* dir_walk, string_t return_path, FileInfo* fileinfo) {
DirWalkResult dir_walk_read(DirWalk* dir_walk, FuriString* return_path, FileInfo* fileinfo) {
return dir_walk_iter(dir_walk, return_path, fileinfo);
}
@@ -147,6 +149,6 @@ void dir_walk_close(DirWalk* dir_walk) {
}
DirIndexList_reset(dir_walk->index_list);
string_reset(dir_walk->path);
furi_string_reset(dir_walk->path);
dir_walk->current_index = 0;
}