diff options
| author | Ray <[email protected]> | 2023-07-02 11:10:42 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2023-07-02 11:10:42 +0200 |
| commit | 4fc5e82e3087b5a9df21db86f6dc4588e5d629b4 (patch) | |
| tree | 6c7efe77322d6c2a1394d46030d17266bba9946d /src/rtext.c | |
| parent | 3e4e4b32fdcaa2cff8854e11ff2179af4ff2afe9 (diff) | |
| download | raylib-4fc5e82e3087b5a9df21db86f6dc4588e5d629b4.tar.gz raylib-4fc5e82e3087b5a9df21db86f6dc4588e5d629b4.zip | |
REVIEWED: `TextToUpper()`, `TextToLower()`, `TextToPascal()`
Diffstat (limited to 'src/rtext.c')
| -rw-r--r-- | src/rtext.c | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/src/rtext.c b/src/rtext.c index cb609cf6..0cdac6d1 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1588,7 +1588,8 @@ int TextFindIndex(const char *text, const char *find) } // Get upper case version of provided string -// REQUIRES: toupper() +// WARNING: Limited functionality, only basic characters set +// TODO: Support UTF-8 diacritics to upper-case, check codepoints const char *TextToUpper(const char *text) { static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 }; @@ -1596,17 +1597,10 @@ const char *TextToUpper(const char *text) if (text != NULL) { - for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++) + for (int i = 0; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[i] != '\0'); i++) { - if (text[i] != '\0') - { - buffer[i] = (char)toupper(text[i]); - //if ((text[i] >= 'a') && (text[i] <= 'z')) buffer[i] = text[i] - 32; - - // TODO: Support UTF-8 diacritics to upper-case - //if ((text[i] >= 'à') && (text[i] <= 'ý')) buffer[i] = text[i] - 32; - } - else { buffer[i] = '\0'; break; } + if ((text[i] >= 'a') && (text[i] <= 'z')) buffer[i] = text[i] - 32; + else buffer[i] = text[i]; } } @@ -1614,7 +1608,7 @@ const char *TextToUpper(const char *text) } // Get lower case version of provided string -// REQUIRES: tolower() +// WARNING: Limited functionality, only basic characters set const char *TextToLower(const char *text) { static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 }; @@ -1622,14 +1616,10 @@ const char *TextToLower(const char *text) if (text != NULL) { - for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++) + for (int i = 0; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[i] != '\0'); i++) { - if (text[i] != '\0') - { - buffer[i] = (char)tolower(text[i]); - //if ((text[i] >= 'A') && (text[i] <= 'Z')) buffer[i] = text[i] + 32; - } - else { buffer[i] = '\0'; break; } + if ((text[i] >= 'A') && (text[i] <= 'Z')) buffer[i] = text[i] + 32; + else buffer[i] = text[i]; } } @@ -1637,7 +1627,7 @@ const char *TextToLower(const char *text) } // Get Pascal case notation version of provided string -// REQUIRES: toupper() +// WARNING: Limited functionality, only basic characters set const char *TextToPascal(const char *text) { static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 }; @@ -1645,20 +1635,18 @@ const char *TextToPascal(const char *text) if (text != NULL) { - buffer[0] = (char)toupper(text[0]); + // Upper case first character + if ((text[0] >= 'a') && (text[0] <= 'z')) buffer[0] = text[0] - 32; - for (int i = 1, j = 1; i < MAX_TEXT_BUFFER_LENGTH; i++, j++) + // Check for next separator to upper case another character + for (int i = 1, j = 1; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[j] != '\0'); i++, j++) { - if (text[j] != '\0') + if (text[j] != '_') buffer[i] = text[j]; + else { - if (text[j] != '_') buffer[i] = text[j]; - else - { - j++; - buffer[i] = (char)toupper(text[j]); - } + j++; + if ((text[j] >= 'a') && (text[j] <= 'z')) buffer[i] = text[j] - 32; } - else { buffer[i] = '\0'; break; } } } |
