UTF8String.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // UTF8String.h
  3. //
  4. // Library: Foundation
  5. // Package: Text
  6. // Module: UTF8String
  7. //
  8. // Definition of the UTF8 string functions.
  9. //
  10. // Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Foundation_UTF8String_INCLUDED
  16. #define Foundation_UTF8String_INCLUDED
  17. #include "Poco/Foundation.h"
  18. namespace Poco {
  19. struct Foundation_API UTF8
  20. /// This class provides static methods that are UTF-8 capable variants
  21. /// of the same functions in Poco/String.h.
  22. ///
  23. /// The various variants of icompare() provide case insensitive comparison
  24. /// for UTF-8 encoded strings.
  25. ///
  26. /// toUpper(), toUpperInPlace(), toLower() and toLowerInPlace() provide
  27. /// Unicode-based character case transformation for UTF-8 encoded strings.
  28. ///
  29. /// removeBOM() removes the UTF-8 Byte Order Mark sequence (0xEF, 0xBB, 0xBF)
  30. /// from the beginning of the given string, if it's there.
  31. {
  32. static int icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2);
  33. static int icompare(const std::string& str1, const std::string& str2);
  34. static int icompare(const std::string& str1, std::string::size_type n1, const std::string& str2, std::string::size_type n2);
  35. static int icompare(const std::string& str1, std::string::size_type n, const std::string& str2);
  36. static int icompare(const std::string& str1, std::string::size_type pos, std::string::size_type n, const std::string& str2);
  37. static int icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n1, const std::string& str2, std::string::size_type pos2, std::string::size_type n2);
  38. static int icompare(const std::string& str1, std::string::size_type pos1, std::string::size_type n, const std::string& str2, std::string::size_type pos2);
  39. static int icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr);
  40. static int icompare(const std::string& str, std::string::size_type pos, const std::string::value_type* ptr);
  41. static int icompare(const std::string& str, const std::string::value_type* ptr);
  42. static std::string toUpper(const std::string& str);
  43. static std::string& toUpperInPlace(std::string& str);
  44. static std::string toLower(const std::string& str);
  45. static std::string& toLowerInPlace(std::string& str);
  46. static void removeBOM(std::string& str);
  47. /// Remove the UTF-8 Byte Order Mark sequence (0xEF, 0xBB, 0xBF)
  48. /// from the beginning of the string, if it's there.
  49. static std::string escape(const std::string& s, bool strictJSON = false);
  50. /// Escapes a string. Special characters like tab, backslash, ... are
  51. /// escaped. Unicode characters are escaped to \uxxxx.
  52. /// If strictJSON is true, \a and \v will be escaped to \\u0007 and \\u000B
  53. /// instead of \\a and \\v for strict JSON conformance.
  54. static std::string escape(const std::string::const_iterator& begin, const std::string::const_iterator& end, bool strictJSON = false);
  55. /// Escapes a string. Special characters like tab, backslash, ... are
  56. /// escaped. Unicode characters are escaped to \uxxxx.
  57. /// If strictJSON is true, \a and \v will be escaped to \\u0007 and \\u000B
  58. /// instead of \\a and \\v for strict JSON conformance.
  59. static std::string unescape(const std::string& s);
  60. /// Creates an UTF8 string from a string that contains escaped characters.
  61. static std::string unescape(const std::string::const_iterator& begin, const std::string::const_iterator& end);
  62. /// Creates an UTF8 string from a string that contains escaped characters.
  63. };
  64. } // namespace Poco
  65. #endif // Foundation_UTF8String_INCLUDED