diff --git a/src/misc.cc b/src/misc.cc index d7bf065d..3cb44aa0 100644 --- a/src/misc.cc +++ b/src/misc.cc @@ -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(*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,