Browse Source

Str.cpp: fix warnings | Add test for String::Split()

1vanK 3 years ago
parent
commit
1d84eb9ca1
2 changed files with 14 additions and 5 deletions
  1. 9 0
      Source/Tools/Tests/Container/Str.cpp
  2. 5 5
      Source/Urho3D/Container/Str.cpp

+ 9 - 0
Source/Tools/Tests/Container/Str.cpp

@@ -49,4 +49,13 @@ void Test_Container_Str()
         str.Replace(10, 3, "Array<T>");
         str.Replace(10, 3, "Array<T>");
         assert(str == "bool Swap(Array<T>&)");
         assert(str == "bool Swap(Array<T>&)");
     }
     }
+
+    {
+        const char* str = "aa bb CC";
+        Vector<String> substrings = String::Split(str, ' ');
+        assert(substrings.Size() == 3);
+        assert(substrings[0] == "aa");
+        assert(substrings[1] == "bb");
+        assert(substrings[2] == "CC");
+    }
 }
 }

+ 5 - 5
Source/Urho3D/Container/Str.cpp

@@ -940,7 +940,7 @@ String String::SubstringUTF8(i32 pos, i32 length) const
 void String::EncodeUTF8(char*& dest, c32 unicodeChar)
 void String::EncodeUTF8(char*& dest, c32 unicodeChar)
 {
 {
     if (unicodeChar < 0x80)
     if (unicodeChar < 0x80)
-        *dest++ = unicodeChar;
+        *dest++ = (char)unicodeChar;
     else if (unicodeChar < 0x800)
     else if (unicodeChar < 0x800)
     {
     {
         dest[0] = (char)(0xc0u | ((unicodeChar >> 6u) & 0x1fu));
         dest[0] = (char)(0xc0u | ((unicodeChar >> 6u) & 0x1fu));
@@ -1045,7 +1045,7 @@ c32 String::DecodeUTF8(const char*& src)
 void String::EncodeUTF16(wchar_t*& dest, c32 unicodeChar)
 void String::EncodeUTF16(wchar_t*& dest, c32 unicodeChar)
 {
 {
     if (unicodeChar < 0x10000)
     if (unicodeChar < 0x10000)
-        *dest++ = unicodeChar;
+        *dest++ = (wchar_t)unicodeChar;
     else
     else
     {
     {
         unicodeChar -= 0x10000;
         unicodeChar -= 0x10000;
@@ -1096,14 +1096,14 @@ Vector<String> String::Split(const char* str, char separator, bool keepEmptyStri
         {
         {
             const ptrdiff_t splitLen = splitEnd - str;
             const ptrdiff_t splitLen = splitEnd - str;
             if (splitLen > 0 || keepEmptyStrings)
             if (splitLen > 0 || keepEmptyStrings)
-                ret.Push(String(str, splitLen));
+                ret.Push(String(str, (i32)splitLen));
             str = splitEnd + 1;
             str = splitEnd + 1;
         }
         }
     }
     }
 
 
     const ptrdiff_t splitLen = strEnd - str;
     const ptrdiff_t splitLen = strEnd - str;
     if (splitLen > 0 || keepEmptyStrings)
     if (splitLen > 0 || keepEmptyStrings)
-        ret.Push(String(str, splitLen));
+        ret.Push(String(str, (i32)splitLen));
 
 
     return ret;
     return ret;
 }
 }
@@ -1302,7 +1302,7 @@ WString::WString(const String& str) :
     {
     {
         wchar_t* dest = temp;
         wchar_t* dest = temp;
         String::EncodeUTF16(dest, str.NextUTF8Char(byteOffset));
         String::EncodeUTF16(dest, str.NextUTF8Char(byteOffset));
-        neededSize += dest - temp;
+        neededSize += (i32)(dest - temp);
     }
     }
 
 
     Resize(neededSize);
     Resize(neededSize);