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:
@@ -6,7 +6,7 @@
|
||||
struct ResourceManifestReader {
|
||||
Storage* storage;
|
||||
Stream* stream;
|
||||
string_t linebuf;
|
||||
FuriString* linebuf;
|
||||
ResourceManifestEntry entry;
|
||||
};
|
||||
|
||||
@@ -16,16 +16,16 @@ ResourceManifestReader* resource_manifest_reader_alloc(Storage* storage) {
|
||||
resource_manifest->storage = storage;
|
||||
resource_manifest->stream = buffered_file_stream_alloc(resource_manifest->storage);
|
||||
memset(&resource_manifest->entry, 0, sizeof(ResourceManifestEntry));
|
||||
string_init(resource_manifest->entry.name);
|
||||
string_init(resource_manifest->linebuf);
|
||||
resource_manifest->entry.name = furi_string_alloc();
|
||||
resource_manifest->linebuf = furi_string_alloc();
|
||||
return resource_manifest;
|
||||
}
|
||||
|
||||
void resource_manifest_reader_free(ResourceManifestReader* resource_manifest) {
|
||||
furi_assert(resource_manifest);
|
||||
|
||||
string_clear(resource_manifest->linebuf);
|
||||
string_clear(resource_manifest->entry.name);
|
||||
furi_string_free(resource_manifest->linebuf);
|
||||
furi_string_free(resource_manifest->entry.name);
|
||||
buffered_file_stream_close(resource_manifest->stream);
|
||||
stream_free(resource_manifest->stream);
|
||||
free(resource_manifest);
|
||||
@@ -45,7 +45,7 @@ bool resource_manifest_reader_open(ResourceManifestReader* resource_manifest, co
|
||||
ResourceManifestEntry* resource_manifest_reader_next(ResourceManifestReader* resource_manifest) {
|
||||
furi_assert(resource_manifest);
|
||||
|
||||
string_reset(resource_manifest->entry.name);
|
||||
furi_string_reset(resource_manifest->entry.name);
|
||||
resource_manifest->entry.type = ResourceManifestEntryTypeUnknown;
|
||||
resource_manifest->entry.size = 0;
|
||||
memset(resource_manifest->entry.hash, 0, sizeof(resource_manifest->entry.hash));
|
||||
@@ -56,9 +56,9 @@ ResourceManifestEntry* resource_manifest_reader_next(ResourceManifestReader* res
|
||||
}
|
||||
|
||||
/* Trim end of line */
|
||||
string_strim(resource_manifest->linebuf);
|
||||
furi_string_trim(resource_manifest->linebuf);
|
||||
|
||||
char type_code = string_get_char(resource_manifest->linebuf, 0);
|
||||
char type_code = furi_string_get_char(resource_manifest->linebuf, 0);
|
||||
switch(type_code) {
|
||||
case 'F':
|
||||
resource_manifest->entry.type = ResourceManifestEntryTypeFile;
|
||||
@@ -75,9 +75,9 @@ ResourceManifestEntry* resource_manifest_reader_next(ResourceManifestReader* res
|
||||
F:<hash>:<size>:<name> */
|
||||
|
||||
/* Remove entry type code */
|
||||
string_right(resource_manifest->linebuf, 2);
|
||||
furi_string_right(resource_manifest->linebuf, 2);
|
||||
|
||||
if(string_search_char(resource_manifest->linebuf, ':') !=
|
||||
if(furi_string_search_char(resource_manifest->linebuf, ':') !=
|
||||
sizeof(resource_manifest->entry.hash) * 2) {
|
||||
/* Invalid hash */
|
||||
continue;
|
||||
@@ -85,27 +85,27 @@ ResourceManifestEntry* resource_manifest_reader_next(ResourceManifestReader* res
|
||||
|
||||
/* Read hash */
|
||||
hex_chars_to_uint8(
|
||||
string_get_cstr(resource_manifest->linebuf), resource_manifest->entry.hash);
|
||||
furi_string_get_cstr(resource_manifest->linebuf), resource_manifest->entry.hash);
|
||||
|
||||
/* Remove hash */
|
||||
string_right(
|
||||
furi_string_right(
|
||||
resource_manifest->linebuf, sizeof(resource_manifest->entry.hash) * 2 + 1);
|
||||
|
||||
resource_manifest->entry.size = atoi(string_get_cstr(resource_manifest->linebuf));
|
||||
resource_manifest->entry.size = atoi(furi_string_get_cstr(resource_manifest->linebuf));
|
||||
|
||||
/* Remove size */
|
||||
size_t offs = string_search_char(resource_manifest->linebuf, ':');
|
||||
string_right(resource_manifest->linebuf, offs + 1);
|
||||
size_t offs = furi_string_search_char(resource_manifest->linebuf, ':');
|
||||
furi_string_right(resource_manifest->linebuf, offs + 1);
|
||||
|
||||
string_set(resource_manifest->entry.name, resource_manifest->linebuf);
|
||||
furi_string_set(resource_manifest->entry.name, resource_manifest->linebuf);
|
||||
} else if(resource_manifest->entry.type == ResourceManifestEntryTypeDirectory) {
|
||||
/* Parse directory entry
|
||||
D:<name> */
|
||||
|
||||
/* Remove entry type code */
|
||||
string_right(resource_manifest->linebuf, 2);
|
||||
furi_string_right(resource_manifest->linebuf, 2);
|
||||
|
||||
string_set(resource_manifest->entry.name, resource_manifest->linebuf);
|
||||
furi_string_set(resource_manifest->entry.name, resource_manifest->linebuf);
|
||||
}
|
||||
|
||||
return &resource_manifest->entry;
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <storage/storage.h>
|
||||
|
||||
#include <m-string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -18,7 +17,7 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
ResourceManifestEntryType type;
|
||||
string_t name;
|
||||
FuriString* name;
|
||||
uint32_t size;
|
||||
uint8_t hash[16];
|
||||
} ResourceManifestEntry;
|
||||
|
Reference in New Issue
Block a user