StringUtils.h 4.5 KB

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