1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-28 13:00:45 +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, void print_startcase(struct text_object *obj, char *p,
unsigned int p_max_size) { 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); evaluate(obj->data.s, p, p_max_size);
if (0 != strcmp(p, "")) { src = p; } for (unsigned int x = 0, z = 0; x < p_max_size - 1 && p[x]; x++) {
if (isspace(p[x])) {
for (; *src && p_max_size - 1 > x; src++, x++) { z = 0;
if (0 == z) { } else if (z == 0) {
*dest++ = (toupper(static_cast<unsigned char>(*src))); p[x] = toupper(p[x]);
z++;
} else {
p[x] = tolower(p[x]);
z++; z++;
continue;
} }
*dest++ = *src;
if (' ' == *src) z = 0;
} }
*dest = '\0'; p[p_max_size - 1] = '\0';
snprintf(p, p_max_size, "%s", buf);
} }
void print_lowercase(struct text_object *obj, char *p, void print_lowercase(struct text_object *obj, char *p,