mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-21 13:13:35 -05:00
Compare commits
2 Commits
ed3b5b2649
...
7103703313
| Author | SHA1 | Date | |
|---|---|---|---|
| 7103703313 | |||
| d2f6c4924c |
@ -1506,6 +1506,8 @@ RLAPI const char *CodepointToUTF8(int codepoint, int *utf8Size);
|
||||
// Text strings management functions (no UTF-8 strings, only byte chars)
|
||||
// WARNING 1: Most of these functions use internal static buffers, it's recommended to store returned data on user-side for re-use
|
||||
// WARNING 2: Some strings allocate memory internally for the returned strings, those strings must be free by user using MemFree()
|
||||
RLAPI char **LoadTextLines(const char *text, int *count); // Load text as separate lines ('\n')
|
||||
RLAPI void UnloadTextLines(char **text); // Unload text lines
|
||||
RLAPI int TextCopy(char *dst, const char *src); // Copy one string to another, returns bytes copied
|
||||
RLAPI bool TextIsEqual(const char *text1, const char *text2); // Check if two text string are equal
|
||||
RLAPI unsigned int TextLength(const char *text); // Get text length, checks for '\0' ending
|
||||
@ -1522,7 +1524,6 @@ RLAPI char *TextToLower(const char *text);
|
||||
RLAPI char *TextToPascal(const char *text); // Get Pascal case notation version of provided string
|
||||
RLAPI char *TextToSnake(const char *text); // Get Snake case notation version of provided string
|
||||
RLAPI char *TextToCamel(const char *text); // Get Camel case notation version of provided string
|
||||
|
||||
RLAPI int TextToInteger(const char *text); // Get integer value from text
|
||||
RLAPI float TextToFloat(const char *text); // Get float value from text
|
||||
|
||||
|
||||
34
src/rtext.c
34
src/rtext.c
@ -1415,6 +1415,40 @@ Rectangle GetGlyphAtlasRec(Font font, int codepoint)
|
||||
//----------------------------------------------------------------------------------
|
||||
// Text strings management functions
|
||||
//----------------------------------------------------------------------------------
|
||||
// Load text as separate lines ('\n')
|
||||
// WARNING: There is a limit set for number of lines and line-size
|
||||
char **LoadTextLines(const char *text, int *count)
|
||||
{
|
||||
#define MAX_TEXTLINES_COUNT 512
|
||||
#define MAX_TEXTLINES_LINE_LEN 512
|
||||
|
||||
char **lines = (char **)RL_CALLOC(MAX_TEXTLINES_COUNT, sizeof(char *));
|
||||
for (int i = 0; i < MAX_TEXTLINES_COUNT; i++) lines[i] = (char *)RL_CALLOC(MAX_TEXTLINES_LINE_LEN, 1);
|
||||
int textSize = (int)strlen(text);
|
||||
int k = 0;
|
||||
|
||||
for (int i = 0, len = 0; (i < textSize) && (k < MAX_TEXTLINES_COUNT); i++)
|
||||
{
|
||||
if ((text[i] == '\n') || (len == (MAX_TEXTLINES_LINE_LEN - 1)))
|
||||
{
|
||||
strncpy(lines[k], &text[i - len], len);
|
||||
len = 0;
|
||||
k++;
|
||||
}
|
||||
else len++;
|
||||
}
|
||||
|
||||
*count += k;
|
||||
return lines;
|
||||
}
|
||||
|
||||
// Unload text lines
|
||||
void UnloadTextLines(char **lines)
|
||||
{
|
||||
for (int i = 0; i < MAX_TEXTLINES_COUNT; i++) RL_FREE(lines[i]);
|
||||
RL_FREE(lines);
|
||||
}
|
||||
|
||||
// Get text length in bytes, check for \0 character
|
||||
unsigned int TextLength(const char *text)
|
||||
{
|
||||
|
||||
@ -9605,6 +9605,32 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "LoadTextLines",
|
||||
"description": "Load text as separate lines ('\\n')",
|
||||
"returnType": "char **",
|
||||
"params": [
|
||||
{
|
||||
"type": "const char *",
|
||||
"name": "text"
|
||||
},
|
||||
{
|
||||
"type": "int *",
|
||||
"name": "count"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "UnloadTextLines",
|
||||
"description": "Unload text lines",
|
||||
"returnType": "void",
|
||||
"params": [
|
||||
{
|
||||
"type": "char **",
|
||||
"name": "text"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "TextCopy",
|
||||
"description": "Copy one string to another, returns bytes copied",
|
||||
|
||||
@ -6845,6 +6845,23 @@ return {
|
||||
{type = "int *", name = "utf8Size"}
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "LoadTextLines",
|
||||
description = "Load text as separate lines ('\\n')",
|
||||
returnType = "char **",
|
||||
params = {
|
||||
{type = "const char *", name = "text"},
|
||||
{type = "int *", name = "count"}
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "UnloadTextLines",
|
||||
description = "Unload text lines",
|
||||
returnType = "void",
|
||||
params = {
|
||||
{type = "char **", name = "text"}
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "TextCopy",
|
||||
description = "Copy one string to another, returns bytes copied",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -679,7 +679,7 @@
|
||||
<Param type="unsigned int" name="frames" desc="" />
|
||||
</Callback>
|
||||
</Callbacks>
|
||||
<Functions count="584">
|
||||
<Functions count="586">
|
||||
<Function name="InitWindow" retType="void" paramCount="3" desc="Initialize window and OpenGL context">
|
||||
<Param type="int" name="width" desc="" />
|
||||
<Param type="int" name="height" desc="" />
|
||||
@ -2435,6 +2435,13 @@
|
||||
<Param type="int" name="codepoint" desc="" />
|
||||
<Param type="int *" name="utf8Size" desc="" />
|
||||
</Function>
|
||||
<Function name="LoadTextLines" retType="char **" paramCount="2" desc="Load text as separate lines ('\n')">
|
||||
<Param type="const char *" name="text" desc="" />
|
||||
<Param type="int *" name="count" desc="" />
|
||||
</Function>
|
||||
<Function name="UnloadTextLines" retType="void" paramCount="1" desc="Unload text lines">
|
||||
<Param type="char **" name="text" desc="" />
|
||||
</Function>
|
||||
<Function name="TextCopy" retType="int" paramCount="2" desc="Copy one string to another, returns bytes copied">
|
||||
<Param type="char *" name="dst" desc="" />
|
||||
<Param type="const char *" name="src" desc="" />
|
||||
|
||||
@ -148,11 +148,6 @@ static int UpdateRequiredFiles(void);
|
||||
static rlExampleInfo *LoadExamplesData(const char *fileName, const char *category, bool sort, int *exCount);
|
||||
static void UnloadExamplesData(rlExampleInfo *exInfo);
|
||||
|
||||
// Get text lines (by line-breaks '\n')
|
||||
// WARNING: It does not copy text data, just returns line pointers
|
||||
static char **LoadTextLines(const char *text, int *count);
|
||||
static void UnloadTextLines(char **text);
|
||||
|
||||
// Load example info from file header
|
||||
static rlExampleInfo *LoadExampleInfo(const char *exFileName);
|
||||
static void UnloadExampleInfo(rlExampleInfo *exInfo);
|
||||
@ -1775,39 +1770,6 @@ static int FileMove(const char *srcPath, const char *dstPath)
|
||||
return result;
|
||||
}
|
||||
|
||||
// Load text lines
|
||||
static char **LoadTextLines(const char *text, int *count)
|
||||
{
|
||||
#define MAX_TEXT_LINES 512
|
||||
#define MAX_TEXT_LINE_LEN 512
|
||||
|
||||
char **lines = (char **)RL_CALLOC(MAX_TEXT_LINES, sizeof(char *));
|
||||
for (int i = 0; i < MAX_TEXT_LINES; i++) lines[i] = (char *)RL_CALLOC(MAX_TEXT_LINE_LEN, 1);
|
||||
int textSize = (int)strlen(text);
|
||||
int k = 0;
|
||||
|
||||
for (int i = 0, len = 0; (i < textSize) && (k < MAX_TEXT_LINES); i++)
|
||||
{
|
||||
if ((text[i] == '\n') || (len == (MAX_TEXT_LINE_LEN - 1)))
|
||||
{
|
||||
strncpy(lines[k], &text[i - len], len);
|
||||
len = 0;
|
||||
k++;
|
||||
}
|
||||
else len++;
|
||||
}
|
||||
|
||||
*count += k;
|
||||
return lines;
|
||||
}
|
||||
|
||||
// Unload text lines
|
||||
static void UnloadTextLines(char **lines)
|
||||
{
|
||||
for (int i = 0; i < MAX_TEXT_LINES; i++) RL_FREE(lines[i]);
|
||||
RL_FREE(lines);
|
||||
}
|
||||
|
||||
// Get example info from example file header
|
||||
// NOTE: Expecting the example to follow raylib_example_template.c
|
||||
rlExampleInfo *LoadExampleInfo(const char *exFileName)
|
||||
|
||||
Reference in New Issue
Block a user