summaryrefslogtreecommitdiffhomepage
path: root/src/text.c
diff options
context:
space:
mode:
authorRay <[email protected]>2019-10-11 20:12:15 +0200
committerRay <[email protected]>2019-10-11 20:12:15 +0200
commite0cb892d2d2d9d1c95f5f0622f1f8237ee843f45 (patch)
treee0b26df081db3d313510458cef0e79c700a7483f /src/text.c
parent12d3e21f1bfa66f3aca334bcb01da9b52f96b089 (diff)
downloadraylib-e0cb892d2d2d9d1c95f5f0622f1f8237ee843f45.tar.gz
raylib-e0cb892d2d2d9d1c95f5f0622f1f8237ee843f45.zip
ADDED: GetCodepoints()
Get the unicode equivalent characters (as int array) from a UTF-8 text array... maybe this function is renamed to be clearer to users...
Diffstat (limited to 'src/text.c')
-rw-r--r--src/text.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/text.c b/src/text.c
index 4eb1b4b0..4dad8c6b 100644
--- a/src/text.c
+++ b/src/text.c
@@ -65,6 +65,8 @@
//----------------------------------------------------------------------------------
#define MAX_TEXT_BUFFER_LENGTH 1024 // Size of internal static buffers of some Text*() functions
+#define MAX_TEXT_UNICODE_CHARS 512 // Maximum number of unicode codepoints
+
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
@@ -869,6 +871,26 @@ int GetNextCodepoint(const char *text, int *bytesProcessed)
return code;
}
+// Get all codepoints in a string, codepoints count returned by parameters
+int *GetCodepoints(const char *text, int *count)
+{
+ static int codepoints[MAX_TEXT_UNICODE_CHARS] = { 0 };
+ memset(codepoints, 0, MAX_TEXT_UNICODE_CHARS*sizeof(int));
+
+ int bytesProcessed = 0;
+ int textLength = strlen(text);
+ int codepointsCount = 0;
+
+ for (int i = 0; i < textLength; codepointsCount++)
+ {
+ codepoints[codepointsCount] = GetNextCodepoint(text + i, &bytesProcessed);
+ i += bytesProcessed;
+ }
+
+ return codepoints;
+}
+
+
// Draw text (using default font)
// NOTE: fontSize work like in any drawing program but if fontSize is lower than font-base-size, then font-base-size is used