Skip to content

Commit

Permalink
fixed coding style in function TextToFloat (#3627)
Browse files Browse the repository at this point in the history
* function to convert string to float

* fix code to match coding conventions
  • Loading branch information
benjibst authored Dec 13, 2023
1 parent a57a0ec commit 6083d2b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,7 @@ RLAPI const char *TextToUpper(const char *text); // Get upp
RLAPI const 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 int TextToInteger(const char *text); // Get integer value from text (negative values not supported)
RLAPI float TextToFloat(const char *text); // Get float value from text (negative values not supported)

//------------------------------------------------------------------------------------
// Basic 3d Shapes Drawing Functions (Module: models)
Expand Down
22 changes: 22 additions & 0 deletions src/rtext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,28 @@ int TextToInteger(const char *text)
return value*sign;
}

float TextToFloat(const char *text)
{
float value = 0.0f;
float sign = 1.0f;

if ((text[0] == '+') || (text[0] == '-'))
{
if (text[0] == '-') sign = -1;
text++;
}
int i = 0;
for (; ((text[i] >= '0') && (text[i] <= '9')); ++i) value = value*10.0f + (float)(text[i] - '0');
if (text[i++] != '.') return value*sign;
float divisor = 10.0f;
for (; ((text[i] >= '0') && (text[i] <= '9')); ++i)
{
value += ((float)(text[i] - '0'))/divisor;
divisor = divisor*10.0f;
}
return value;
}

#if defined(SUPPORT_TEXT_MANIPULATION)
// Copy one string to another, returns bytes copied
int TextCopy(char *dst, const char *src)
Expand Down

0 comments on commit 6083d2b

Please sign in to comment.