1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-27 20:44:56 +00:00

Optimised and corrected print_startcase

This commit is contained in:
AlexApps99 2020-01-17 16:12:40 +13:00 committed by Brenden Matthews
parent 49638c6c19
commit 435d05dc6e

View File

@ -87,26 +87,19 @@ void print_catp(struct text_object *obj, char *p, unsigned int p_max_size) {
void print_startcase(struct text_object *obj, char *p,
unsigned int p_max_size) {
unsigned int x = 0;
int z = 0;
char buf[DEFAULT_TEXT_BUFFER_SIZE];
char *src = obj->data.s;
char *dest = buf;
evaluate(obj->data.s, p, p_max_size);
if (0 != strcmp(p, "")) { src = p; }
for (; *src && p_max_size - 1 > x; src++, x++) {
if (0 == z) {
*dest++ = (toupper(static_cast<unsigned char>(*src)));
for (unsigned int x = 0, z = 0; x < p_max_size - 1 && p[x]; x++) {
if (isspace(p[x])) {
z = 0;
} else if (z == 0) {
p[x] = toupper(p[x]);
z++;
} else {
p[x] = tolower(p[x]);
z++;
continue;
}
*dest++ = *src;
if (' ' == *src) z = 0;
}
*dest = '\0';
snprintf(p, p_max_size, "%s", buf);
p[p_max_size - 1] = '\0';
}
void print_lowercase(struct text_object *obj, char *p,