Skip to content

Commit

Permalink
M*LIB: non-inlined strings, FuriString primitive (#1795)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
DrZlo13 and skotopes authored Oct 5, 2022
1 parent 0f9ea92 commit 4bf2982
Show file tree
Hide file tree
Showing 370 changed files with 5,599 additions and 3,965 deletions.
12 changes: 6 additions & 6 deletions applications/debug/bt_debug_app/views/bt_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
#include <gui/canvas.h>
#include <gui/elements.h>
#include <m-array.h>
#include <m-string.h>
#include <furi.h>
#include <stdint.h>

struct BtTestParam {
const char* label;
uint8_t current_value_index;
string_t current_value_text;
FuriString* current_value_text;
uint8_t values_count;
BtTestParamChangeCallback change_callback;
void* context;
Expand Down Expand Up @@ -85,7 +84,8 @@ static void bt_test_draw_callback(Canvas* canvas, void* _model) {
canvas_draw_str(canvas, 50, param_text_y, "<");
}

canvas_draw_str(canvas, 61, param_text_y, string_get_cstr(param->current_value_text));
canvas_draw_str(
canvas, 61, param_text_y, furi_string_get_cstr(param->current_value_text));

if(param->current_value_index < (param->values_count - 1)) {
canvas_draw_str(canvas, 113, param_text_y, ">");
Expand Down Expand Up @@ -322,7 +322,7 @@ void bt_test_free(BtTest* bt_test) {
BtTestParamArray_it_t it;
for(BtTestParamArray_it(it, model->params); !BtTestParamArray_end_p(it);
BtTestParamArray_next(it)) {
string_clear(BtTestParamArray_ref(it)->current_value_text);
furi_string_free(BtTestParamArray_ref(it)->current_value_text);
}
BtTestParamArray_clear(model->params);
return false;
Expand Down Expand Up @@ -354,7 +354,7 @@ BtTestParam* bt_test_param_add(
param->change_callback = change_callback;
param->context = context;
param->current_value_index = 0;
string_init(param->current_value_text);
param->current_value_text = furi_string_alloc();
return true;
});

Expand Down Expand Up @@ -410,7 +410,7 @@ void bt_test_set_current_value_index(BtTestParam* param, uint8_t current_value_i
}

void bt_test_set_current_value_text(BtTestParam* param, const char* current_value_text) {
string_set_str(param->current_value_text, current_value_text);
furi_string_set(param->current_value_text, current_value_text);
}

uint8_t bt_test_get_current_value_index(BtTestParam* param) {
Expand Down
10 changes: 5 additions & 5 deletions applications/debug/display_test/display_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ static void display_config_set_regulation_ratio(VariableItem* item) {
static void display_config_set_contrast(VariableItem* item) {
DisplayTest* instance = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
string_t temp;
string_init(temp);
string_cat_printf(temp, "%d", index);
variable_item_set_current_value_text(item, string_get_cstr(temp));
string_clear(temp);
FuriString* temp;
temp = furi_string_alloc();
furi_string_cat_printf(temp, "%d", index);
variable_item_set_current_value_text(item, furi_string_get_cstr(temp));
furi_string_free(temp);
instance->config_contrast = index;
display_test_reload_config(instance);
}
Expand Down
5 changes: 2 additions & 3 deletions applications/debug/file_browser_test/file_browser_app.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "assets_icons.h"
#include "file_browser_app_i.h"
#include "gui/modules/file_browser.h"
#include "m-string.h"
#include <furi.h>
#include <furi_hal.h>
#include <storage/storage.h>
Expand Down Expand Up @@ -47,7 +46,7 @@ FileBrowserApp* file_browser_app_alloc(char* arg) {

app->widget = widget_alloc();

string_init(app->file_path);
app->file_path = furi_string_alloc();
app->file_browser = file_browser_alloc(app->file_path);
file_browser_configure(app->file_browser, "*", true, &I_badusb_10px, true);

Expand Down Expand Up @@ -84,7 +83,7 @@ void file_browser_app_free(FileBrowserApp* app) {
furi_record_close(RECORD_NOTIFICATION);
furi_record_close(RECORD_DIALOGS);

string_clear(app->file_path);
furi_string_free(app->file_path);

free(app);
}
Expand Down
2 changes: 1 addition & 1 deletion applications/debug/file_browser_test/file_browser_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct FileBrowserApp {
Widget* widget;
FileBrowser* file_browser;

string_t file_path;
FuriString* file_path;
};

typedef enum {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "../file_browser_app_i.h"
#include <core/check.h>
#include <core/log.h>
#include "furi_hal.h"
#include "m-string.h"
#include <furi.h>

#define DEFAULT_PATH "/"
#define EXTENSION "*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "../file_browser_app_i.h"
#include "furi_hal.h"
#include "m-string.h"
#include <furi.h>

void file_browser_scene_result_ok_callback(InputType type, void* context) {
furi_assert(context);
Expand All @@ -24,7 +23,13 @@ void file_browser_scene_result_on_enter(void* context) {
FileBrowserApp* app = context;

widget_add_string_multiline_element(
app->widget, 64, 10, AlignCenter, AlignTop, FontSecondary, string_get_cstr(app->file_path));
app->widget,
64,
10,
AlignCenter,
AlignTop,
FontSecondary,
furi_string_get_cstr(app->file_path));

view_dispatcher_switch_to_view(app->view_dispatcher, FileBrowserAppViewResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bool file_browser_scene_start_on_event(void* context, SceneManagerEvent event) {
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
string_set_str(app->file_path, ANY_PATH("badusb/demo_windows.txt"));
furi_string_set(app->file_path, ANY_PATH("badusb/demo_windows.txt"));
scene_manager_next_scene(app->scene_manager, FileBrowserSceneBrowser);
consumed = true;
} else if(event.type == SceneManagerEventTypeTick) {
Expand Down
18 changes: 9 additions & 9 deletions applications/debug/uart_echo/uart_echo.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <furi.h>
#include <m-string.h>
#include <gui/gui.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
Expand All @@ -25,7 +24,7 @@ typedef struct {
} UartEchoApp;

typedef struct {
string_t text;
FuriString* text;
} ListElement;

struct UartDumpModel {
Expand Down Expand Up @@ -64,10 +63,11 @@ static void uart_echo_view_draw_callback(Canvas* canvas, void* _model) {
canvas,
0,
(i + 1) * (canvas_current_font_height(canvas) - 1),
string_get_cstr(model->list[i]->text));
furi_string_get_cstr(model->list[i]->text));

if(i == model->line) {
uint8_t width = canvas_string_width(canvas, string_get_cstr(model->list[i]->text));
uint8_t width =
canvas_string_width(canvas, furi_string_get_cstr(model->list[i]->text));

canvas_draw_box(
canvas,
Expand Down Expand Up @@ -113,7 +113,7 @@ static void uart_echo_push_to_list(UartDumpModel* model, const char data) {
model->escape = true;
} else if((data >= ' ' && data <= '~') || (data == '\n' || data == '\r')) {
bool new_string_needed = false;
if(string_size(model->list[model->line]->text) >= COLUMNS_ON_SCREEN) {
if(furi_string_size(model->list[model->line]->text) >= COLUMNS_ON_SCREEN) {
new_string_needed = true;
} else if((data == '\n' || data == '\r')) {
// pack line breaks
Expand All @@ -132,13 +132,13 @@ static void uart_echo_push_to_list(UartDumpModel* model, const char data) {
model->list[i - 1] = model->list[i];
}

string_reset(first->text);
furi_string_reset(first->text);
model->list[model->line] = first;
}
}

if(data != '\n' && data != '\r') {
string_push_back(model->list[model->line]->text, data);
furi_string_push_back(model->list[model->line]->text, data);
}
}
model->last_char = data;
Expand Down Expand Up @@ -208,7 +208,7 @@ static UartEchoApp* uart_echo_app_alloc() {
model->line = 0;
model->escape = false;
model->list[i] = malloc(sizeof(ListElement));
string_init(model->list[i]->text);
model->list[i]->text = furi_string_alloc();
}
return true;
});
Expand Down Expand Up @@ -247,7 +247,7 @@ static void uart_echo_app_free(UartEchoApp* app) {
with_view_model(
app->view, (UartDumpModel * model) {
for(size_t i = 0; i < LINES_ON_SCREEN; i++) {
string_clear(model->list[i]->text);
furi_string_free(model->list[i]->text);
free(model->list[i]);
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static const char* test_data_win = "Filetype: Flipper Format test\r\n"
#define ARRAY_W_BSIZE(x) (x), (sizeof(x))

MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
string_t tmpstr;
FuriString* tmpstr;
uint32_t version;
uint32_t uint32_data[COUNT_OF(test_uint_data)];
int32_t int32_data[COUNT_OF(test_int_data)];
Expand Down Expand Up @@ -101,14 +101,14 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
mu_assert_int_eq(position_before, stream_tell(flipper_format_get_raw_stream(flipper_format)));

// read test
string_init(tmpstr);
tmpstr = furi_string_alloc();

mu_check(flipper_format_read_header(flipper_format, tmpstr, &version));
mu_assert_string_eq(test_filetype, string_get_cstr(tmpstr));
mu_assert_string_eq(test_filetype, furi_string_get_cstr(tmpstr));
mu_assert_int_eq(test_version, version);

mu_check(flipper_format_read_string(flipper_format, test_string_key, tmpstr));
mu_assert_string_eq(test_string_data, string_get_cstr(tmpstr));
mu_assert_string_eq(test_string_data, furi_string_get_cstr(tmpstr));

mu_check(flipper_format_get_value_count(flipper_format, test_int_key, &count));
mu_assert_int_eq(COUNT_OF(test_int_data), count);
Expand All @@ -133,7 +133,7 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {

mu_check(!flipper_format_read_string(flipper_format, "Key that doesn't exist", tmpstr));

string_clear(tmpstr);
furi_string_free(tmpstr);

// update data
mu_check(flipper_format_rewind(flipper_format));
Expand All @@ -155,14 +155,14 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
uint8_t hex_updated_data[COUNT_OF(test_hex_updated_data)];

mu_check(flipper_format_rewind(flipper_format));
string_init(tmpstr);
tmpstr = furi_string_alloc();

mu_check(flipper_format_read_header(flipper_format, tmpstr, &version));
mu_assert_string_eq(test_filetype, string_get_cstr(tmpstr));
mu_assert_string_eq(test_filetype, furi_string_get_cstr(tmpstr));
mu_assert_int_eq(test_version, version);

mu_check(flipper_format_read_string(flipper_format, test_string_key, tmpstr));
mu_assert_string_eq(test_string_updated_data, string_get_cstr(tmpstr));
mu_assert_string_eq(test_string_updated_data, furi_string_get_cstr(tmpstr));

mu_check(flipper_format_get_value_count(flipper_format, test_int_key, &count));
mu_assert_int_eq(COUNT_OF(test_int_updated_data), count);
Expand Down Expand Up @@ -190,7 +190,7 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {

mu_check(!flipper_format_read_string(flipper_format, "Key that doesn't exist", tmpstr));

string_clear(tmpstr);
furi_string_free(tmpstr);

// update data
mu_check(flipper_format_rewind(flipper_format));
Expand All @@ -214,14 +214,14 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {
uint8_t hex_new_data[COUNT_OF(test_hex_new_data)];

mu_check(flipper_format_rewind(flipper_format));
string_init(tmpstr);
tmpstr = furi_string_alloc();

mu_check(flipper_format_read_header(flipper_format, tmpstr, &version));
mu_assert_string_eq(test_filetype, string_get_cstr(tmpstr));
mu_assert_string_eq(test_filetype, furi_string_get_cstr(tmpstr));
mu_assert_int_eq(test_version, version);

mu_check(flipper_format_read_string(flipper_format, test_string_key, tmpstr));
mu_assert_string_eq(test_string_updated_2_data, string_get_cstr(tmpstr));
mu_assert_string_eq(test_string_updated_2_data, furi_string_get_cstr(tmpstr));

mu_check(flipper_format_get_value_count(flipper_format, test_int_key, &count));
mu_assert_int_eq(COUNT_OF(test_int_updated_2_data), count);
Expand Down Expand Up @@ -255,7 +255,7 @@ MU_TEST_1(flipper_format_read_and_update_test, FlipperFormat* flipper_format) {

mu_check(!flipper_format_read_string(flipper_format, "Key that doesn't exist", tmpstr));

string_clear(tmpstr);
furi_string_free(tmpstr);

// delete key test
mu_check(flipper_format_rewind(flipper_format));
Expand Down
Loading

0 comments on commit 4bf2982

Please sign in to comment.