WString.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETCOREWSTRING_H
  28. #define ROCKETCOREWSTRING_H
  29. #include "Types.h"
  30. #include "Header.h"
  31. namespace Rocket {
  32. namespace Core {
  33. typedef StringBase< word > WStringBase;
  34. /**
  35. Stores a string of characters encoded in UCS-2 format (UTF-16 without support for supplementary characters).
  36. @author Peter Curry
  37. */
  38. class ROCKETCORE_API WString : public WStringBase
  39. {
  40. public:
  41. /// Constructs an empty string.
  42. WString();
  43. /// Constructs a string as a copy of another UCS-2 string.
  44. WString(const WStringBase& ucs2_string);
  45. /// Constructs a string from a sequence of UCS-2 encoded characters.
  46. WString(const word* ucs2_string_begin, const word* ucs2_string_end);
  47. /// Constructs a string from multiples of a UCS-2 encoded character.
  48. WString(WStringBase::size_type count, word ucs2_char);
  49. /// Constructs a string from a null-terminated sequence of UTF-8 encoded characters.
  50. WString(const char* utf8_string);
  51. /// Constructs a string from a sequence of UTF-8 encoded characters.
  52. WString(const char* utf8_string_begin, const char* utf8_string_end);
  53. /// Constructs a string from a sequence of UTF-8 encoded characters.
  54. WString(const String& utf8_string);
  55. /// Destroys the string.
  56. ~WString();
  57. /// Converts the string to UTF-8 encoding.
  58. String& ToUTF8(String& utf8_string, bool append = false) const;
  59. /// Assigns a UCS-2 string to this string.
  60. WString& operator=(const WStringBase& string);
  61. /// Assigns a UCS-2 string to this string.
  62. WString& operator=(const WString& string);
  63. /// Assigns a null-terminated UCS-2 string to this string.
  64. WString& operator=(const word* string);
  65. /// Converts a UTF-8 encoded string into UCS-2 and assigns it to this string.
  66. WString& operator=(const char* string);
  67. /// Checks equality between two UCS-2 encoded strings.
  68. bool operator==(const WString& string) const;
  69. /// Checks equality between this string and another string in UTF-8 encoding.
  70. bool operator==(const char* string) const;
  71. WStringBase::size_type Find(const WString& s, WStringBase::size_type pos = WStringBase::npos) const;
  72. WStringBase::size_type Find(const word* s, WStringBase::size_type pos = WStringBase::npos) const;
  73. WStringBase::size_type Find(const word& s, WStringBase::size_type pos = WStringBase::npos) const;
  74. word& operator[](WStringBase::size_type offset);
  75. word operator[](WStringBase::size_type offset) const;
  76. };
  77. }
  78. }
  79. #endif