StringUtils.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 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. /// Parse a bool from a string. Check for the first non-empty character (converted to lowercase) being either 't', 'y' or '1'.
  30. bool ToBool(const String& source);
  31. /// Parse a bool from a C string. Check for the first non-empty character (converted to lowercase) being either 't', 'y' or '1'.
  32. bool ToBool(const char* source);
  33. /// Parse a float from a string.
  34. float ToFloat(const String& source);
  35. /// Parse a float from a C string.
  36. float ToFloat(const char* source);
  37. /// Parse an integer from a string.
  38. int ToInt(const String& source);
  39. /// Parse an integer from a C string.
  40. int ToInt(const char* source);
  41. /// Parse an unsigned integer from a string.
  42. unsigned ToUInt(const String& source);
  43. /// Parse an unsigned integer from a C string.
  44. unsigned ToUInt(const char* source);
  45. /// Parse a Color from a string.
  46. Color ToColor(const String& source);
  47. /// Parse a Color from a C string.
  48. Color ToColor(const char* source);
  49. /// Parse an IntRect from a string.
  50. IntRect ToIntRect(const String& source);
  51. /// Parse an IntRect from a C string.
  52. IntRect ToIntRect(const char* source);
  53. /// Parse an IntVector2 from a string.
  54. IntVector2 ToIntVector2(const String& source);
  55. /// Parse an IntVector2 from a C string.
  56. IntVector2 ToIntVector2(const char* source);
  57. /// Parse a Quaternion from a string. If only 3 components specified, convert Euler angles (degrees) to quaternion.
  58. Quaternion ToQuaternion(const String& source);
  59. /// Parse a Quaternion from a C string. If only 3 components specified, convert Euler angles (degrees) to quaternion.
  60. Quaternion ToQuaternion(const char* source);
  61. /// Parse a Rect from a string.
  62. Rect ToRect(const String& source);
  63. /// Parse a Rect from a C string.
  64. Rect ToRect(const char* source);
  65. /// Parse a Vector2 from a string.
  66. Vector2 ToVector2(const String& source);
  67. /// Parse a Vector2 from a C string.
  68. Vector2 ToVector2(const char* source);
  69. /// Parse a Vector3 from a string.
  70. Vector3 ToVector3(const String& source);
  71. /// Parse a Vector3 from a C string.
  72. Vector3 ToVector3(const char* source);
  73. /// Parse a Vector4 from a string.
  74. Vector4 ToVector4(const String& source, bool allowMissingCoords = false);
  75. /// Parse a Vector4 from a C string.
  76. Vector4 ToVector4(const char* source, bool allowMissingCoords = false);
  77. /// Convert a pointer to string (returns hexadecimal.)
  78. String ToString(void* value);
  79. /// Convert an unsigned integer to string as hexadecimal.
  80. String ToStringHex(unsigned value);
  81. /// Return an index to a string list corresponding to the given string, or a default value if not found. The string list must be empty-terminated.
  82. unsigned GetStringListIndex(const String& value, const String* strings, unsigned defaultIndex, bool caseSensitive = false);
  83. /// Return an index to a string list corresponding to the given C string, or a default value if not found. The string list must be empty-terminated.
  84. unsigned GetStringListIndex(const char* value, const String* strings, unsigned defaultIndex, bool caseSensitive = false);