فهرست منبع

Removed const_cast from Font and Properties because it wasn't necessary.
Fixed isStringNumeric in Properties.cpp

Darryl Gough 14 سال پیش
والد
کامیت
27f0fcbe9f
3فایلهای تغییر یافته به همراه23 افزوده شده و 22 حذف شده
  1. 10 10
      gameplay/src/Font.cpp
  2. 1 1
      gameplay/src/Font.h
  3. 12 11
      gameplay/src/Properties.cpp

+ 10 - 10
gameplay/src/Font.cpp

@@ -177,10 +177,10 @@ void Font::begin()
 void Font::drawText(const char* text, int x, int y, const Vector4& color, unsigned int size, bool rightToLeft)
 void Font::drawText(const char* text, int x, int y, const Vector4& color, unsigned int size, bool rightToLeft)
 {
 {
     float scale = (float)size / _size;
     float scale = (float)size / _size;
-    char* cursor = NULL;
+    const char* cursor = NULL;
     if (rightToLeft)
     if (rightToLeft)
     {
     {
-        cursor = const_cast<char*>(text);
+        cursor = text;
     }
     }
 
 
     int xPos = x, yPos = y;
     int xPos = x, yPos = y;
@@ -289,7 +289,7 @@ void Font::drawText(const char* text, int x, int y, const Vector4& color, unsign
 void Font::drawText(const char* text, const Rectangle& area, const Vector4& color, unsigned int size, Justify justify, bool wrap, bool rightToLeft)
 void Font::drawText(const char* text, const Rectangle& area, const Vector4& color, unsigned int size, Justify justify, bool wrap, bool rightToLeft)
 {
 {
     float scale = (float)size / _size;
     float scale = (float)size / _size;
-    char* token = const_cast<char*>(text);
+    const char* token = text;
     const int length = strlen(text);
     const int length = strlen(text);
     int yPos = area.y;
     int yPos = area.y;
 
 
@@ -305,7 +305,7 @@ void Font::drawText(const char* text, const Rectangle& area, const Vector4& colo
         hAlign = ALIGN_LEFT;
         hAlign = ALIGN_LEFT;
     }
     }
 
 
-    token = const_cast<char*>(text);
+    token = text;
 
 
     // For alignments other than top-left, need to calculate the y position to begin drawing from
     // For alignments other than top-left, need to calculate the y position to begin drawing from
     // and the starting x position of each line.  For right-to-left text, need to determine
     // and the starting x position of each line.  For right-to-left text, need to determine
@@ -476,12 +476,12 @@ void Font::drawText(const char* text, const Rectangle& area, const Vector4& colo
         xPos = *xPositionsIt++;
         xPos = *xPositionsIt++;
     }
     }
 
 
-    token = const_cast<char*>(text);
+    token = text;
     
     
     int iteration = 1;
     int iteration = 1;
     unsigned int lineLength;
     unsigned int lineLength;
     unsigned int currentLineLength = 0;
     unsigned int currentLineLength = 0;
-    char* lineStart;
+    const char* lineStart;
     std::vector<unsigned int>::const_iterator lineLengthsIt;
     std::vector<unsigned int>::const_iterator lineLengthsIt;
     if (rightToLeft)
     if (rightToLeft)
     {
     {
@@ -651,7 +651,7 @@ void Font::measureText(const char* text, unsigned int size, unsigned int* width,
 {
 {
     float scale = (float)size / _size;
     float scale = (float)size / _size;
     const int length = strlen(text);
     const int length = strlen(text);
-    char* token = const_cast<char*>(text);
+    const char* token = text;
 
 
     *width = 0;
     *width = 0;
     *height = 0;
     *height = 0;
@@ -691,7 +691,7 @@ void Font::measureText(const char* text, const Rectangle& viewport, unsigned int
         hAlign = ALIGN_LEFT;
         hAlign = ALIGN_LEFT;
     }
     }
 
 
-    char* token = const_cast<char*>(text);
+    const char* token = text;
     std::vector<bool> emptyLines;
     std::vector<bool> emptyLines;
     std::vector<Vector2> lines;
     std::vector<Vector2> lines;
 
 
@@ -1027,7 +1027,7 @@ unsigned int Font::getTokenWidth(const char* token, unsigned int length, unsigne
 
 
 unsigned int Font::getReversedTokenLength(const char* token, const char* bufStart)
 unsigned int Font::getReversedTokenLength(const char* token, const char* bufStart)
 {
 {
-    char* cursor = const_cast<char*>(token);
+    const char* cursor = token;
     char c = cursor[0];
     char c = cursor[0];
     unsigned int length = 0;
     unsigned int length = 0;
 
 
@@ -1046,7 +1046,7 @@ unsigned int Font::getReversedTokenLength(const char* token, const char* bufStar
     return length;
     return length;
 }
 }
 
 
-bool Font::handleDelimiters(char** token, const unsigned int size, const int iteration, const int areaX, int* xPos, int* yPos, unsigned int* lineLength,
+bool Font::handleDelimiters(const char** token, const unsigned int size, const int iteration, const int areaX, int* xPos, int* yPos, unsigned int* lineLength,
                       std::vector<int>::const_iterator* xPositionsIt, std::vector<int>::const_iterator xPositionsEnd)
                       std::vector<int>::const_iterator* xPositionsIt, std::vector<int>::const_iterator xPositionsEnd)
 {
 {
     char delimiter = *token[0];
     char delimiter = *token[0];

+ 1 - 1
gameplay/src/Font.h

@@ -198,7 +198,7 @@ private:
     unsigned int getReversedTokenLength(const char* token, const char* bufStart);
     unsigned int getReversedTokenLength(const char* token, const char* bufStart);
 
 
     // Returns false if EOF was reached, true otherwise.
     // Returns false if EOF was reached, true otherwise.
-    bool handleDelimiters(char** token, const unsigned int size, const int iteration, const int areaX, int* xPos, int* yPos, unsigned int* lineLength,
+    bool handleDelimiters(const char** token, const unsigned int size, const int iteration, const int areaX, int* xPos, int* yPos, unsigned int* lineLength,
                           std::vector<int>::const_iterator* xPositionsIt, std::vector<int>::const_iterator xPositionsEnd);
                           std::vector<int>::const_iterator* xPositionsIt, std::vector<int>::const_iterator xPositionsEnd);
     void addLineInfo(const Rectangle& area, int lineWidth, int lineLength, Justify hAlign,
     void addLineInfo(const Rectangle& area, int lineWidth, int lineLength, Justify hAlign,
                      std::vector<int>* xPositions, std::vector<unsigned int>* lineLengths, bool rightToLeft);
                      std::vector<int>* xPositions, std::vector<unsigned int>* lineLengths, bool rightToLeft);

+ 12 - 11
gameplay/src/Properties.cpp

@@ -324,34 +324,35 @@ bool Properties::exists(const char* name) const
     return _properties.find(name) != _properties.end();
     return _properties.find(name) != _properties.end();
 }
 }
 
 
-bool isStringNumeric(const char* str)
+const bool isStringNumeric(const char* str)
 {
 {
-    char* ptr = const_cast<char*>(str);
+    // The first character may be '-'
+    if (*str == '-')
+        str++;
 
 
-    // First character must be a digit
-    if (!isdigit(*ptr))
+    // The first character after the sign must be a digit
+    if (!isdigit(*str))
         return false;
         return false;
-    ptr++;
+    str++;
 
 
     // All remaining characters must be digits, with a single decimal (.) permitted
     // All remaining characters must be digits, with a single decimal (.) permitted
     unsigned int decimalCount = 0;
     unsigned int decimalCount = 0;
-    while (*ptr)
+    while (*str)
     {
     {
-        if (!isdigit(*ptr))
+        if (!isdigit(*str))
         {
         {
-            if (*ptr == '.' && decimalCount == 0)
+            if (*str == '.' && decimalCount == 0)
             {
             {
                 // Max of 1 decimal allowed
                 // Max of 1 decimal allowed
                 decimalCount++;
                 decimalCount++;
             }
             }
             else
             else
             {
             {
-                // Not a number
+                return false;
             }
             }
         }
         }
-        ptr++;
+        str++;
     }
     }
-    
     return true;
     return true;
 }
 }