-
Notifications
You must be signed in to change notification settings - Fork 16
add new code part #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| #include <stdbool.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <ctype.h> | ||
|
|
||
|
|
||
| typedef enum EErrorCode { | ||
|
|
@@ -75,6 +77,7 @@ TString stringJoin(TString s1, TString s2, TString delim); | |
| TString stringJoinCharArr(TString s1, TString s2, const char *delim); | ||
| TString stringArrJoin(const TString *s, size_t count, TString delim); | ||
| TString stringArrJoinCharArr(const TString *s, size_t count, const char *delim); | ||
| TString stringInitWithCharArr(const char *str); | ||
|
|
||
| void stringScan(TString *s); | ||
| void stringPrint(TString s); | ||
|
|
@@ -100,6 +103,9 @@ void stringMap(TString *s, char (*func)(char)); | |
| void stringMapIndex(TString *s, char (*func)(size_t, char)); | ||
| void stringRemove(TString *s, size_t pos, size_t len); | ||
| void stringDestroy(TString *s); | ||
| void stringPrint(const TString s); | ||
| void stringCapitalize(TString *s); | ||
|
|
||
|
|
||
| double stringToDouble(TString s); | ||
|
|
||
|
|
@@ -941,4 +947,46 @@ double stringToDouble(TString s) { | |
| return number + decimal; | ||
| } | ||
|
|
||
| #endif | ||
| TString stringInitWithCharArr(const char *str) { | ||
| TString s; | ||
| s.length = strlen(str); | ||
| s.capacity = s.length + 1; | ||
| s.data = (char *)malloc(s.capacity * sizeof(char)); | ||
| if (s.data != NULL) { | ||
| strcpy(s.data, str); | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| void stringDestroy(TString *s) { | ||
| if (s->data != NULL) { | ||
| free(s->data); | ||
| s->data = NULL; | ||
| } | ||
| s->length = 0; | ||
| s->capacity = 0; | ||
| } | ||
|
|
||
| void stringPrint(const TString s) { | ||
| if (s.data != NULL) { | ||
| printf("%s\n", s.data); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Такой print нельзя, так как буффер строки не заканчивается |
||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+950
to
+975
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Но эти функции же уже есть в коде библиотеки |
||
| void stringCapitalize(TString *s) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Chat-GPT ❤️ |
||
| if (s->data == NULL) { | ||
| return; | ||
| } | ||
|
|
||
| int capitalizeNext = 1; | ||
| for (size_t i = 0; i < s->length; i++) { | ||
| if (isspace(s->data[i])) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. И добавьте знаки пунктуации, которые тоже разделяют слова |
||
| capitalizeNext = 1; | ||
| } else if (capitalizeNext && isalpha(s->data[i])) { | ||
| s->data[i] = toupper(s->data[i]); | ||
| capitalizeNext = 0; | ||
| } else { | ||
| s->data[i] = tolower(s->data[i]); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не нужно уменьшать буквы, функция только делает большими первые буквы
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Readme says: void stringCapitalize(TString *s); - Capitalize the first letter of each word. |
||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