@@ -70,21 +70,21 @@ char* wrap_text(const char* text, size_t max_line_width) {
70
70
// More realistic initial size estimation
71
71
size_t allocated_size = len + len / max_line_width + 1 ;
72
72
char * wrapped = malloc (allocated_size );
73
- if (!wrapped ) return NULL ;
73
+ if (!wrapped ) return NULL ;
74
74
75
75
size_t cur_line_len = 0 ;
76
76
size_t wrapped_index = 0 ;
77
77
size_t word_len = 0 ;
78
78
79
- for (size_t i = 0 ; i < len ; ++ i ) {
79
+ for (size_t i = 0 ; i < len ; ++ i ) {
80
80
word_len ++ ;
81
- if (text [i ] == '\n' ) {
82
- for (size_t j = i - word_len + 1 ; j <= i ; ++ j ) {
81
+ if (text [i ] == '\n' ) {
82
+ for (size_t j = i - word_len + 1 ; j <= i ; ++ j ) {
83
83
// Check and reallocate if necessary before writing to the buffer
84
- if (wrapped_index >= allocated_size ) {
84
+ if (wrapped_index >= allocated_size ) {
85
85
allocated_size *= 2 ;
86
86
char * new_wrapped = realloc (wrapped , allocated_size );
87
- if (!new_wrapped ) {
87
+ if (!new_wrapped ) {
88
88
free (wrapped );
89
89
return NULL ;
90
90
}
@@ -97,41 +97,41 @@ char* wrap_text(const char* text, size_t max_line_width) {
97
97
continue ;
98
98
}
99
99
100
- if (text [i ] == ' ' || i == len - 1 ) {
101
- if (word_len >= max_line_width ) {
102
- if (cur_line_len > 0 ) {
100
+ if (text [i ] == ' ' || i == len - 1 ) {
101
+ if (word_len >= max_line_width ) {
102
+ if (cur_line_len > 0 ) {
103
103
wrapped [wrapped_index ++ ] = '\n' ;
104
104
cur_line_len = 0 ;
105
105
}
106
- for (size_t j = i - word_len + 1 ; j <= i ; ++ j ) {
106
+ for (size_t j = i - word_len + 1 ; j <= i ; ++ j ) {
107
107
// Check and reallocate if necessary before writing to the buffer
108
- if (wrapped_index >= allocated_size ) {
108
+ if (wrapped_index >= allocated_size ) {
109
109
allocated_size *= 2 ;
110
110
char * new_wrapped = realloc (wrapped , allocated_size );
111
- if (!new_wrapped ) {
111
+ if (!new_wrapped ) {
112
112
free (wrapped );
113
113
return NULL ;
114
114
}
115
115
wrapped = new_wrapped ;
116
116
}
117
117
wrapped [wrapped_index ++ ] = text [j ];
118
- if (++ cur_line_len >= max_line_width && text [j ] != '\n' ) {
118
+ if (++ cur_line_len >= max_line_width && text [j ] != '\n' ) {
119
119
wrapped [wrapped_index ++ ] = '\n' ;
120
120
cur_line_len = 0 ;
121
121
}
122
122
}
123
- } else if (cur_line_len + word_len > max_line_width ) {
124
- if (cur_line_len > 0 ) {
123
+ } else if (cur_line_len + word_len > max_line_width ) {
124
+ if (cur_line_len > 0 ) {
125
125
wrapped [wrapped_index ++ ] = '\n' ;
126
126
cur_line_len = 0 ;
127
127
}
128
128
}
129
- for (size_t j = i - word_len + 1 ; j <= i ; ++ j ) {
129
+ for (size_t j = i - word_len + 1 ; j <= i ; ++ j ) {
130
130
// Check and reallocate if necessary before writing to the buffer
131
- if (wrapped_index >= allocated_size ) {
131
+ if (wrapped_index >= allocated_size ) {
132
132
allocated_size *= 2 ;
133
133
char * new_wrapped = realloc (wrapped , allocated_size );
134
- if (!new_wrapped ) {
134
+ if (!new_wrapped ) {
135
135
free (wrapped );
136
136
return NULL ;
137
137
}
@@ -148,7 +148,6 @@ char* wrap_text(const char* text, size_t max_line_width) {
148
148
return wrapped ;
149
149
}
150
150
151
-
152
151
void topic_scene_on_enter (void * context ) {
153
152
furi_assert (context );
154
153
App * app = (App * )context ;
@@ -162,13 +161,14 @@ void topic_scene_on_enter(void* context) {
162
161
if (file_stream_open (app -> file_stream , file_path , FSAM_READ , FSOM_OPEN_EXISTING )) {
163
162
FuriString * line = furi_string_alloc ();
164
163
while (stream_read_line (app -> file_stream , line )) {
165
- dynamic_buffer_append (& dynamic_content , furi_string_get_cstr (line ), furi_string_size (line ));
164
+ dynamic_buffer_append (
165
+ & dynamic_content , furi_string_get_cstr (line ), furi_string_size (line ));
166
166
dynamic_buffer_append (& dynamic_content , "\r\n" , 1 );
167
167
}
168
168
dynamic_buffer_append (& dynamic_content , "\0" , 1 );
169
169
furi_string_free (line );
170
170
file_stream_close (app -> file_stream );
171
- size_t max_line_width = WIDGET_WIDTH / CHAR_WIDTH ;
171
+ size_t max_line_width = WIDGET_WIDTH / UICHAR_WIDTH ;
172
172
char * wrapped_text = wrap_text (dynamic_content .data , max_line_width );
173
173
dynamic_buffer_free (& dynamic_content );
174
174
0 commit comments