StringUtils.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /// 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 float from a string.
  32. float ToFloat(const String& source);
  33. /// Parse an integer from a string.
  34. int ToInt(const String& source);
  35. /// Parse an unsigned integer from a string.
  36. unsigned ToUInt(const String& source);
  37. /// Parse a Color from a string.
  38. Color ToColor(const String& source);
  39. /// Parse an IntRect from a string.
  40. IntRect ToIntRect(const String& source);
  41. /// Parse an IntVector2 from a string.
  42. IntVector2 ToIntVector2(const String& source);
  43. /// Parse a Quaternion from a string. If only 3 components specified, convert Euler angles (degrees) to quaternion.
  44. Quaternion ToQuaternion(const String& source);
  45. /// Parse a Rect from a string.
  46. Rect ToRect(const String& source);
  47. /// Parse a Vector2 from a string.
  48. Vector2 ToVector2(const String& source);
  49. /// Parse a Vector3 from a string.
  50. Vector3 ToVector3(const String& source);
  51. /// Parse a Vector4 from a string.
  52. Vector4 ToVector4(const String& source, bool allowMissingCoords = false);
  53. /// Convert a pointer to string (returns hexadecimal.)
  54. String ToString(void* value);
  55. /// Convert an unsigned integer to string as hexadecimal.
  56. String ToStringHex(unsigned value);
  57. /// 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.
  58. unsigned GetStringListIndex(const String& value, const String* strings, unsigned defaultIndex, bool caseSensitive = false);