@@ -47,7 +47,7 @@ static void normalizeCharSetName(StringRef CSName,
4747}
4848
4949// Maps the charset name to enum constant if possible.
50- std::optional<text_encoding::id> getKnownCharSet (StringRef CSName) {
50+ static std::optional<text_encoding::id> getKnownCharSet (StringRef CSName) {
5151 SmallString<16 > Normalized;
5252 normalizeCharSetName (CSName, Normalized);
5353 if (Normalized.equals (" utf8" ))
@@ -57,8 +57,9 @@ std::optional<text_encoding::id> getKnownCharSet(StringRef CSName) {
5757 return std::nullopt ;
5858}
5959
60- void HandleOverflow (size_t &Capacity, char *&Output, size_t &OutputLength,
61- SmallVectorImpl<char > &Result) {
60+ static void HandleOverflow (size_t &Capacity, char *&Output,
61+ size_t &OutputLength,
62+ SmallVectorImpl<char > &Result) {
6263 // No space left in output buffer. Double the size of the underlying
6364 // memory in the SmallVectorImpl, adjust pointer and length and continue
6465 // the conversion.
@@ -150,9 +151,10 @@ std::error_code CharSetConverterICU::convert(StringRef Source,
150151 SmallVectorImpl<char > &Result,
151152 bool ShouldAutoFlush) const {
152153 // Setup the output. We directly write into the SmallVector.
153- Result.resize_for_overwrite (Source. size () );
154- size_t OutputLength, Capacity = Result. capacity () ;
154+ size_t Capacity = Result.capacity ( );
155+ size_t OutputLength = Capacity ;
155156 char *Output, *Out;
157+ Result.resize_for_overwrite (Capacity);
156158
157159 UErrorCode EC = U_ZERO_ERROR;
158160
@@ -163,9 +165,7 @@ std::error_code CharSetConverterICU::convert(StringRef Source,
163165 InputLength ? const_cast <char *>(Source.data ()) : nullptr ;
164166 const char *In = Input;
165167 Output = InputLength ? static_cast <char *>(Result.data ()) : nullptr ;
166- OutputLength = Capacity;
167168 Out = Output;
168- Result.resize_for_overwrite (Capacity);
169169 ucnv_convertEx (ToConvDesc, FromConvDesc, &Output, Out + OutputLength,
170170 &Input, In + InputLength, /* pivotStart=*/ NULL ,
171171 /* pivotSource=*/ NULL , /* pivotTarget=*/ NULL ,
@@ -177,7 +177,7 @@ std::error_code CharSetConverterICU::convert(StringRef Source,
177177 HandleOverflow (Capacity, Output, OutputLength, Result);
178178 else
179179 // Some other error occured.
180- return std::error_code (errno , std::generic_category ());
180+ return std::error_code (EILSEQ , std::generic_category ());
181181 } else if (U_SUCCESS (EC))
182182 break ;
183183 } while (U_FAILURE (EC));
0 commit comments