@@ -57,6 +57,7 @@ static std::optional<text_encoding::id> getKnownCharSet(StringRef CSName) {
5757 return std::nullopt ;
5858}
5959
60+ #if defined(HAVE_ICONV) || defined(HAVE_ICU)
6061static void HandleOverflow (size_t &Capacity, char *&Output,
6162 size_t &OutputLength,
6263 SmallVectorImpl<char > &Result) {
@@ -71,6 +72,7 @@ static void HandleOverflow(size_t &Capacity, char *&Output,
7172 Output = static_cast <char *>(Result.data ());
7273 OutputLength = Capacity;
7374}
75+ #endif
7476
7577namespace {
7678enum ConversionType {
@@ -89,13 +91,13 @@ class CharSetConverterTable : public details::CharSetConverterImplBase {
8991public:
9092 CharSetConverterTable (ConversionType ConvType) : ConvType(ConvType) {}
9193
92- std::error_code convert (StringRef Source, SmallVectorImpl< char > &Result,
93- bool ShouldAutoFlush ) const override ;
94+ std::error_code convert (StringRef Source,
95+ SmallVectorImpl< char > &Result ) const override ;
9496};
9597
96- std::error_code CharSetConverterTable::convert (StringRef Source,
97- SmallVectorImpl< char > &Result ,
98- bool ShouldAutoFlush ) const {
98+ std::error_code
99+ CharSetConverterTable::convert (StringRef Source ,
100+ SmallVectorImpl< char > &Result ) const {
99101 if (ConvType == IBM1047ToUTF) {
100102 ConverterEBCDIC::convertToUTF8 (Source, Result);
101103 return std::error_code ();
@@ -131,13 +133,13 @@ class CharSetConverterICU : public details::CharSetConverterImplBase {
131133 ToConvDesc = nullptr ;
132134 }
133135
134- std::error_code convert (StringRef Source, SmallVectorImpl< char > &Result,
135- bool ShouldAutoFlush ) const override ;
136+ std::error_code convert (StringRef Source,
137+ SmallVectorImpl< char > &Result ) const override ;
136138};
137139
138- std::error_code CharSetConverterICU::convert (StringRef Source,
139- SmallVectorImpl< char > &Result ,
140- bool ShouldAutoFlush ) const {
140+ std::error_code
141+ CharSetConverterICU::convert (StringRef Source ,
142+ SmallVectorImpl< char > &Result ) const {
141143 // Setup the output. We directly write into the SmallVector.
142144 size_t Capacity = Result.capacity ();
143145 size_t OutputLength = Capacity;
@@ -158,7 +160,7 @@ std::error_code CharSetConverterICU::convert(StringRef Source,
158160 &Input, In + InputLength, /* pivotStart=*/ NULL ,
159161 /* pivotSource=*/ NULL , /* pivotTarget=*/ NULL ,
160162 /* pivotLimit=*/ NULL , /* reset=*/ true ,
161- /* flush=*/ ShouldAutoFlush , &EC);
163+ /* flush=*/ true , &EC);
162164 if (U_FAILURE (EC)) {
163165 if (EC == U_BUFFER_OVERFLOW_ERROR &&
164166 Capacity < std::numeric_limits<size_t >::max ()) {
@@ -182,13 +184,13 @@ class CharSetConverterIconv : public details::CharSetConverterImplBase {
182184public:
183185 CharSetConverterIconv (iconv_t ConvDesc) : ConvDesc(ConvDesc) {}
184186
185- std::error_code convert (StringRef Source, SmallVectorImpl< char > &Result,
186- bool ShouldAutoFlush ) const override ;
187+ std::error_code convert (StringRef Source,
188+ SmallVectorImpl< char > &Result ) const override ;
187189};
188190
189- std::error_code CharSetConverterIconv::convert (StringRef Source,
190- SmallVectorImpl< char > &Result ,
191- bool ShouldAutoFlush ) const {
191+ std::error_code
192+ CharSetConverterIconv::convert (StringRef Source ,
193+ SmallVectorImpl< char > &Result ) const {
192194 // Setup the input. Use nullptr to reset iconv state if input length is zero.
193195 size_t InputLength = Source.size ();
194196 char *Input = InputLength ? const_cast <char *>(Source.data ()) : nullptr ;
@@ -226,11 +228,10 @@ std::error_code CharSetConverterIconv::convert(StringRef Source,
226228 while ((Ret = iconv (ConvDesc, &Input, &InputLength, &Output, &OutputLength)))
227229 if (auto EC = HandleError (Ret))
228230 return EC;
229- if (ShouldAutoFlush) {
230- while ((Ret = iconv (ConvDesc, nullptr , nullptr , &Output, &OutputLength)))
231- if (auto EC = HandleError (Ret))
232- return EC;
233- }
231+ // Flush the converter
232+ while ((Ret = iconv (ConvDesc, nullptr , nullptr , &Output, &OutputLength)))
233+ if (auto EC = HandleError (Ret))
234+ return EC;
234235
235236 // Re-adjust size to actual size.
236237 Result.resize (Capacity - OutputLength);
0 commit comments