mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
[FL-3884] Proper integer parsing (#3839)
* feat: strint_to_uint32 and tests
* fix: permit explicit bases and prefixes
* feat: strint_to_{int32,uint16,int16}
* feat: strint_to_u?int64
* refactor: replace strtol, strtoul, sscanf with strint_to_*
* fix: api symbols
* docs: document parameter `end` of strint_to_uint_32
* style: apply changes requested by hedger
* refactor: fix pvs-studio diagnostic
* style: apply changes requested by CookiePLMonster
* fix: unused var
* fix: pointer type
* refactor: convert atoi to strint_to_*
* fix: strint_to_uint8 doesn't actually exist ._ .
* fix: memory leak
* style: address review comments
* Toolbox: couple small comments in the code and doxygen comment update. SubGhz, Loader: fix strint usage.
* Loader: fix incorrect cast
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <flipper_format/flipper_format.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
#include <lib/subghz/devices/devices.h>
|
||||
#include <lib/toolbox/strint.h>
|
||||
|
||||
#define TAG "SubGhzFileEncoderWorker"
|
||||
|
||||
@@ -45,27 +46,26 @@ void subghz_file_encoder_worker_add_level_duration(
|
||||
}
|
||||
|
||||
bool subghz_file_encoder_worker_data_parse(SubGhzFileEncoderWorker* instance, const char* strStart) {
|
||||
char* str1;
|
||||
bool res = false;
|
||||
// Line sample: "RAW_Data: -1, 2, -2..."
|
||||
|
||||
// Look for a key in the line
|
||||
str1 = strstr(strStart, "RAW_Data: ");
|
||||
// Look for the key in the line
|
||||
char* str = strstr(strStart, "RAW_Data: ");
|
||||
bool res = false;
|
||||
|
||||
if(str1 != NULL) {
|
||||
if(str) {
|
||||
// Skip key
|
||||
str1 = strchr(str1, ' ');
|
||||
str = strchr(str, ' ');
|
||||
|
||||
// Check that there is still an element in the line
|
||||
while(strchr(str1, ' ') != NULL) {
|
||||
str1 = strchr(str1, ' ');
|
||||
|
||||
// Skip space
|
||||
str1 += 1;
|
||||
subghz_file_encoder_worker_add_level_duration(instance, atoi(str1));
|
||||
// Parse next element
|
||||
int32_t duration;
|
||||
while(strint_to_int32(str, &str, &duration, 10) == StrintParseNoError) {
|
||||
subghz_file_encoder_worker_add_level_duration(instance, duration);
|
||||
if(*str == ',') str++; // could also be `\0`
|
||||
}
|
||||
|
||||
res = true;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user