StringUtils.h 4.5 KB

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