diff options
| author | raysan5 <[email protected]> | 2020-05-09 12:38:33 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2020-05-09 12:38:33 +0200 |
| commit | 7efed56b664d3caf8af01ae017fb3585123997f6 (patch) | |
| tree | beeec17eb9f5f31b27561b3b145db0ade3ac1181 /src/text.c | |
| parent | 7a1d3d807f0840a640642ab4c72895d5eac7eeb6 (diff) | |
| download | raylib-7efed56b664d3caf8af01ae017fb3585123997f6.tar.gz raylib-7efed56b664d3caf8af01ae017fb3585123997f6.zip | |
Added [text] flag: SUPPORT_TEXT_MANIPULATION
Diffstat (limited to 'src/text.c')
| -rw-r--r-- | src/text.c | 147 |
1 files changed, 73 insertions, 74 deletions
@@ -1093,40 +1093,6 @@ int GetGlyphIndex(Font font, int codepoint) //---------------------------------------------------------------------------------- // Text strings management functions //---------------------------------------------------------------------------------- - -// Copy one string to another, returns bytes copied -int TextCopy(char *dst, const char *src) -{ - int bytes = 0; - - if (dst != NULL) - { - while (*src != '\0') - { - *dst = *src; - dst++; - src++; - - bytes++; - } - - *dst = '\0'; - } - - return bytes; -} - -// Check if two text string are equal -// REQUIRES: strcmp() -bool TextIsEqual(const char *text1, const char *text2) -{ - bool result = false; - - if (strcmp(text1, text2) == 0) result = true; - - return result; -} - // Get text length in bytes, check for \0 character unsigned int TextLength(const char *text) { @@ -1166,6 +1132,40 @@ const char *TextFormat(const char *text, ...) return currentBuffer; } +#if defined(SUPPORT_TEXT_MANIPULATION) +// Copy one string to another, returns bytes copied +int TextCopy(char *dst, const char *src) +{ + int bytes = 0; + + if (dst != NULL) + { + while (*src != '\0') + { + *dst = *src; + dst++; + src++; + + bytes++; + } + + *dst = '\0'; + } + + return bytes; +} + +// Check if two text string are equal +// REQUIRES: strcmp() +bool TextIsEqual(const char *text1, const char *text2) +{ + bool result = false; + + if (strcmp(text1, text2) == 0) result = true; + + return result; +} + // Get a piece of a text string const char *TextSubtext(const char *text, int position, int length) { @@ -1457,6 +1457,44 @@ char *TextToUtf8(int *codepoints, int length) return text; } +// Encode codepoint into utf8 text (char array length returned as parameter) +RLAPI const char *CodepointToUtf8(int codepoint, int *byteLength) +{ + static char utf8[6] = { 0 }; + int length = 0; + + if (codepoint <= 0x7f) + { + utf8[0] = (char)codepoint; + length = 1; + } + else if (codepoint <= 0x7ff) + { + utf8[0] = (char)(((codepoint >> 6) & 0x1f) | 0xc0); + utf8[1] = (char)((codepoint & 0x3f) | 0x80); + length = 2; + } + else if (codepoint <= 0xffff) + { + utf8[0] = (char)(((codepoint >> 12) & 0x0f) | 0xe0); + utf8[1] = (char)(((codepoint >> 6) & 0x3f) | 0x80); + utf8[2] = (char)((codepoint & 0x3f) | 0x80); + length = 3; + } + else if (codepoint <= 0x10ffff) + { + utf8[0] = (char)(((codepoint >> 18) & 0x07) | 0xf0); + utf8[1] = (char)(((codepoint >> 12) & 0x3f) | 0x80); + utf8[2] = (char)(((codepoint >> 6) & 0x3f) | 0x80); + utf8[3] = (char)((codepoint & 0x3f) | 0x80); + length = 4; + } + + *byteLength = length; + + return utf8; +} + // Get all codepoints in a string, codepoints count returned by parameters int *GetCodepoints(const char *text, int *count) { @@ -1498,7 +1536,7 @@ int GetCodepointsCount(const char *text) return len; } - +#endif // SUPPORT_TEXT_MANIPULATION // Returns next codepoint in a UTF8 encoded text, scanning until '\0' is found // When a invalid UTF8 byte is encountered we exit as soon as possible and a '?'(0x3f) codepoint is returned @@ -1612,45 +1650,6 @@ int GetNextCodepoint(const char *text, int *bytesProcessed) return code; } -// Encode codepoint into utf8 text (char array length returned as parameter) -RLAPI const char *CodepointToUtf8(int codepoint, int *byteLength) -{ - static char utf8[6] = { 0 }; - int length = 0; - - if (codepoint <= 0x7f) - { - utf8[0] = (char)codepoint; - length = 1; - } - else if (codepoint <= 0x7ff) - { - utf8[0] = (char)(((codepoint >> 6) & 0x1f) | 0xc0); - utf8[1] = (char)((codepoint & 0x3f) | 0x80); - length = 2; - } - else if (codepoint <= 0xffff) - { - utf8[0] = (char)(((codepoint >> 12) & 0x0f) | 0xe0); - utf8[1] = (char)(((codepoint >> 6) & 0x3f) | 0x80); - utf8[2] = (char)((codepoint & 0x3f) | 0x80); - length = 3; - } - else if (codepoint <= 0x10ffff) - { - utf8[0] = (char)(((codepoint >> 18) & 0x07) | 0xf0); - utf8[1] = (char)(((codepoint >> 12) & 0x3f) | 0x80); - utf8[2] = (char)(((codepoint >> 6) & 0x3f) | 0x80); - utf8[3] = (char)((codepoint & 0x3f) | 0x80); - length = 4; - } - - *byteLength = length; - - return utf8; -} -//---------------------------------------------------------------------------------- - //---------------------------------------------------------------------------------- // Module specific Functions Definition //---------------------------------------------------------------------------------- |
