@@ -1448,36 +1448,38 @@ Rectangle GetGlyphAtlasRec(Font font, int codepoint)
14481448// Text strings management functions
14491449//----------------------------------------------------------------------------------
14501450// Load text as separate lines ('\n')
1451- // WARNING: There is a limit set for number of lines and line-size
1451+ // NOTE: Returned lines end with null terminator '\0'
14521452char * * LoadTextLines (const char * text , int * count )
14531453{
1454- #define MAX_TEXTLINES_COUNT 512
1455- #define MAX_TEXTLINES_LINE_LEN 512
1454+ int lineCount = 1 ;
1455+ int textSize = strlen ( text );
14561456
1457- char * * lines = (char * * )RL_CALLOC (MAX_TEXTLINES_COUNT , sizeof (char * ));
1458- for (int i = 0 ; i < MAX_TEXTLINES_COUNT ; i ++ ) lines [i ] = (char * )RL_CALLOC (MAX_TEXTLINES_LINE_LEN , 1 );
1459- int textSize = (int )strlen (text );
1460- int k = 0 ;
1457+ // Text pass to get required line count
1458+ for (int i = 0 ; i < textSize ; i ++ )
1459+ {
1460+ if (text [i ] == '\n' ) lineCount ++ ;
1461+ }
14611462
1462- for (int i = 0 , len = 0 ; (i < textSize ) && (k < MAX_TEXTLINES_COUNT ); i ++ )
1463+ char * * lines = (char * * )RL_CALLOC (lineCount , sizeof (char * ));
1464+ for (int i = 0 , l = 0 , lineLen = 0 ; i < lineCount ; i ++ , lineLen ++ )
14631465 {
1464- if (( text [i ] == '\n' ) || ( len == ( MAX_TEXTLINES_LINE_LEN - 1 )) )
1466+ if (text [i ] == '\n' )
14651467 {
1466- strncpy (lines [k ], & text [i - len ], len );
1467- len = 0 ;
1468- k ++ ;
1468+ lines [l ] = (char * )RL_CALLOC (lineLen + 1 , 1 );
1469+ strncpy (lines [l ], & text [i - lineLen ], lineLen );
1470+ lineLen = 0 ;
1471+ l ++ ;
14691472 }
1470- else len ++ ;
14711473 }
14721474
1473- * count += k ;
1475+ * count = lineCount ;
14741476 return lines ;
14751477}
14761478
14771479// Unload text lines
1478- void UnloadTextLines (char * * lines )
1480+ void UnloadTextLines (char * * lines , int lineCount )
14791481{
1480- for (int i = 0 ; i < MAX_TEXTLINES_COUNT ; i ++ ) RL_FREE (lines [i ]);
1482+ for (int i = 0 ; i < lineCount ; i ++ ) RL_FREE (lines [i ]);
14811483 RL_FREE (lines );
14821484}
14831485
0 commit comments