From c78c05eac543bd6b310bad39a6ba8c303c08a253 Mon Sep 17 00:00:00 2001 From: Skabunkel <> Date: Sun, 10 Feb 2019 09:03:27 +0100 Subject: [PATCH] Fixed spelling mistakes --- src/raylib.h | 4 ++-- src/text.c | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index c9886e467..6b7196cd6 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1184,9 +1184,9 @@ 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 const char *TextTrim(const char *text, char trimChar); // Removes all chars equal to trimChar from the begining and end of the given text (memory should be freed!) +RLAPI const char *TextTrim(const char *text, char trimChar); // Removes all chars equal to trimChar from the beginning and end of the given text (memory should be freed!) RLAPI const char *TextRightTrim(const char *text, char trimChar); // Removes all chars equal to trimChar from the end of the given text (memory should be freed!) -RLAPI const char *TextLeftTrim(const char *text, char trimChar); // Removes all chars equal to trimChar from the begining of the given text (memory should be freed!) +RLAPI const char *TextLeftTrim(const char *text, char trimChar); // Removes all chars equal to trimChar from the beginning of the given text (memory should be freed!) //------------------------------------------------------------------------------------ // Basic 3d Shapes Drawing Functions (Module: models) diff --git a/src/text.c b/src/text.c index 7179b2a7f..31d840557 100644 --- a/src/text.c +++ b/src/text.c @@ -1089,17 +1089,18 @@ const char *TextSubtext(const char *text, int position, int length) return buffer; } -// removes a specific char from the begining of a string +// removes a specific char from the beginning of a string // REQUIRES: strlen() const char *TextLeftTrim(const char *text, char trimChar) { int textLength = strlen(text); + int leftOffset = 0; for(leftOffset; leftOffset < textLength; leftOffset++) { - if(*(text + leftOffset) != trimChar) - break; + if(*(text + leftOffset) != trimChar) break; } + const char *subText = TextSubtext(text, leftOffset, textLength-leftOffset); int subTextLength = strlen(subText); char *result = malloc(subTextLength+1); @@ -1116,12 +1117,13 @@ const char *TextLeftTrim(const char *text, char trimChar) const char *TextRightTrim(const char *text, char trimChar) { int textLength = strlen(text); + int rightOffset = textLength-1; for(rightOffset; -1 < rightOffset; rightOffset--) { - if(*(text + rightOffset) != trimChar) - break; + if(*(text + rightOffset) != trimChar) break; } + const char *subText = TextSubtext(text, 0, rightOffset+1); int subTextLength = strlen(subText); char *result = malloc(subTextLength+1); @@ -1133,23 +1135,24 @@ const char *TextRightTrim(const char *text, char trimChar) return result; } -// removes a specific char from the begining of a string +// removes a specific char from the beginning and end of a string // REQUIRES: strlen() const char *TextTrim(const char *text, char trimChar) { int textLength = strlen(text); + int leftOffset = 0; for(leftOffset; leftOffset < textLength; leftOffset++) { - if(*(text + leftOffset) != trimChar) - break; + if(*(text + leftOffset) != trimChar) break; } + int rightOffset = textLength-1; for(rightOffset; leftOffset < rightOffset; rightOffset--) { - if(*(text + rightOffset) != trimChar) - break; + if(*(text + rightOffset) != trimChar) break; } + const char *subText = TextSubtext(text, leftOffset, rightOffset+1-leftOffset); int subTextLength = strlen(subText); char *result = malloc(subTextLength+1);