Skip to content

Conversation

@gorilli4
Copy link

@gorilli4 gorilli4 commented Jun 1, 2024

Внес свой вклад в развитие проекта добавлением функции, которая безопасно делает заглавной первую букву каждого слова в строке. Это может быть полезно для форматирования текстовых файлов.

}
}

void stringCapitalize(TString *s) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chat-GPT ❤️

Comment on lines +950 to +975
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);
}
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Но эти функции же уже есть в коде библиотеки


void stringPrint(const TString s) {
if (s.data != NULL) {
printf("%s\n", s.data);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Такой print нельзя, так как буффер строки не заканчивается \0

s->data[i] = toupper(s->data[i]);
capitalizeNext = 0;
} else {
s->data[i] = tolower(s->data[i]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не нужно уменьшать буквы, функция только делает большими первые буквы

Copy link
Owner

Choose a reason for hiding this comment

The 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.


int capitalizeNext = 1;
for (size_t i = 0; i < s->length; i++) {
if (isspace(s->data[i])) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И добавьте знаки пунктуации, которые тоже разделяют слова

- [x] size_t stringCount(TString s, char c); - Count occurrences of a character.
- [ ] size_t stringCountSubstring(TString s, TString pattern); - Count occurrences of a substring.
- [ ] void stringCapitalize(TString *s); - Capitalize the first letter of each word.
- [x] void stringCapitalize(TString *s); - Capitalize the first letter of each word.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants