Skip to content

Commit b32b472

Browse files
committed
rename filename, class to use TextEncoding, address comments
1 parent a39b13e commit b32b472

File tree

7 files changed

+74
-69
lines changed

7 files changed

+74
-69
lines changed

llvm/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,9 @@ else()
592592
option(LLVM_ENABLE_THREADS "Use threads if available." ON)
593593
endif()
594594

595-
set(LLVM_ENABLE_ICU "OFF" CACHE STRING "Use ICU for character conversion support if available. Can be ON, OFF, or FORCE_ON")
595+
set(LLVM_ENABLE_ICU "OFF" CACHE STRING "Use ICU for text encoding conversion support if available. Can be ON, OFF, or FORCE_ON")
596596

597-
set(LLVM_ENABLE_ICONV "OFF" CACHE STRING "Use iconv for character conversion support if available. Can be ON, OFF, or FORCE_ON")
597+
set(LLVM_ENABLE_ICONV "OFF" CACHE STRING "Use iconv for text encoding conversion support if available. Can be ON, OFF, or FORCE_ON")
598598

599599
set(LLVM_ENABLE_ZLIB "ON" CACHE STRING "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON")
600600

llvm/cmake/config-ix.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ if(LLVM_ENABLE_ICU AND NOT(LLVM_ENABLE_ICONV STREQUAL FORCE_ON))
314314
set(CMAKE_FIND_LIBRARY_SUFFIXES ${LIBRARY_SUFFIXES})
315315
endif()
316316

317-
# Check for builtin iconv to avoid licensing issues.
317+
# Check only for builtin iconv to avoid licensing issues.
318318
if(LLVM_ENABLE_ICONV AND NOT HAVE_ICU)
319319
if (LLVM_ENABLE_ICONV STREQUAL FORCE_ON)
320320
find_package(Iconv REQUIRED)

llvm/include/llvm/Support/EncodingConverter.h renamed to llvm/include/llvm/Support/TextEncoding.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- EncodingConverter.h - Encoding conversion class -----------*- C++ -*-=//
1+
//===-- TextEncodingConverter.h - Encoding conversion class -------*- C++ -*-=//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -28,7 +28,7 @@ namespace llvm {
2828
template <typename T> class SmallVectorImpl;
2929

