@@ -91,13 +91,15 @@ class CharSetConverterTable : public details::CharSetConverterImplBase {
9191public:
9292 CharSetConverterTable (ConversionType ConvType) : ConvType(ConvType) {}
9393
94- std::error_code convert (StringRef Source,
95- SmallVectorImpl<char > &Result) const override ;
94+ std::error_code convertString (StringRef Source,
95+ SmallVectorImpl<char > &Result) override ;
96+
97+ void reset () override {}
9698};
9799
98100std::error_code
99- CharSetConverterTable::convert (StringRef Source,
100- SmallVectorImpl<char > &Result) const {
101+ CharSetConverterTable::convertString (StringRef Source,
102+ SmallVectorImpl<char > &Result) {
101103 if (ConvType == IBM1047ToUTF8) {
102104 ConverterEBCDIC::convertToUTF8 (Source, Result);
103105 return std::error_code ();
@@ -127,13 +129,15 @@ class CharSetConverterICU : public details::CharSetConverterImplBase {
127129 : FromConvDesc(std::move(FromConverter)),
128130 ToConvDesc (std::move(ToConverter)) {}
129131
130- std::error_code convert (StringRef Source,
131- SmallVectorImpl<char > &Result) const override ;
132+ std::error_code convertString (StringRef Source,
133+ SmallVectorImpl<char > &Result) override ;
134+
135+ void reset () override ;
132136};
133137
134138std::error_code
135- CharSetConverterICU::convert (StringRef Source,
136- SmallVectorImpl<char > &Result) const {
139+ CharSetConverterICU::convertString (StringRef Source,
140+ SmallVectorImpl<char > &Result) {
137141 // Setup the input in case it has no backing data.
138142 size_t InputLength = Source.size ();
139143 const char *In = InputLength ? const_cast <char *>(Source.data ()) : " " ;
@@ -171,6 +175,11 @@ CharSetConverterICU::convert(StringRef Source,
171175 return std::error_code ();
172176}
173177
178+ void CharSetConverterICU::reset () {
179+ ucnv_reset (&*FromConvDesc);
180+ ucnv_reset (&*ToConvDesc);
181+ }
182+
174183#elif defined(HAVE_ICONV)
175184class CharSetConverterIconv : public details ::CharSetConverterImplBase {
176185 class UniqueIconvT {
@@ -202,13 +211,15 @@ class CharSetConverterIconv : public details::CharSetConverterImplBase {
202211 CharSetConverterIconv (UniqueIconvT ConvDesc)
203212 : ConvDesc(std::move(ConvDesc)) {}
204213
205- std::error_code convert (StringRef Source,
206- SmallVectorImpl<char > &Result) const override ;
214+ std::error_code convertString (StringRef Source,
215+ SmallVectorImpl<char > &Result) override ;
216+
217+ void reset () override ;
207218};
208219
209220std::error_code
210- CharSetConverterIconv::convert (StringRef Source,
211- SmallVectorImpl<char > &Result) const {
221+ CharSetConverterIconv::convertString (StringRef Source,
222+ SmallVectorImpl<char > &Result) {
212223 // Setup the output. We directly write into the SmallVector.
213224 size_t Capacity = Result.capacity ();
214225 char *Output = static_cast <char *>(Result.data ());
@@ -262,10 +273,14 @@ CharSetConverterIconv::convert(StringRef Source,
262273 } while (true );
263274
264275 // Re-adjust size to actual size.
265- Result.resize (Capacity - OutputLength );
276+ Result.resize (Output - Result. data () );
266277 return std::error_code ();
267278}
268279
280+ void CharSetConverterIconv::reset () {
281+ iconv (ConvDesc, nullptr , nullptr , nullptr , nullptr );
282+ }
283+
269284#endif // HAVE_ICONV
270285} // namespace
271286
@@ -281,8 +296,7 @@ CharSetConverter CharSetConverter::create(text_encoding::id CPFrom,
281296 CPTo == text_encoding::id::UTF8)
282297 Conversion = IBM1047ToUTF8;
283298 else
284- assert (false &&
285- " Only conversions between UTF-8 and IBM-1047 are supported" );
299+ llvm_unreachable (" Invalid ConversionType!" );
286300 std::unique_ptr<details::CharSetConverterImplBase> Converter =
287301 std::make_unique<CharSetConverterTable>(Conversion);
288302
0 commit comments