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++) {
|
||||
|
||||
Reference in New Issue
Block a user