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