Skip to content

Commit 0d040a3

Browse files
feat (functionality): change special String cases
Able to convert given string to equivalent pascal, camel, snake and kebab case. Change the strings according to following examples, "clAsS#1_nAmE" to pascal case is "Class1Name" "vaRiAbLe#1_nAmE" to camel case is "variable1Name" "DO_fuNC@$01 nAmE" to snake case is "do_func_01_name" "DO-fuNC@$01 nAmE" to kebab case is "do-func-01-name" Resolves: #126
1 parent e276f6c commit 0d040a3

8 files changed

Lines changed: 445 additions & 13 deletions

File tree

cov/string.c.gcov

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,78 @@ call 0 returned 1
439439
1: 153: delete_string (&string);
440440
call 0 returned 1
441441
-: 154:
442-
1: 155: printf (BOLD_YELLOW "...Unit test ends!" BOLD_MAGENTA " [String]\n" RESET_STYLE);
442+
1: 155: string = create_string (12, "clAsS@1_nAmE");
443443
call 0 returned 1
444-
1: 156:}
444+
1: 156: str = get_pascal_case_string (string);
445+
call 0 returned 1
446+
1*: 157: TEST (true == compare_raw_strings_shh (10, "Class1Name", 10, str -> text), "Matched pascal case string (\"clAsS#1_nAmE\") = \"Class1Name\"");
447+
call 0 returned 1
448+
branch 1 taken 1 (fallthrough)
449+
branch 2 taken 0
450+
1: 157-block 175
451+
call 3 returned 1
452+
%%%%%: 157-block 176
453+
call 4 never executed
454+
1: 158: delete_string (&str);
455+
1: 158-block 177
456+
call 0 returned 1
457+
1: 159: delete_string (&string);
458+
call 0 returned 1
459+
-: 160:
460+
1: 161: string = create_string (15, "vaRiAbLe#1_nAmE");
461+
call 0 returned 1
462+
1: 162: str = get_camel_case_string (string);
463+
call 0 returned 1
464+
1*: 163: TEST (true == compare_raw_strings_shh (13, "variable1Name", 13, str -> text), "Matched camel case string (\"vaRiAbLe#1_nAmE\") = \"variable1Name\"");
465+
call 0 returned 1
466+
branch 1 taken 1 (fallthrough)
467+
branch 2 taken 0
468+
1: 163-block 183
469+
call 3 returned 1
470+
%%%%%: 163-block 184
471+
call 4 never executed
472+
1: 164: delete_string (&str);
473+
1: 164-block 185
474+
call 0 returned 1
475+
1: 165: delete_string (&string);
476+
call 0 returned 1
477+
-: 166:
478+
1: 167: string = create_string (16, "DO_fuNC@$01 nAmE");
479+
call 0 returned 1
480+
1: 168: str = get_snake_case_string (string);
481+
call 0 returned 1
482+
1*: 169: TEST (true == compare_raw_strings_shh (15, "do_func_01_name", 15, str -> text), "Matched snake case string (\"DO_fuNC@$01 nAmE\") = \"do_func_01_name\"");
483+
call 0 returned 1
484+
branch 1 taken 1 (fallthrough)
485+
branch 2 taken 0
486+
1: 169-block 191
487+
call 3 returned 1
488+
%%%%%: 169-block 192
489+
call 4 never executed
490+
1: 170: delete_string (&str);
491+
1: 170-block 193
492+
call 0 returned 1
493+
1: 171: delete_string (&string);
494+
call 0 returned 1
495+
-: 172:
496+
1: 173: string = create_string (16, "DO-fuNC@$01 nAmE");
497+
call 0 returned 1
498+
1: 174: str = get_kebab_case_string (string);
499+
call 0 returned 1
500+
1*: 175: TEST (true == compare_raw_strings_shh (15, "do-func-01-name", 15, str -> text), "Matched kebab case string (\"DO-fuNC@$01 nAmE\") = \"do-func-01-name\"");
501+
call 0 returned 1
502+
branch 1 taken 1 (fallthrough)
503+
branch 2 taken 0
504+
1: 175-block 199
505+
call 3 returned 1
506+
%%%%%: 175-block 200
507+
call 4 never executed
508+
1: 176: delete_string (&str);
509+
1: 176-block 201
510+
call 0 returned 1
511+
1: 177: delete_string (&string);
512+
call 0 returned 1
513+
-: 178:
514+
1: 179: printf (BOLD_YELLOW "...Unit test ends!" BOLD_MAGENTA " [String]\n" RESET_STYLE);
515+
call 0 returned 1
516+
1: 180:}

inc/string.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,9 @@ String* get_lower_case_string (String* string);
3636
String* swap_string_case (String* string);
3737
String* capitalize_string (String* string);
3838
String* get_title_case_string (String* string);
39+
String* get_pascal_case_string (String* string);
40+
String* get_camel_case_string (String* string);
41+
String* get_snake_case_string (String* string);
42+
String* get_kebab_case_string (String* string);
3943

4044
#endif // STRING_H

log/all_cov.log

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ Creating 'basic.c.gcov'
1414
Lines executed:100.00% of 16
1515

1616
Function 'test_string'
17-
Lines executed:100.00% of 99
18-
Branches executed:100.00% of 56
19-
Taken at least once:50.00% of 56
20-
Calls executed:80.28% of 142
17+
Lines executed:100.00% of 119
18+
Branches executed:100.00% of 64
19+
Taken at least once:50.00% of 64
20+
Calls executed:81.18% of 170
2121

2222
File 'tst/string.c'
23-
Lines executed:100.00% of 99
24-
Branches executed:100.00% of 56
25-
Taken at least once:50.00% of 56
26-
Calls executed:80.28% of 142
23+
Lines executed:100.00% of 119
24+
Branches executed:100.00% of 64
25+
Taken at least once:50.00% of 64
26+
Calls executed:81.18% of 170
2727
Creating 'string.c.gcov'
2828

29-
Lines executed:100.00% of 99
29+
Lines executed:100.00% of 119
3030

3131
Function 'test_data'
3232
Lines executed:100.00% of 13

log/all_cov_cnt.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
100.00
1111
100.00
1212
50.00
13-
80.28
13+
81.18
1414
100.00
1515
100.00
1616
50.00
17-
80.28
17+
81.18
1818
100.00
1919
100.00
2020
100.00

log/memory.log

616 Bytes
Binary file not shown.

log/test.log

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
[PASSED]: (Matched swap-case ("HE1lo") = "he1LO")
3737
[PASSED]: (Matched capitalize string ("heLLo") = "Hello")
3838
[PASSED]: (Matched title case string ("heLLo, wOrLd") = "Hello, World")
39+
[PASSED]: (Matched pascal case string ("clAsS#1_nAmE") = "Class1Name")
40+
[PASSED]: (Matched camel case string ("vaRiAbLe#1_nAmE") = "variable1Name")
41+
[PASSED]: (Matched snake case string ("DO_fuNC@$01 nAmE") = "do_func_01_name")
42+
[PASSED]: (Matched kebab case string ("DO-fuNC@$01 nAmE") = "do-func-01-name")
3943
...Unit test ends! [String]
4044
Unit test starts... [Data]
4145
 [PASSED]: (Address non-null check)

0 commit comments

Comments
 (0)