REVIEWED: Remove some const
from text buffer return values
Lately got some compilation `errors` related, it seems GCC 14 interprets some `const`-missmatch as errors instead of warnings (as previous versions). But in any case, I don't see why an user won't be able to operate directly over of those returned buffers; `const` adds a restriction (for security reasons?) that in my opinion is useless. From an expert on compilers (w64devkit creator), here there are some notes I agree with: ``` No const. It serves no practical role in optimization, and I cannot recall an instance where it caught, or would have caught, a mistake. I held out for awhile as prototype documentation, but on reflection I found that good parameter names were sufficient. Dropping const has made me noticeably more productive by reducing cognitive load and eliminating visual clutter. I now believe its inclusion in C was a costly mistake. (One small exception: I still like it as a hint to place static tables in read-only memory closer to the code. I’ll cast away the const if needed. This is only of minor importance.) ``` Ref: https://nullprogram.com/blog/2023/10/08/
This commit is contained in:
parent
ddd86a3387
commit
bf8962dbc7
2 changed files with 15 additions and 15 deletions
14
src/raylib.h
14
src/raylib.h
|
@ -1510,15 +1510,15 @@ RLAPI const char *TextFormat(const char *text, ...);
|
||||||
RLAPI const char *TextSubtext(const char *text, int position, int length); // Get a piece of a text string
|
RLAPI const char *TextSubtext(const char *text, int position, int length); // Get a piece of a text string
|
||||||
RLAPI char *TextReplace(const char *text, const char *replace, const char *by); // Replace text string (WARNING: memory must be freed!)
|
RLAPI char *TextReplace(const char *text, const char *replace, const char *by); // Replace text string (WARNING: memory must be freed!)
|
||||||
RLAPI char *TextInsert(const char *text, const char *insert, int position); // Insert text in a position (WARNING: memory must be freed!)
|
RLAPI char *TextInsert(const char *text, const char *insert, int position); // Insert text in a position (WARNING: memory must be freed!)
|
||||||
RLAPI const char *TextJoin(const char **textList, int count, const char *delimiter); // Join text strings with delimiter
|
RLAPI char *TextJoin(const char **textList, int count, const char *delimiter); // Join text strings with delimiter
|
||||||
RLAPI const char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings
|
RLAPI char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings
|
||||||
RLAPI void TextAppend(char *text, const char *append, int *position); // Append text at specific position and move cursor!
|
RLAPI void TextAppend(char *text, const char *append, int *position); // Append text at specific position and move cursor!
|
||||||
RLAPI int TextFindIndex(const char *text, const char *find); // Find first text occurrence within a string
|
RLAPI int TextFindIndex(const char *text, const char *find); // Find first text occurrence within a string
|
||||||
RLAPI const char *TextToUpper(const char *text); // Get upper case version of provided string
|
RLAPI char *TextToUpper(const char *text); // Get upper case version of provided string
|
||||||
RLAPI const char *TextToLower(const char *text); // Get lower case version of provided string
|
RLAPI char *TextToLower(const char *text); // Get lower case version of provided string
|
||||||
RLAPI const char *TextToPascal(const char *text); // Get Pascal case notation version of provided string
|
RLAPI char *TextToPascal(const char *text); // Get Pascal case notation version of provided string
|
||||||
RLAPI const char *TextToSnake(const char *text); // Get Snake case notation version of provided string
|
RLAPI char *TextToSnake(const char *text); // Get Snake case notation version of provided string
|
||||||
RLAPI const char *TextToCamel(const char *text); // Get Camel 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 int TextToInteger(const char *text); // Get integer value from text
|
||||||
RLAPI float TextToFloat(const char *text); // Get float value from text
|
RLAPI float TextToFloat(const char *text); // Get float value from text
|
||||||
|
|
16
src/rtext.c
16
src/rtext.c
|
@ -1629,7 +1629,7 @@ char *TextInsert(const char *text, const char *insert, int position)
|
||||||
|
|
||||||
// Join text strings with delimiter
|
// Join text strings with delimiter
|
||||||
// REQUIRES: memset(), memcpy()
|
// REQUIRES: memset(), memcpy()
|
||||||
const char *TextJoin(const char **textList, int count, const char *delimiter)
|
char *TextJoin(const char **textList, int count, const char *delimiter)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
@ -1663,7 +1663,7 @@ const char *TextJoin(const char **textList, int count, const char *delimiter)
|
||||||
|
|
||||||
// Split string into multiple strings
|
// Split string into multiple strings
|
||||||
// REQUIRES: memset()
|
// REQUIRES: memset()
|
||||||
const char **TextSplit(const char *text, char delimiter, int *count)
|
char **TextSplit(const char *text, char delimiter, int *count)
|
||||||
{
|
{
|
||||||
// NOTE: Current implementation returns a copy of the provided string with '\0' (string end delimiter)
|
// NOTE: Current implementation returns a copy of the provided string with '\0' (string end delimiter)
|
||||||
// inserted between strings defined by "delimiter" parameter. No memory is dynamically allocated,
|
// inserted between strings defined by "delimiter" parameter. No memory is dynamically allocated,
|
||||||
|
@ -1671,7 +1671,7 @@ const char **TextSplit(const char *text, char delimiter, int *count)
|
||||||
// 1. Maximum number of possible split strings is set by MAX_TEXTSPLIT_COUNT
|
// 1. Maximum number of possible split strings is set by MAX_TEXTSPLIT_COUNT
|
||||||
// 2. Maximum size of text to split is MAX_TEXT_BUFFER_LENGTH
|
// 2. Maximum size of text to split is MAX_TEXT_BUFFER_LENGTH
|
||||||
|
|
||||||
static const char *result[MAX_TEXTSPLIT_COUNT] = { NULL };
|
static char *result[MAX_TEXTSPLIT_COUNT] = { NULL };
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
|
||||||
|
@ -1727,7 +1727,7 @@ int TextFindIndex(const char *text, const char *find)
|
||||||
// Get upper case version of provided string
|
// Get upper case version of provided string
|
||||||
// WARNING: Limited functionality, only basic characters set
|
// WARNING: Limited functionality, only basic characters set
|
||||||
// TODO: Support UTF-8 diacritics to upper-case, check codepoints
|
// TODO: Support UTF-8 diacritics to upper-case, check codepoints
|
||||||
const char *TextToUpper(const char *text)
|
char *TextToUpper(const char *text)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
@ -1746,7 +1746,7 @@ const char *TextToUpper(const char *text)
|
||||||
|
|
||||||
// Get lower case version of provided string
|
// Get lower case version of provided string
|
||||||
// WARNING: Limited functionality, only basic characters set
|
// WARNING: Limited functionality, only basic characters set
|
||||||
const char *TextToLower(const char *text)
|
char *TextToLower(const char *text)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
@ -1765,7 +1765,7 @@ const char *TextToLower(const char *text)
|
||||||
|
|
||||||
// Get Pascal case notation version of provided string
|
// Get Pascal case notation version of provided string
|
||||||
// WARNING: Limited functionality, only basic characters set
|
// WARNING: Limited functionality, only basic characters set
|
||||||
const char *TextToPascal(const char *text)
|
char *TextToPascal(const char *text)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
@ -1793,7 +1793,7 @@ const char *TextToPascal(const char *text)
|
||||||
|
|
||||||
// Get snake case notation version of provided string
|
// Get snake case notation version of provided string
|
||||||
// WARNING: Limited functionality, only basic characters set
|
// WARNING: Limited functionality, only basic characters set
|
||||||
const char *TextToSnake(const char *text)
|
char *TextToSnake(const char *text)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = {0};
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = {0};
|
||||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
@ -1821,7 +1821,7 @@ const char *TextToSnake(const char *text)
|
||||||
|
|
||||||
// Get Camel case notation version of provided string
|
// Get Camel case notation version of provided string
|
||||||
// WARNING: Limited functionality, only basic characters set
|
// WARNING: Limited functionality, only basic characters set
|
||||||
const char *TextToCamel(const char *text)
|
char *TextToCamel(const char *text)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = {0};
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = {0};
|
||||||
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue