StringUtils.h 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "Color.h"
  25. #include "Quaternion.h"
  26. #include "Rect.h"
  27. #include "StringHash.h"
  28. #include "Vector4.h"
  29. #include "Vector.h"
  30. /// Split string with a separator char
  31. Vector<String> Split(const String& source, char separator);
  32. /// Parse a bool from a string. Check for the substring "true" case-insensitively
  33. bool ToBool(const String& source);
  34. /// Parse a float from a string
  35. float ToFloat(const String& source);
  36. /// Parse an integer from a string
  37. int ToInt(const String& source);
  38. /// Parse an unsigned integer from a string
  39. unsigned ToUInt(const String& source);
  40. /// Parse a Color from a string
  41. Color ToColor(const String& source);
  42. /// Parse an IntRect from a string
  43. IntRect ToIntRect(const String& source);
  44. /// Parse an IntVector2 from a string
  45. IntVector2 ToIntVector2(const String& source);
  46. /// Parse a Quaternion from a string. If only 3 components specified, convert Euler angles (degrees) to quaternion
  47. Quaternion ToQuaternion(const String& source);
  48. /// Parse a Rect from a string
  49. Rect ToRect(const String& source);
  50. /// Parse a Vector2 from a string
  51. Vector2 ToVector2(const String& source);
  52. /// Parse a Vector3 from a string
  53. Vector3 ToVector3(const String& source);
  54. /// Parse a Vector4 from a string
  55. Vector4 ToVector4(const String& source, bool allowMissingCoords = false);
  56. /// Convert a bool to string
  57. String ToString(bool value);
  58. /// Convert a float to string
  59. String ToString(float value);
  60. /// Convert an integer to string
  61. String ToString(int value);
  62. /// Convert an unsigned integer to string
  63. String ToString(unsigned value);
  64. /// Convert a Color to string
  65. String ToString(const Color& value);
  66. /// Convert an IntRect to string
  67. String ToString(const IntRect& value);
  68. /// Convert an IntVector2 to string
  69. String ToString(const IntVector2& value);
  70. /// Convert a Quaternion to string
  71. String ToString(const Quaternion& value);
  72. /// Convert a Rect to string
  73. String ToString(const Rect& value);
  74. /// Convert a StringHash to string. Return the reverse mapping if found
  75. String ToString(const StringHash& value);
  76. /// Convert a ShortStringHash to string. Return the reverse mapping if found
  77. String ToString(const ShortStringHash& value);
  78. /// Convert a Vector2 to string
  79. String ToString(const Vector2& value);
  80. /// Convert a Vector3 to string
  81. String ToString(const Vector3& value);
  82. /// Convert a Vector4 to string
  83. String ToString(const Vector4& value);
  84. /// Convert a pointer to string (returns hexadecimal)
  85. String ToString(void* value);
  86. /// Convert an unsigned integer to string as hexadecimal
  87. String ToStringHex(unsigned value);
  88. /// Return an index to a string list corresponding to the given string, or a default value if not found
  89. unsigned GetStringListIndex(const String& value, const String* strings, unsigned count, unsigned defaultIndex,
  90. bool caseSensitive = false);