diff options
| author | IoIxD <[email protected]> | 2024-06-03 11:13:28 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-06-03 20:13:28 +0200 |
| commit | 39f12859dcdf92822c8fefece1135bf6e76a1573 (patch) | |
| tree | c3cfe9a317002ff65dc83c46d0063dbb23c623f2 /src/rtext.c | |
| parent | 06f8c4f73318488e5a4bf1f7bd82fe991a66827e (diff) | |
| download | raylib-39f12859dcdf92822c8fefece1135bf6e76a1573.tar.gz raylib-39f12859dcdf92822c8fefece1135bf6e76a1573.zip | |
rtext: added functions for camel case and snake case (reopened due to formatting errors) (#4033)
* rtext: added functions for camel case and snake case
* Update raylib_api.* by CI
* rtext: removed always false comparison
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'src/rtext.c')
| -rw-r--r-- | src/rtext.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/rtext.c b/src/rtext.c index 5ba4e8b6..118a559d 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1786,6 +1786,71 @@ const char *TextToPascal(const char *text) return buffer; } +// Get snake case notation version of provided string +// WARNING: Limited functionality, only basic characters set +const char *TextToSnake(const char *text) +{ + static char buffer[MAX_TEXT_BUFFER_LENGTH] = {0}; + memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH); + + if (text != NULL) + { + // Check for next separator to upper case another character + for (int i = 0, j = 0; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[j] != '\0'); i++, j++) + { + if ((text[j] >= 'A') && (text[j] <= 'Z')) + { + if (i >= 1) + { + buffer[i] = '_'; + i++; + } + buffer[i] = text[j] + 32; + } + else + { + buffer[i] = text[j]; + } + } + } + + return buffer; +} + +// Get Camel case notation version of provided string +// WARNING: Limited functionality, only basic characters set +const char *TextToCamel(const char *text) +{ + static char buffer[MAX_TEXT_BUFFER_LENGTH] = {0}; + memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH); + + if (text != NULL) + { + // Lower case first character + if ((text[0] >= 'A') && (text[0] <= 'Z')) + buffer[0] = text[0] + 32; + else + buffer[0] = text[0]; + + // 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] != '_') + buffer[i] = text[j]; + else + { + j++; + if ((text[j] >= 'a') && (text[j] <= 'z')) + { + buffer[i] = text[j] - 32; + } + } + } + } + + return buffer; +} + // Encode text codepoint into UTF-8 text // REQUIRES: memcpy() // WARNING: Allocated memory must be manually freed |
