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,60 +1,60 @@
|
||||
#include "args.h"
|
||||
#include "hex.h"
|
||||
|
||||
size_t args_get_first_word_length(string_t args) {
|
||||
size_t ws = string_search_char(args, ' ');
|
||||
if(ws == STRING_FAILURE) {
|
||||
ws = string_size(args);
|
||||
size_t args_get_first_word_length(FuriString* args) {
|
||||
size_t ws = furi_string_search_char(args, ' ');
|
||||
if(ws == FURI_STRING_FAILURE) {
|
||||
ws = furi_string_size(args);
|
||||
}
|
||||
|
||||
return ws;
|
||||
}
|
||||
|
||||
size_t args_length(string_t args) {
|
||||
return string_size(args);
|
||||
size_t args_length(FuriString* args) {
|
||||
return furi_string_size(args);
|
||||
}
|
||||
|
||||
bool args_read_int_and_trim(string_t args, int* value) {
|
||||
bool args_read_int_and_trim(FuriString* args, int* value) {
|
||||
size_t cmd_length = args_get_first_word_length(args);
|
||||
|
||||
if(cmd_length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(sscanf(string_get_cstr(args), "%d", value) == 1) {
|
||||
string_right(args, cmd_length);
|
||||
string_strim(args);
|
||||
if(sscanf(furi_string_get_cstr(args), "%d", value) == 1) {
|
||||
furi_string_right(args, cmd_length);
|
||||
furi_string_trim(args);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool args_read_string_and_trim(string_t args, string_t word) {
|
||||
bool args_read_string_and_trim(FuriString* args, FuriString* word) {
|
||||
size_t cmd_length = args_get_first_word_length(args);
|
||||
|
||||
if(cmd_length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
string_set_n(word, args, 0, cmd_length);
|
||||
string_right(args, cmd_length);
|
||||
string_strim(args);
|
||||
furi_string_set_n(word, args, 0, cmd_length);
|
||||
furi_string_right(args, cmd_length);
|
||||
furi_string_trim(args);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool args_read_probably_quoted_string_and_trim(string_t args, string_t word) {
|
||||
if(string_size(args) > 1 && string_get_char(args, 0) == '\"') {
|
||||
size_t second_quote_pos = string_search_char(args, '\"', 1);
|
||||
bool args_read_probably_quoted_string_and_trim(FuriString* args, FuriString* word) {
|
||||
if(furi_string_size(args) > 1 && furi_string_get_char(args, 0) == '\"') {
|
||||
size_t second_quote_pos = furi_string_search_char(args, '\"', 1);
|
||||
|
||||
if(second_quote_pos == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
string_set_n(word, args, 1, second_quote_pos - 1);
|
||||
string_right(args, second_quote_pos + 1);
|
||||
string_strim(args);
|
||||
furi_string_set_n(word, args, 1, second_quote_pos - 1);
|
||||
furi_string_right(args, second_quote_pos + 1);
|
||||
furi_string_trim(args);
|
||||
return true;
|
||||
} else {
|
||||
return args_read_string_and_trim(args, word);
|
||||
@@ -76,9 +76,9 @@ bool args_char_to_hex(char hi_nibble, char low_nibble, uint8_t* byte) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool args_read_hex_bytes(string_t args, uint8_t* bytes, size_t bytes_count) {
|
||||
bool args_read_hex_bytes(FuriString* args, uint8_t* bytes, size_t bytes_count) {
|
||||
bool result = true;
|
||||
const char* str_pointer = string_get_cstr(args);
|
||||
const char* str_pointer = furi_string_get_cstr(args);
|
||||
|
||||
if(args_get_first_word_length(args) == (bytes_count * 2)) {
|
||||
for(size_t i = 0; i < bytes_count; i++) {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <m-string.h>
|
||||
#include <furi.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -15,7 +15,7 @@ extern "C" {
|
||||
* @return true - success
|
||||
* @return false - arguments string does not contain int
|
||||
*/
|
||||
bool args_read_int_and_trim(string_t args, int* value);
|
||||
bool args_read_int_and_trim(FuriString* args, int* value);
|
||||
|
||||
/**
|
||||
* @brief Extract first argument from arguments string and trim arguments string
|
||||
@@ -25,7 +25,7 @@ bool args_read_int_and_trim(string_t args, int* value);
|
||||
* @return true - success
|
||||
* @return false - arguments string does not contain anything
|
||||
*/
|
||||
bool args_read_string_and_trim(string_t args, string_t word);
|
||||
bool args_read_string_and_trim(FuriString* args, FuriString* word);
|
||||
|
||||
/**
|
||||
* @brief Extract the first quoted argument from the argument string and trim the argument string. If the argument is not quoted, calls args_read_string_and_trim.
|
||||
@@ -35,7 +35,7 @@ bool args_read_string_and_trim(string_t args, string_t word);
|
||||
* @return true - success
|
||||
* @return false - arguments string does not contain anything
|
||||
*/
|
||||
bool args_read_probably_quoted_string_and_trim(string_t args, string_t word);
|
||||
bool args_read_probably_quoted_string_and_trim(FuriString* args, FuriString* word);
|
||||
|
||||
/**
|
||||
* @brief Convert hex ASCII values to byte array
|
||||
@@ -46,7 +46,7 @@ bool args_read_probably_quoted_string_and_trim(string_t args, string_t word);
|
||||
* @return true - success
|
||||
* @return false - arguments string does not contain enough values, or contain non-hex ASCII values
|
||||
*/
|
||||
bool args_read_hex_bytes(string_t args, uint8_t* bytes, size_t bytes_count);
|
||||
bool args_read_hex_bytes(FuriString* args, uint8_t* bytes, size_t bytes_count);
|
||||
|
||||
/************************************ HELPERS ***************************************/
|
||||
|
||||
@@ -56,7 +56,7 @@ bool args_read_hex_bytes(string_t args, uint8_t* bytes, size_t bytes_count);
|
||||
* @param args arguments string
|
||||
* @return size_t length of first word
|
||||
*/
|
||||
size_t args_get_first_word_length(string_t args);
|
||||
size_t args_get_first_word_length(FuriString* args);
|
||||
|
||||
/**
|
||||
* @brief Get length of arguments string
|
||||
@@ -64,7 +64,7 @@ size_t args_get_first_word_length(string_t args);
|
||||
* @param args arguments string
|
||||
* @return size_t length of arguments string
|
||||
*/
|
||||
size_t args_length(string_t args);
|
||||
size_t args_length(FuriString* args);
|
||||
|
||||
/**
|
||||
* @brief Convert ASCII hex values to byte
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ FS_Error dir_walk_get_error(DirWalk* dir_walk);
|
||||
* @param fileinfo
|
||||
* @return DirWalkResult
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Close directory
|
||||
|
@@ -13,5 +13,4 @@
|
||||
HASH(m_core_cstr_hash), \
|
||||
EQUAL(M_CSTR_EQUAL), \
|
||||
CMP(strcmp), \
|
||||
TYPE(const char*), \
|
||||
OUT_STR(M_CSTR_OUT_STR))
|
||||
TYPE(const char*))
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <m-string.h>
|
||||
#include <furi.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -12,7 +11,7 @@ extern "C" {
|
||||
* @param path path string
|
||||
* @param filename output filename string. Must be initialized before.
|
||||
*/
|
||||
void path_extract_filename_no_ext(const char* path, string_t filename);
|
||||
void path_extract_filename_no_ext(const char* path, FuriString* filename);
|
||||
|
||||
/**
|
||||
* @brief Extract filename string from path.
|
||||
@@ -21,7 +20,7 @@ void path_extract_filename_no_ext(const char* path, string_t filename);
|
||||
* @param filename output filename string. Must be initialized before.
|
||||
* @param trim_ext true - get filename without extension
|
||||
*/
|
||||
void path_extract_filename(string_t path, string_t filename, bool trim_ext);
|
||||
void path_extract_filename(FuriString* path, FuriString* filename, bool trim_ext);
|
||||
|
||||
/**
|
||||
* @brief Extract file extension from path.
|
||||
@@ -30,7 +29,7 @@ void path_extract_filename(string_t path, string_t filename, bool trim_ext);
|
||||
* @param ext output extension string
|
||||
* @param ext_len_max maximum extension string length
|
||||
*/
|
||||
void path_extract_extension(string_t path, char* ext, size_t ext_len_max);
|
||||
void path_extract_extension(FuriString* path, char* ext, size_t ext_len_max);
|
||||
|
||||
/**
|
||||
* @brief Extract last path component
|
||||
@@ -38,7 +37,7 @@ void path_extract_extension(string_t path, char* ext, size_t ext_len_max);
|
||||
* @param path path string
|
||||
* @param filename output string. Must be initialized before.
|
||||
*/
|
||||
void path_extract_basename(const char* path, string_t basename);
|
||||
void path_extract_basename(const char* path, FuriString* basename);
|
||||
|
||||
/**
|
||||
* @brief Extract path, except for last component
|
||||
@@ -46,7 +45,7 @@ void path_extract_basename(const char* path, string_t basename);
|
||||
* @param path path string
|
||||
* @param filename output string. Must be initialized before.
|
||||
*/
|
||||
void path_extract_dirname(const char* path, string_t dirname);
|
||||
void path_extract_dirname(const char* path, FuriString* dirname);
|
||||
|
||||
/**
|
||||
* @brief Appends new component to path, adding path delimiter
|
||||
@@ -54,7 +53,7 @@ void path_extract_dirname(const char* path, string_t dirname);
|
||||
* @param path path string
|
||||
* @param suffix path part to apply
|
||||
*/
|
||||
void path_append(string_t path, const char* suffix);
|
||||
void path_append(FuriString* path, const char* suffix);
|
||||
|
||||
/**
|
||||
* @brief Appends new component to path, adding path delimiter
|
||||
@@ -63,7 +62,7 @@ void path_append(string_t path, const char* suffix);
|
||||
* @param suffix second path part
|
||||
* @param out_path output string to combine parts into. Must be initialized
|
||||
*/
|
||||
void path_concat(const char* path, const char* suffix, string_t out_path);
|
||||
void path_concat(const char* path, const char* suffix, FuriString* out_path);
|
||||
|
||||
/**
|
||||
* @brief Check that path contains only ascii characters
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <lib/toolbox/level_duration.h>
|
||||
#include <mlib/m-string.h>
|
||||
#include <furi.h>
|
||||
|
||||
typedef void* (*ProtocolAlloc)(void);
|
||||
typedef void (*ProtocolFree)(void* protocol);
|
||||
@@ -15,7 +15,7 @@ typedef bool (*ProtocolDecoderFeed)(void* protocol, bool level, uint32_t duratio
|
||||
typedef bool (*ProtocolEncoderStart)(void* protocol);
|
||||
typedef LevelDuration (*ProtocolEncoderYield)(void* protocol);
|
||||
|
||||
typedef void (*ProtocolRenderData)(void* protocol, string_t result);
|
||||
typedef void (*ProtocolRenderData)(void* protocol, FuriString* result);
|
||||
typedef bool (*ProtocolWriteData)(void* protocol, void* data);
|
||||
|
||||
typedef struct {
|
||||
|
@@ -185,7 +185,7 @@ LevelDuration protocol_dict_encoder_yield(ProtocolDict* dict, size_t protocol_in
|
||||
}
|
||||
}
|
||||
|
||||
void protocol_dict_render_data(ProtocolDict* dict, string_t result, size_t protocol_index) {
|
||||
void protocol_dict_render_data(ProtocolDict* dict, FuriString* result, size_t protocol_index) {
|
||||
furi_assert(protocol_index < dict->count);
|
||||
ProtocolRenderData fn = dict->base[protocol_index]->render_data;
|
||||
|
||||
@@ -194,7 +194,7 @@ void protocol_dict_render_data(ProtocolDict* dict, string_t result, size_t proto
|
||||
}
|
||||
}
|
||||
|
||||
void protocol_dict_render_brief_data(ProtocolDict* dict, string_t result, size_t protocol_index) {
|
||||
void protocol_dict_render_brief_data(ProtocolDict* dict, FuriString* result, size_t protocol_index) {
|
||||
furi_assert(protocol_index < dict->count);
|
||||
ProtocolRenderData fn = dict->base[protocol_index]->render_brief_data;
|
||||
|
||||
|
@@ -58,9 +58,9 @@ bool protocol_dict_encoder_start(ProtocolDict* dict, size_t protocol_index);
|
||||
|
||||
LevelDuration protocol_dict_encoder_yield(ProtocolDict* dict, size_t protocol_index);
|
||||
|
||||
void protocol_dict_render_data(ProtocolDict* dict, string_t result, size_t protocol_index);
|
||||
void protocol_dict_render_data(ProtocolDict* dict, FuriString* result, size_t protocol_index);
|
||||
|
||||
void protocol_dict_render_brief_data(ProtocolDict* dict, string_t result, size_t protocol_index);
|
||||
void protocol_dict_render_brief_data(ProtocolDict* dict, FuriString* result, size_t protocol_index);
|
||||
|
||||
uint32_t protocol_dict_get_validate_count(ProtocolDict* dict, size_t protocol_index);
|
||||
|
||||
|
@@ -173,17 +173,20 @@ static bool file_stream_delete_and_insert(
|
||||
Stream* scratch_stream = file_stream_alloc(_stream->storage);
|
||||
|
||||
// TODO: we need something like "storage_open_tmpfile and storage_close_tmpfile"
|
||||
string_t scratch_name;
|
||||
string_t tmp_name;
|
||||
string_init(tmp_name);
|
||||
FuriString* scratch_name;
|
||||
FuriString* tmp_name;
|
||||
tmp_name = furi_string_alloc();
|
||||
storage_get_next_filename(
|
||||
_stream->storage, STORAGE_ANY_PATH_PREFIX, ".scratch", ".pad", tmp_name, 255);
|
||||
string_init_printf(scratch_name, ANY_PATH("%s.pad"), string_get_cstr(tmp_name));
|
||||
string_clear(tmp_name);
|
||||
scratch_name = furi_string_alloc_printf(ANY_PATH("%s.pad"), furi_string_get_cstr(tmp_name));
|
||||
furi_string_free(tmp_name);
|
||||
|
||||
do {
|
||||
if(!file_stream_open(
|
||||
scratch_stream, string_get_cstr(scratch_name), FSAM_READ_WRITE, FSOM_CREATE_NEW))
|
||||
scratch_stream,
|
||||
furi_string_get_cstr(scratch_name),
|
||||
FSAM_READ_WRITE,
|
||||
FSOM_CREATE_NEW))
|
||||
break;
|
||||
|
||||
size_t current_position = stream_tell(stream);
|
||||
@@ -225,8 +228,8 @@ static bool file_stream_delete_and_insert(
|
||||
} while(false);
|
||||
|
||||
stream_free(scratch_stream);
|
||||
storage_common_remove(_stream->storage, string_get_cstr(scratch_name));
|
||||
string_clear(scratch_name);
|
||||
storage_common_remove(_stream->storage, furi_string_get_cstr(scratch_name));
|
||||
furi_string_free(scratch_name);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -67,8 +67,8 @@ static bool stream_write_struct(Stream* stream, const void* context) {
|
||||
return (stream_write(stream, write_data->data, write_data->size) == write_data->size);
|
||||
}
|
||||
|
||||
bool stream_read_line(Stream* stream, string_t str_result) {
|
||||
string_reset(str_result);
|
||||
bool stream_read_line(Stream* stream, FuriString* str_result) {
|
||||
furi_string_reset(str_result);
|
||||
const uint8_t buffer_size = 32;
|
||||
uint8_t buffer[buffer_size];
|
||||
|
||||
@@ -84,13 +84,13 @@ bool stream_read_line(Stream* stream, string_t str_result) {
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
string_push_back(str_result, buffer[i]);
|
||||
furi_string_push_back(str_result, buffer[i]);
|
||||
result = true;
|
||||
break;
|
||||
} else if(buffer[i] == '\r') {
|
||||
// Ignore
|
||||
} else {
|
||||
string_push_back(str_result, buffer[i]);
|
||||
furi_string_push_back(str_result, buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ bool stream_read_line(Stream* stream, string_t str_result) {
|
||||
}
|
||||
} while(true);
|
||||
|
||||
return string_size(str_result) != 0;
|
||||
return furi_string_size(str_result) != 0;
|
||||
}
|
||||
|
||||
bool stream_rewind(Stream* stream) {
|
||||
@@ -112,9 +112,10 @@ size_t stream_write_char(Stream* stream, char c) {
|
||||
return stream_write(stream, (const uint8_t*)&c, 1);
|
||||
}
|
||||
|
||||
size_t stream_write_string(Stream* stream, string_t string) {
|
||||
size_t stream_write_string(Stream* stream, FuriString* string) {
|
||||
furi_assert(stream);
|
||||
return stream_write(stream, (const uint8_t*)string_get_cstr(string), string_size(string));
|
||||
return stream_write(
|
||||
stream, (const uint8_t*)furi_string_get_cstr(string), furi_string_size(string));
|
||||
}
|
||||
|
||||
size_t stream_write_cstring(Stream* stream, const char* string) {
|
||||
@@ -134,10 +135,10 @@ size_t stream_write_format(Stream* stream, const char* format, ...) {
|
||||
|
||||
size_t stream_write_vaformat(Stream* stream, const char* format, va_list args) {
|
||||
furi_assert(stream);
|
||||
string_t data;
|
||||
string_init_vprintf(data, format, args);
|
||||
FuriString* data;
|
||||
data = furi_string_alloc_vprintf(format, args);
|
||||
size_t size = stream_write_string(stream, data);
|
||||
string_clear(data);
|
||||
furi_string_free(data);
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -153,7 +154,7 @@ bool stream_insert_char(Stream* stream, char c) {
|
||||
return stream_delete_and_insert_char(stream, 0, c);
|
||||
}
|
||||
|
||||
bool stream_insert_string(Stream* stream, string_t string) {
|
||||
bool stream_insert_string(Stream* stream, FuriString* string) {
|
||||
furi_assert(stream);
|
||||
return stream_delete_and_insert_string(stream, 0, string);
|
||||
}
|
||||
@@ -184,10 +185,10 @@ bool stream_delete_and_insert_char(Stream* stream, size_t delete_size, char c) {
|
||||
return stream_delete_and_insert(stream, delete_size, stream_write_struct, &write_data);
|
||||
}
|
||||
|
||||
bool stream_delete_and_insert_string(Stream* stream, size_t delete_size, string_t string) {
|
||||
bool stream_delete_and_insert_string(Stream* stream, size_t delete_size, FuriString* string) {
|
||||
furi_assert(stream);
|
||||
StreamWriteData write_data = {
|
||||
.data = (uint8_t*)string_get_cstr(string), .size = string_size(string)};
|
||||
.data = (uint8_t*)furi_string_get_cstr(string), .size = furi_string_size(string)};
|
||||
return stream_delete_and_insert(stream, delete_size, stream_write_struct, &write_data);
|
||||
}
|
||||
|
||||
@@ -213,12 +214,12 @@ bool stream_delete_and_insert_vaformat(
|
||||
const char* format,
|
||||
va_list args) {
|
||||
furi_assert(stream);
|
||||
string_t data;
|
||||
string_init_vprintf(data, format, args);
|
||||
FuriString* data;
|
||||
data = furi_string_alloc_vprintf(format, args);
|
||||
StreamWriteData write_data = {
|
||||
.data = (uint8_t*)string_get_cstr(data), .size = string_size(data)};
|
||||
.data = (uint8_t*)furi_string_get_cstr(data), .size = furi_string_size(data)};
|
||||
bool result = stream_delete_and_insert(stream, delete_size, stream_write_struct, &write_data);
|
||||
string_clear(data);
|
||||
furi_string_free(data);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <mlib/m-string.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -105,7 +104,7 @@ bool stream_delete_and_insert(
|
||||
* @return true if line lenght is not zero
|
||||
* @return false otherwise
|
||||
*/
|
||||
bool stream_read_line(Stream* stream, string_t str_result);
|
||||
bool stream_read_line(Stream* stream, FuriString* str_result);
|
||||
|
||||
/**
|
||||
* Moves the rw pointer to the start
|
||||
@@ -127,7 +126,7 @@ size_t stream_write_char(Stream* stream, char c);
|
||||
* @param string string value
|
||||
* @return size_t how many bytes was written
|
||||
*/
|
||||
size_t stream_write_string(Stream* stream, string_t string);
|
||||
size_t stream_write_string(Stream* stream, FuriString* string);
|
||||
|
||||
/**
|
||||
* Write const char* to the stream
|
||||
@@ -182,7 +181,7 @@ bool stream_insert_char(Stream* stream, char c);
|
||||
* @return true if the operation was successful
|
||||
* @return false on error
|
||||
*/
|
||||
bool stream_insert_string(Stream* stream, string_t string);
|
||||
bool stream_insert_string(Stream* stream, FuriString* string);
|
||||
|
||||
/**
|
||||
* Insert const char* to the stream
|
||||
@@ -231,7 +230,7 @@ bool stream_delete_and_insert_char(Stream* stream, size_t delete_size, char c);
|
||||
* @return true if the operation was successful
|
||||
* @return false on error
|
||||
*/
|
||||
bool stream_delete_and_insert_string(Stream* stream, size_t delete_size, string_t string);
|
||||
bool stream_delete_and_insert_string(Stream* stream, size_t delete_size, FuriString* string);
|
||||
|
||||
/**
|
||||
* Delete N chars from the stream and insert const char* to the stream
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
typedef struct {
|
||||
Stream stream_base;
|
||||
string_t string;
|
||||
FuriString* string;
|
||||
size_t index;
|
||||
} StringStream;
|
||||
|
||||
@@ -39,14 +39,14 @@ const StreamVTable string_stream_vtable = {
|
||||
|
||||
Stream* string_stream_alloc() {
|
||||
StringStream* stream = malloc(sizeof(StringStream));
|
||||
string_init(stream->string);
|
||||
stream->string = furi_string_alloc();
|
||||
stream->index = 0;
|
||||
stream->stream_base.vtable = &string_stream_vtable;
|
||||
return (Stream*)stream;
|
||||
}
|
||||
|
||||
static void string_stream_free(StringStream* stream) {
|
||||
string_clear(stream->string);
|
||||
furi_string_free(stream->string);
|
||||
free(stream);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ static bool string_stream_eof(StringStream* stream) {
|
||||
|
||||
static void string_stream_clean(StringStream* stream) {
|
||||
stream->index = 0;
|
||||
string_reset(stream->string);
|
||||
furi_string_reset(stream->string);
|
||||
}
|
||||
|
||||
static bool string_stream_seek(StringStream* stream, int32_t offset, StreamOffset offset_type) {
|
||||
@@ -79,8 +79,8 @@ static bool string_stream_seek(StringStream* stream, int32_t offset, StreamOffse
|
||||
}
|
||||
break;
|
||||
case StreamOffsetFromEnd:
|
||||
if(((int32_t)string_size(stream->string) + offset) >= 0) {
|
||||
stream->index = string_size(stream->string) + offset;
|
||||
if(((int32_t)furi_string_size(stream->string) + offset) >= 0) {
|
||||
stream->index = furi_string_size(stream->string) + offset;
|
||||
} else {
|
||||
result = false;
|
||||
stream->index = 0;
|
||||
@@ -88,7 +88,7 @@ static bool string_stream_seek(StringStream* stream, int32_t offset, StreamOffse
|
||||
break;
|
||||
}
|
||||
|
||||
int32_t diff = (stream->index - string_size(stream->string));
|
||||
int32_t diff = (stream->index - furi_string_size(stream->string));
|
||||
if(diff > 0) {
|
||||
stream->index -= diff;
|
||||
result = false;
|
||||
@@ -102,7 +102,7 @@ static size_t string_stream_tell(StringStream* stream) {
|
||||
}
|
||||
|
||||
static size_t string_stream_size(StringStream* stream) {
|
||||
return string_size(stream->string);
|
||||
return furi_string_size(stream->string);
|
||||
}
|
||||
|
||||
static size_t string_stream_write(StringStream* stream, const char* data, size_t size) {
|
||||
@@ -117,7 +117,7 @@ static size_t string_stream_write(StringStream* stream, const char* data, size_t
|
||||
|
||||
static size_t string_stream_read(StringStream* stream, char* data, size_t size) {
|
||||
size_t write_index = 0;
|
||||
const char* cstr = string_get_cstr(stream->string);
|
||||
const char* cstr = furi_string_get_cstr(stream->string);
|
||||
|
||||
if(!string_stream_eof(stream)) {
|
||||
while(true) {
|
||||
@@ -145,17 +145,17 @@ static bool string_stream_delete_and_insert(
|
||||
remain_size = MIN(delete_size, remain_size);
|
||||
|
||||
if(remain_size != 0) {
|
||||
string_replace_at(stream->string, stream->index, remain_size, "");
|
||||
furi_string_replace_at(stream->string, stream->index, remain_size, "");
|
||||
}
|
||||
}
|
||||
|
||||
if(write_callback) {
|
||||
string_t right;
|
||||
string_init_set(right, &string_get_cstr(stream->string)[stream->index]);
|
||||
string_left(stream->string, string_stream_tell(stream));
|
||||
FuriString* right;
|
||||
right = furi_string_alloc_set(&furi_string_get_cstr(stream->string)[stream->index]);
|
||||
furi_string_left(stream->string, string_stream_tell(stream));
|
||||
result &= write_callback((Stream*)stream, ctx);
|
||||
string_cat(stream->string, right);
|
||||
string_clear(right);
|
||||
furi_string_cat(stream->string, right);
|
||||
furi_string_free(right);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -169,9 +169,9 @@ static bool string_stream_delete_and_insert(
|
||||
*/
|
||||
static size_t string_stream_write_char(StringStream* stream, char c) {
|
||||
if(string_stream_eof(stream)) {
|
||||
string_push_back(stream->string, c);
|
||||
furi_string_push_back(stream->string, c);
|
||||
} else {
|
||||
string_set_char(stream->string, stream->index, c);
|
||||
furi_string_set_char(stream->string, stream->index, c);
|
||||
}
|
||||
stream->index++;
|
||||
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include <stdlib.h>
|
||||
#include <mlib/m-string.h>
|
||||
#include "stream.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -220,14 +220,14 @@ static int archive_extract_foreach_cb(mtar_t* tar, const mtar_header_t* header,
|
||||
return 0;
|
||||
}
|
||||
|
||||
string_t full_extracted_fname;
|
||||
FuriString* full_extracted_fname;
|
||||
if(header->type == MTAR_TDIR) {
|
||||
string_init(full_extracted_fname);
|
||||
full_extracted_fname = furi_string_alloc();
|
||||
path_concat(op_params->work_dir, header->name, full_extracted_fname);
|
||||
|
||||
bool create_res =
|
||||
storage_simply_mkdir(archive->storage, string_get_cstr(full_extracted_fname));
|
||||
string_clear(full_extracted_fname);
|
||||
storage_simply_mkdir(archive->storage, furi_string_get_cstr(full_extracted_fname));
|
||||
furi_string_free(full_extracted_fname);
|
||||
return create_res ? 0 : -1;
|
||||
}
|
||||
|
||||
@@ -238,19 +238,19 @@ static int archive_extract_foreach_cb(mtar_t* tar, const mtar_header_t* header,
|
||||
|
||||
FURI_LOG_D(TAG, "Extracting %d bytes to '%s'", header->size, header->name);
|
||||
|
||||
string_t converted_fname;
|
||||
string_init_set(converted_fname, header->name);
|
||||
FuriString* converted_fname = furi_string_alloc_set(header->name);
|
||||
if(op_params->converter) {
|
||||
op_params->converter(converted_fname);
|
||||
}
|
||||
|
||||
string_init(full_extracted_fname);
|
||||
path_concat(op_params->work_dir, string_get_cstr(converted_fname), full_extracted_fname);
|
||||
full_extracted_fname = furi_string_alloc();
|
||||
path_concat(op_params->work_dir, furi_string_get_cstr(converted_fname), full_extracted_fname);
|
||||
|
||||
bool success = archive_extract_current_file(archive, string_get_cstr(full_extracted_fname));
|
||||
bool success =
|
||||
archive_extract_current_file(archive, furi_string_get_cstr(full_extracted_fname));
|
||||
|
||||
string_clear(converted_fname);
|
||||
string_clear(full_extracted_fname);
|
||||
furi_string_free(converted_fname);
|
||||
furi_string_free(full_extracted_fname);
|
||||
return success ? 0 : -1;
|
||||
}
|
||||
|
||||
@@ -333,32 +333,32 @@ bool tar_archive_add_dir(TarArchive* archive, const char* fs_full_path, const ch
|
||||
break;
|
||||
}
|
||||
|
||||
string_t element_name, element_fs_abs_path;
|
||||
string_init(element_name);
|
||||
string_init(element_fs_abs_path);
|
||||
FuriString* element_name = furi_string_alloc();
|
||||
FuriString* element_fs_abs_path = furi_string_alloc();
|
||||
|
||||
path_concat(fs_full_path, name, element_fs_abs_path);
|
||||
if(strlen(path_prefix)) {
|
||||
path_concat(path_prefix, name, element_name);
|
||||
} else {
|
||||
string_init_set(element_name, name);
|
||||
furi_string_set(element_name, name);
|
||||
}
|
||||
|
||||
if(file_info.flags & FSF_DIRECTORY) {
|
||||
success = tar_archive_dir_add_element(archive, string_get_cstr(element_name)) &&
|
||||
tar_archive_add_dir(
|
||||
archive,
|
||||
string_get_cstr(element_fs_abs_path),
|
||||
string_get_cstr(element_name));
|
||||
success =
|
||||
tar_archive_dir_add_element(archive, furi_string_get_cstr(element_name)) &&
|
||||
tar_archive_add_dir(
|
||||
archive,
|
||||
furi_string_get_cstr(element_fs_abs_path),
|
||||
furi_string_get_cstr(element_name));
|
||||
} else {
|
||||
success = tar_archive_add_file(
|
||||
archive,
|
||||
string_get_cstr(element_fs_abs_path),
|
||||
string_get_cstr(element_name),
|
||||
furi_string_get_cstr(element_fs_abs_path),
|
||||
furi_string_get_cstr(element_name),
|
||||
file_info.size);
|
||||
}
|
||||
string_clear(element_name);
|
||||
string_clear(element_fs_abs_path);
|
||||
furi_string_free(element_name);
|
||||
furi_string_free(element_fs_abs_path);
|
||||
|
||||
if(!success) {
|
||||
break;
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <m-string.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Reference in New Issue
Block a user