3030
namespace details {
31-
class EncodingConverterImplBase {
31+
class TextEncodingConverterImplBase {
3232

3333
private:
3434
/// Converts a string.
@@ -57,7 +57,7 @@ class EncodingConverterImplBase {
5757
virtual void reset() = 0;
5858

5959
public:
60-
virtual ~EncodingConverterImplBase() = default;
60+
virtual ~TextEncodingConverterImplBase() = default;
6161

6262
/// Converts a string and resets the converter to the initial state.
6363
std::error_code convert(StringRef Source, SmallVectorImpl<char> &Result) {
@@ -78,43 +78,44 @@ enum class TextEncoding {
7878
};
7979

8080
/// Utility class to convert between different character encodings.
81-
class EncodingConverter {
82-
std::unique_ptr<details::EncodingConverterImplBase> Converter;
81+
class TextEncodingConverter {
82+
std::unique_ptr<details::TextEncodingConverterImplBase> Converter;
8383

84-
EncodingConverter(
85-
std::unique_ptr<details::EncodingConverterImplBase> Converter)
84+
TextEncodingConverter(
85+
std::unique_ptr<details::TextEncodingConverterImplBase> Converter)
8686
: Converter(std::move(Converter)) {}
8787

8888
public:
89-
/// Creates a EncodingConverter instance.
89+
/// Creates a TextEncodingConverter instance.
9090
/// Returns std::errc::invalid_argument in case the requested conversion is
9191
/// not supported.
9292
/// \param[in] From the source character encoding
9393
/// \param[in] To the target character encoding
94-
/// \return a EncodingConverter instance or an error code
95-
static ErrorOr<EncodingConverter> create(TextEncoding From, TextEncoding To);
94+
/// \return a TextEncodingConverter instance or an error code
95+
static ErrorOr<TextEncodingConverter> create(TextEncoding From,
96+
TextEncoding To);
9697

97-
/// Creates a EncodingConverter instance.
98+
/// Creates a TextEncodingConverter instance.
9899
/// Returns std::errc::invalid_argument in case the requested conversion is
99100
/// not supported.
100101
/// \param[in] From name of the source character encoding
101102
/// \param[in] To name of the target character encoding
102-
/// \return a EncodingConverter instance or an error code
103-
static ErrorOr<EncodingConverter> create(StringRef From, StringRef To);
103+
/// \return a TextEncodingConverter instance or an error code
104+
static ErrorOr<TextEncodingConverter> create(StringRef From, StringRef To);
104105

105-
EncodingConverter(const EncodingConverter &) = delete;
106-
EncodingConverter &operator=(const EncodingConverter &) = delete;
106+
TextEncodingConverter(const TextEncodingConverter &) = delete;
107+
TextEncodingConverter &operator=(const TextEncodingConverter &) = delete;
107108

108-
EncodingConverter(EncodingConverter &&Other)
109+
TextEncodingConverter(TextEncodingConverter &&Other)
109110
: Converter(std::move(Other.Converter)) {}
110111

111-
EncodingConverter &operator=(EncodingConverter &&Other) {
112+
TextEncodingConverter &operator=(TextEncodingConverter &&Other) {
112113
if (this != &Other)
113114
Converter = std::move(Other.Converter);
114115
return *this;
115116
}
116117

117-
~EncodingConverter() = default;
118+
~TextEncodingConverter() = default;
118119

119120
/// Converts a string.
120121
/// \param[in] Source source string

llvm/lib/Support/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ add_llvm_component_library(LLVMSupport
186186
ELFAttributes.cpp
187187
ELFAttrParserCompact.cpp
188188
ELFAttrParserExtended.cpp
189-
EncodingConverter.cpp
190189
Error.cpp
191190
ErrorHandling.cpp
192191
ExponentialBackoff.cpp
@@ -258,6 +257,7 @@ add_llvm_component_library(LLVMSupport
258257
SuffixTree.cpp
259258
SystemUtils.cpp
260259
TarWriter.cpp
260+
TextEncoding.cpp
261261
ThreadPool.cpp
262262
TimeProfiler.cpp
263263
Timer.cpp

llvm/lib/Support/EncodingConverter.cpp renamed to llvm/lib/Support/TextEncoding.cpp

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- EncodingConverter.cpp - Encoding conversion class ---------*- C++ -*-=//
1+
//===-- TextEncoding.cpp - Encoding conversion class --------------*- C++ -*-=//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -12,7 +12,7 @@
1212
///
1313
//===----------------------------------------------------------------------===//
1414

15-
#include "llvm/Support/EncodingConverter.h"
15+
#include "llvm/Support/TextEncoding.h"
1616
#include "llvm/ADT/SmallString.h"
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/ADT/StringExtras.h"
@@ -82,11 +82,12 @@ enum ConversionType {
8282
// aforementioned encodings. The use of tables for conversion is only
8383
// possible because EBCDIC 1047 is a single-byte, stateless encoding; other
8484
// encodings are not supported.
85-
class EncodingConverterTable : public details::EncodingConverterImplBase {
85+
class TextEncodingConverterTable
86+
: public details::TextEncodingConverterImplBase {
8687
const ConversionType ConvType;
8788

8889
public:
89-
EncodingConverterTable(ConversionType ConvType) : ConvType(ConvType) {}
90+
TextEncodingConverterTable(ConversionType ConvType) : ConvType(ConvType) {}
9091

9192
std::error_code convertString(StringRef Source,
9293
SmallVectorImpl<char> &Result) override;
@@ -95,8 +96,8 @@ class EncodingConverterTable : public details::EncodingConverterImplBase {
9596
};
9697

9798
std::error_code
98-
EncodingConverterTable::convertString(StringRef Source,
99-
SmallVectorImpl<char> &Result) {
99+
TextEncodingConverterTable::convertString(StringRef Source,
100+
SmallVectorImpl<char> &Result) {
100101
switch (ConvType) {
101102
case IBM1047ToUTF8:
102103
ConverterEBCDIC::convertToUTF8(Source, Result);
@@ -117,13 +118,13 @@ struct UConverterDeleter {
117118
};
118119
using UConverterUniquePtr = std::unique_ptr<UConverter, UConverterDeleter>;
119120

120-
class EncodingConverterICU : public details::EncodingConverterImplBase {
121+
class TextEncodingConverterICU : public details::TextEncodingConverterImplBase {
121122
UConverterUniquePtr FromConvDesc;
122123
UConverterUniquePtr ToConvDesc;
123124

124125
public:
125-
EncodingConverterICU(UConverterUniquePtr FromConverter,
126-
UConverterUniquePtr ToConverter)
126+
TextEncodingConverterICU(UConverterUniquePtr FromConverter,
127+
UConverterUniquePtr ToConverter)
127128
: FromConvDesc(std::move(FromConverter)),
128129
ToConvDesc(std::move(ToConverter)) {}
129130

@@ -138,8 +139,8 @@ class EncodingConverterICU : public details::EncodingConverterImplBase {
138139
// insufficient buffer size. In the future, it would better to save the partial
139140
// result and redo the conversion for the remaining string.
140141
std::error_code
141-
EncodingConverterICU::convertString(StringRef Source,
142-
SmallVectorImpl<char> &Result) {
142+
TextEncodingConverterICU::convertString(StringRef Source,
143+
SmallVectorImpl<char> &Result) {
143144
// Setup the input in case it has no backing data.
144145
size_t InputLength = Source.size();
145146
const char *In = InputLength ? const_cast<char *>(Source.data()) : "";
@@ -183,13 +184,14 @@ EncodingConverterICU::convertString(StringRef Source,
183184
return std::error_code();
184185
}
185186

186-
void EncodingConverterICU::reset() {
187+
void TextEncodingConverterICU::reset() {
187188
ucnv_reset(&*FromConvDesc);
188189
ucnv_reset(&*ToConvDesc);
189190
}
190191

191192
#elif HAVE_ICONV
192-
class EncodingConverterIconv : public details::EncodingConverterImplBase {
193+
class TextEncodingConverterIconv
194+
: public details::TextEncodingConverterImplBase {
193195
class UniqueIconvT {
194196
iconv_t ConvDesc;
195197

@@ -216,7 +218,7 @@ class EncodingConverterIconv : public details::EncodingConverterImplBase {
216218
UniqueIconvT ConvDesc;
217219

218220
public:
219-
EncodingConverterIconv(UniqueIconvT ConvDesc)
221+
TextEncodingConverterIconv(UniqueIconvT ConvDesc)
220222
: ConvDesc(std::move(ConvDesc)) {}
221223

222224
std::error_code convertString(StringRef Source,
@@ -230,8 +232,8 @@ class EncodingConverterIconv : public details::EncodingConverterImplBase {
230232
// insufficient buffer size. In the future, it would better to save the partial
231233
// result and redo the conversion for the remaining string.
232234
std::error_code
233-
EncodingConverterIconv::convertString(StringRef Source,
234-
SmallVectorImpl<char> &Result) {
235+
TextEncodingConverterIconv::convertString(StringRef Source,
236+
SmallVectorImpl<char> &Result) {
235237
// Setup the output. We directly write into the SmallVector.
236238
size_t Capacity = Result.capacity();
237239
char *Output = static_cast<char *>(Result.data());
@@ -289,15 +291,15 @@ EncodingConverterIconv::convertString(StringRef Source,
289291
return std::error_code();
290292
}
291293

292-
void EncodingConverterIconv::reset() {
294+
void TextEncodingConverterIconv::reset() {
293295
iconv(ConvDesc, nullptr, nullptr, nullptr, nullptr);
294296
}
295297

296298
#endif // HAVE_ICONV
297299
} // namespace
298300

299-
ErrorOr<EncodingConverter> EncodingConverter::create(TextEncoding CPFrom,
300-
TextEncoding CPTo) {
301+
ErrorOr<TextEncodingConverter>
302+
TextEncodingConverter::create(TextEncoding CPFrom, TextEncoding CPTo) {
301303

302304
// Text encodings should be distinct.
303305
if (CPFrom == CPTo)
@@ -311,16 +313,17 @@ ErrorOr<EncodingConverter> EncodingConverter::create(TextEncoding CPFrom,
311313
else
312314
return std::error_code(errno, std::generic_category());
313315

314-
return EncodingConverter(
315-
std::make_unique<EncodingConverterTable>(Conversion));
316+
return TextEncodingConverter(
317+
std::make_unique<TextEncodingConverterTable>(Conversion));
316318
}
317319

318-
ErrorOr<EncodingConverter> EncodingConverter::create(StringRef From,
319-
StringRef To) {
320+
ErrorOr<TextEncodingConverter> TextEncodingConverter::create(StringRef From,
321+
StringRef To) {
320322
std::optional<TextEncoding> FromEncoding = getKnownEncoding(From);
321323
std::optional<TextEncoding> ToEncoding = getKnownEncoding(To);
322324
if (FromEncoding && ToEncoding) {
323-
ErrorOr<EncodingConverter> Converter = create(*FromEncoding, *ToEncoding);
325+
ErrorOr<TextEncodingConverter> Converter =
326+
create(*FromEncoding, *ToEncoding);
324327
if (Converter)
325328
return Converter;
326329
}
@@ -334,15 +337,16 @@ ErrorOr<EncodingConverter> EncodingConverter::create(StringRef From,
334337
if (U_FAILURE(EC)) {
335338
return std::error_code(errno, std::generic_category());
336339
}
337-
std::unique_ptr<details::EncodingConverterImplBase> Converter =
338-
std::make_unique<EncodingConverterICU>(std::move(FromConvDesc),
339-
std::move(ToConvDesc));
340-
return EncodingConverter(std::move(Converter));
340+
std::unique_ptr<details::TextEncodingConverterImplBase> Converter =
341+
std::make_unique<TextEncodingConverterICU>(std::move(FromConvDesc),
342+
std::move(ToConvDesc));
343+
return TextEncodingConverter(std::move(Converter));
341344
#elif HAVE_ICONV
342345
iconv_t ConvDesc = iconv_open(To.str().c_str(), From.str().c_str());
343346
if (ConvDesc == (iconv_t)-1)
344347
return std::error_code(errno, std::generic_category());
345-
return EncodingConverter(std::make_unique<EncodingConverterIconv>(ConvDesc));
348+
return TextEncodingConverter(
349+
std::make_unique<TextEncodingConverterIconv>(ConvDesc));
346350
#else
347351
return std::make_error_code(std::errc::invalid_argument);
348352
#endif

llvm/unittests/Support/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ add_llvm_unittest(SupportTests
3939
ErrnoTest.cpp
4040
ErrorOrTest.cpp
4141
ErrorTest.cpp
42-
EncodingConverterTest.cpp
4342
ExponentialBackoffTest.cpp
4443
ExtensibleRTTITest.cpp
4544
FileCollectorTest.cpp
@@ -89,6 +88,7 @@ add_llvm_unittest(SupportTests
8988
SuffixTreeTest.cpp
9089
SwapByteOrderTest.cpp
9190
TarWriterTest.cpp
91+
TextEncodingTest.cpp
9292
ThreadPool.cpp
9393
ThreadSafeAllocatorTest.cpp
9494
Threading.cpp

0 commit comments

Comments
 (0)