Skip to content

Commit e14204c

Browse files
committed
refactor(nvs): Extract string increment logic into a separate function
1 parent e15e7f7 commit e14204c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tests/validation/nvs/nvs.ino

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ void validate_types() {
2828
assert(preferences.getType("struct") == PT_BLOB);
2929
}
3030

31+
// Function to increment string values
32+
void incrementStringValues(String &val_string, char *val_string_buf, size_t buf_size) {
33+
// Extract the number from string and increment it
34+
val_string = "str" + String(val_string.substring(3).toInt() + 1);
35+
36+
// Extract the number from strLen and increment it
37+
String strLen_str = String(val_string_buf);
38+
int strLen_num = strLen_str.substring(6).toInt();
39+
snprintf(val_string_buf, buf_size, "strLen%d", strLen_num + 1);
40+
}
41+
3142
void setup() {
3243
Serial.begin(115200);
3344
while (!Serial) {
@@ -90,11 +101,8 @@ void setup() {
90101
val_double += 1.1;
91102
val_bool = !val_bool; // Toggle boolean value
92103

93-
// Extract the number from strLen and increment it
94-
val_string = "str" + String(val_string.substring(3).toInt() + 1);
95-
String strLen_str = String(val_string_buf);
96-
int strLen_num = strLen_str.substring(6).toInt();
97-
snprintf(val_string_buf, sizeof(val_string_buf), "strLen%d", strLen_num + 1);
104+
// Increment string values using function
105+
incrementStringValues(val_string, val_string_buf, sizeof(val_string_buf));
98106

99107
test_data.id += 1;
100108
test_data.value += 10;

0 commit comments

Comments
 (0)