TextConverter.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // TextConverter.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/TextConverter.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Text
  8. // Module: TextConverter
  9. //
  10. // Definition of the TextConverter class.
  11. //
  12. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_TextConverter_INCLUDED
  18. #define Foundation_TextConverter_INCLUDED
  19. #include "Poco/Foundation.h"
  20. namespace Poco {
  21. class TextEncoding;
  22. class Foundation_API TextConverter
  23. /// A TextConverter converts strings from one encoding
  24. /// into another.
  25. {
  26. public:
  27. typedef int (*Transform)(int);
  28. /// Transform function for convert.
  29. TextConverter(const TextEncoding& inEncoding, const TextEncoding& outEncoding, int defaultChar = '?');
  30. /// Creates the TextConverter. The encoding objects must not be deleted while the
  31. /// TextConverter is in use.
  32. ~TextConverter();
  33. /// Destroys the TextConverter.
  34. int convert(const std::string& source, std::string& destination, Transform trans);
  35. /// Converts the source string from inEncoding to outEncoding
  36. /// and appends the result to destination. Every character is
  37. /// passed to the transform function.
  38. /// If a character cannot be represented in outEncoding, defaultChar
  39. /// is used instead.
  40. /// Returns the number of encoding errors (invalid byte sequences
  41. /// in source).
  42. int convert(const void* source, int length, std::string& destination, Transform trans);
  43. /// Converts the source buffer from inEncoding to outEncoding
  44. /// and appends the result to destination. Every character is
  45. /// passed to the transform function.
  46. /// If a character cannot be represented in outEncoding, defaultChar
  47. /// is used instead.
  48. /// Returns the number of encoding errors (invalid byte sequences
  49. /// in source).
  50. int convert(const std::string& source, std::string& destination);
  51. /// Converts the source string from inEncoding to outEncoding
  52. /// and appends the result to destination.
  53. /// If a character cannot be represented in outEncoding, defaultChar
  54. /// is used instead.
  55. /// Returns the number of encoding errors (invalid byte sequences
  56. /// in source).
  57. int convert(const void* source, int length, std::string& destination);
  58. /// Converts the source buffer from inEncoding to outEncoding
  59. /// and appends the result to destination.
  60. /// If a character cannot be represented in outEncoding, defaultChar
  61. /// is used instead.
  62. /// Returns the number of encoding errors (invalid byte sequences
  63. /// in source).
  64. private:
  65. TextConverter();
  66. TextConverter(const TextConverter&);
  67. TextConverter& operator = (const TextConverter&);
  68. const TextEncoding& _inEncoding;
  69. const TextEncoding& _outEncoding;
  70. int _defaultChar;
  71. };
  72. } // namespace Poco
  73. #endif // Foundation_TextConverter_INCLUDED