@@ -47,7 +47,7 @@ static void normalizeCharSetName(StringRef CSName,
47
47
}
48
48
49
49
// Maps the charset name to enum constant if possible.
50
- static std::optional<TextEncoding> getKnownCharSet (StringRef CSName) {
50
+ static std::optional<TextEncoding> getKnownEncoding (StringRef CSName) {
51
51
SmallString<16 > Normalized;
52
52
normalizeCharSetName (CSName, Normalized);
53
53
if (Normalized.equals (" utf8" ))
@@ -83,11 +83,11 @@ enum ConversionType {
83
83
// aforementioned character sets. The use of tables for conversion is only
84
84
// possible because EBCDIC 1047 is a single-byte, stateless encoding; other
85
85
// character sets are not supported.
86
- class CharSetConverterTable : public details ::CharSetConverterImplBase {
86
+ class EncodingConverterTable : public details ::EncodingConverterImplBase {
87
87
const ConversionType ConvType;
88
88
89
89
public:
90
- CharSetConverterTable (ConversionType ConvType) : ConvType(ConvType) {}
90
+ EncodingConverterTable (ConversionType ConvType) : ConvType(ConvType) {}
91
91
92
92
std::error_code convertString (StringRef Source,
93
93
SmallVectorImpl<char > &Result) override ;
@@ -96,8 +96,8 @@ class CharSetConverterTable : public details::CharSetConverterImplBase {
96
96
};
97
97
98
98
std::error_code
99
- CharSetConverterTable ::convertString (StringRef Source,
100
- SmallVectorImpl<char > &Result) {
99
+ EncodingConverterTable ::convertString (StringRef Source,
100
+ SmallVectorImpl<char > &Result) {
101
101
switch (ConvType) {
102
102
case IBM1047ToUTF8:
103
103
ConverterEBCDIC::convertToUTF8 (Source, Result);
@@ -118,13 +118,13 @@ struct UConverterDeleter {
118
118
};
119
119
using UConverterUniquePtr = std::unique_ptr<UConverter, UConverterDeleter>;
120
120
121
- class CharSetConverterICU : public details ::CharSetConverterImplBase {
121
+ class EncodingConverterICU : public details ::EncodingConverterImplBase {
122
122
UConverterUniquePtr FromConvDesc;
123
123
UConverterUniquePtr ToConvDesc;
124
124
125
125
public:
126
- CharSetConverterICU (UConverterUniquePtr FromConverter,
127
- UConverterUniquePtr ToConverter)
126
+ EncodingConverterICU (UConverterUniquePtr FromConverter,
127
+ UConverterUniquePtr ToConverter)
128
128
: FromConvDesc(std::move(FromConverter)),
129
129
ToConvDesc (std::move(ToConverter)) {}
130
130
@@ -139,8 +139,8 @@ class CharSetConverterICU : public details::CharSetConverterImplBase {
139
139
// insufficient buffer size. In the future, it would better to save the partial
140
140
// result and redo the conversion for the remaining string.
141
141
std::error_code
142
- CharSetConverterICU ::convertString (StringRef Source,
143
- SmallVectorImpl<char > &Result) {
142
+ EncodingConverterICU ::convertString (StringRef Source,
143
+ SmallVectorImpl<char > &Result) {
144
144
// Setup the input in case it has no backing data.
145
145
size_t InputLength = Source.size ();
146
146
const char *In = InputLength ? const_cast <char *>(Source.data ()) : " " ;
@@ -185,13 +185,13 @@ CharSetConverterICU::convertString(StringRef Source,
185
185
return std::error_code ();
186
186
}
187
187
188
- void CharSetConverterICU ::reset () {
188
+ void EncodingConverterICU ::reset () {
189
189
ucnv_reset (&*FromConvDesc);
190
190
ucnv_reset (&*ToConvDesc);
191
191
}
192
192
193
193
#elif HAVE_ICONV
194
- class CharSetConverterIconv : public details ::CharSetConverterImplBase {
194
+ class EncodingConverterIconv : public details ::EncodingConverterImplBase {
195
195
class UniqueIconvT {
196
196
iconv_t ConvDesc;
197
197
@@ -218,7 +218,7 @@ class CharSetConverterIconv : public details::CharSetConverterImplBase {
218
218
UniqueIconvT ConvDesc;
219
219
220
220
public:
221
- CharSetConverterIconv (UniqueIconvT ConvDesc)
221
+ EncodingConverterIconv (UniqueIconvT ConvDesc)
222
222
: ConvDesc(std::move(ConvDesc)) {}
223
223
224
224
std::error_code convertString (StringRef Source,
@@ -232,8 +232,8 @@ class CharSetConverterIconv : public details::CharSetConverterImplBase {
232
232
// insufficient buffer size. In the future, it would better to save the partial
233
233
// result and redo the conversion for the remaining string.
234
234
std::error_code
235
- CharSetConverterIconv ::convertString (StringRef Source,
236
- SmallVectorImpl<char > &Result) {
235
+ EncodingConverterIconv ::convertString (StringRef Source,
236
+ SmallVectorImpl<char > &Result) {
237
237
// Setup the output. We directly write into the SmallVector.
238
238
size_t Capacity = Result.capacity ();
239
239
char *Output = static_cast <char *>(Result.data ());
@@ -291,38 +291,38 @@ CharSetConverterIconv::convertString(StringRef Source,
291
291
return std::error_code ();
292
292
}
293
293
294
- void CharSetConverterIconv ::reset () {
294
+ void EncodingConverterIconv ::reset () {
295
295
iconv (ConvDesc, nullptr , nullptr , nullptr , nullptr );
296
296
}
297
297
298
298
#endif // HAVE_ICONV
299
299
} // namespace
300
300
301
- ErrorOr<CharSetConverter> CharSetConverter ::create (TextEncoding CPFrom,
302
- TextEncoding CPTo) {
301
+ ErrorOr<EncodingConverter> EncodingConverter ::create (TextEncoding CPFrom,
302
+ TextEncoding CPTo) {
303
303
304
304
// text encodings should be distinct
305
- if (CPFrom == CPTo)
305
+ if (CPFrom == CPTo)
306
306
return std::make_error_code (std::errc::invalid_argument);
307
307
308
308
ConversionType Conversion;
309
309
if (CPFrom == TextEncoding::UTF8 && CPTo == TextEncoding::IBM1047)
310
310
Conversion = UTF8ToIBM1047;
311
- else if (CPFrom == TextEncoding::IBM1047 &&
312
- CPTo == TextEncoding::UTF8)
311
+ else if (CPFrom == TextEncoding::IBM1047 && CPTo == TextEncoding::UTF8)
313
312
Conversion = IBM1047ToUTF8;
314
313
else
315
314
return std::error_code (errno, std::generic_category ());
316
315
317
- return CharSetConverter (std::make_unique<CharSetConverterTable>(Conversion));
316
+ return EncodingConverter (
317
+ std::make_unique<EncodingConverterTable>(Conversion));
318
318
}
319
319
320
- ErrorOr<CharSetConverter> CharSetConverter ::create (StringRef CSFrom,
321
- StringRef CSTo) {
322
- std::optional<TextEncoding> From = getKnownCharSet (CSFrom);
323
- std::optional<TextEncoding> To = getKnownCharSet (CSTo);
320
+ ErrorOr<EncodingConverter> EncodingConverter ::create (StringRef CSFrom,
321
+ StringRef CSTo) {
322
+ std::optional<TextEncoding> From = getKnownEncoding (CSFrom);
323
+ std::optional<TextEncoding> To = getKnownEncoding (CSTo);
324
324
if (From && To) {
325
- ErrorOr<CharSetConverter > Converter = create (*From, *To);
325
+ ErrorOr<EncodingConverter > Converter = create (*From, *To);
326
326
if (Converter)
327
327
return Converter;
328
328
}
@@ -336,15 +336,15 @@ ErrorOr<CharSetConverter> CharSetConverter::create(StringRef CSFrom,
336
336
if (U_FAILURE (EC)) {
337
337
return std::error_code (errno, std::generic_category ());
338
338
}
339
- std::unique_ptr<details::CharSetConverterImplBase > Converter =
340
- std::make_unique<CharSetConverterICU >(std::move (FromConvDesc),
341
- std::move (ToConvDesc));
342
- return CharSetConverter (std::move (Converter));
339
+ std::unique_ptr<details::EncodingConverterImplBase > Converter =
340
+ std::make_unique<EncodingConverterICU >(std::move (FromConvDesc),
341
+ std::move (ToConvDesc));
342
+ return EncodingConverter (std::move (Converter));
343
343
#elif HAVE_ICONV
344
344
iconv_t ConvDesc = iconv_open (CSTo.str ().c_str (), CSFrom.str ().c_str ());
345
345
if (ConvDesc == (iconv_t )-1 )
346
346
return std::error_code (errno, std::generic_category ());
347
- return CharSetConverter (std::make_unique<CharSetConverterIconv >(ConvDesc));
347
+ return EncodingConverter (std::make_unique<EncodingConverterIconv >(ConvDesc));
348
348
#else
349
349
return std::make_error_code (std::errc::invalid_argument);
350
350
#endif
0 commit comments