Skip to content

Commit 290e2bc

Browse files
committed
remove AutoFlush, remove stray comment
1 parent b99dca5 commit 290e2bc

File tree

3 files changed

+40
-47
lines changed

3 files changed

+40
-47
lines changed

llvm/include/llvm/Support/CharSet.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class CharSetConverterImplBase {
3636
/// Converts a string.
3737
/// \param[in] Source source string
3838
/// \param[out] Result container for converted string
39-
/// \param[in] ShouldAutoFlush Append shift-back sequence after conversion
40-
/// for stateful encodings if true.
4139
/// \return error code in case something went wrong
4240
///
4341
/// The following error codes can occur, among others:
@@ -55,8 +53,7 @@ class CharSetConverterImplBase {
5553
/// will be set to the initial state.
5654

5755
virtual std::error_code convert(StringRef Source,
58-
SmallVectorImpl<char> &Result,
59-
bool ShouldAutoFlush) const = 0;
56+
SmallVectorImpl<char> &Result) const = 0;
6057
};
6158
} // namespace details
6259

@@ -113,18 +110,15 @@ class CharSetConverter {
113110
/// Converts a string.
114111
/// \param[in] Source source string
115112
/// \param[out] Result container for converted string
116-
/// \param[in] ShouldAutoFlush Append shift-back sequence after conversion
117-
/// for stateful encodings.
118113
/// \return error code in case something went wrong
119-
std::error_code convert(StringRef Source, SmallVectorImpl<char> &Result,
120-
bool ShouldAutoFlush = true) const {
121-
return Converter->convert(Source, Result, ShouldAutoFlush);
114+
std::error_code convert(StringRef Source,
115+
SmallVectorImpl<char> &Result) const {
116+
return Converter->convert(Source, Result);
122117
}
123118

124-
ErrorOr<std::string> convert(StringRef Source,
125-
bool ShouldAutoFlush = true) const {
119+
ErrorOr<std::string> convert(StringRef Source) const {
126120
SmallString<100> Result;
127-
auto EC = Converter->convert(Source, Result, ShouldAutoFlush);
121+
auto EC = Converter->convert(Source, Result);
128122
if (!EC)
129123
return std::string(Result);
130124
return EC;

llvm/lib/Support/CharSet.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
6061
static 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

7577
namespace {
7678
enum ConversionType {
@@ -89,13 +91,13 @@ class CharSetConverterTable : public details::CharSetConverterImplBase {
8991
public:
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 {
182184
public:
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);

llvm/unittests/Support/CharSetTest.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ static const char CyrillicUTF[] = "\xd0\xaf";
4646
// IBM-939: Byte 0x0E shifts from single byte to double byte, and 0x0F shifts
4747
// back.
4848
static const char EarthUTF[] = "\x45\x61\x72\x74\x68\xe5\x9c\xb0\xe7\x90\x83";
49-
// Identical to above, except the final character (球) has its last byte taken
50-
// away from it.
5149
static const char EarthISO2022[] =
5250
"\x45\x61\x72\x74\x68\x1B\x24\x42\x43\x4F\x35\x65\x1B\x28\x42";
5351
static const char EarthIBM939[] =
@@ -60,28 +58,28 @@ TEST(CharSet, FromUTF8) {
6058

6159
CharSetConverter Conv = CharSetConverter::create(text_encoding::id::UTF8,
6260
text_encoding::id::IBM1047);
63-
std::error_code EC = Conv.convert(Src, Dst, true);
61+
std::error_code EC = Conv.convert(Src, Dst);
6462
EXPECT_TRUE(!EC);
6563
EXPECT_STREQ(HelloE, static_cast<std::string>(Dst).c_str());
6664
Dst.clear();
6765

6866
// ABC string.
6967
Src = ABCStrA;
70-
EC = Conv.convert(Src, Dst, true);
68+
EC = Conv.convert(Src, Dst);
7169
EXPECT_TRUE(!EC);
7270
EXPECT_STREQ(ABCStrE, static_cast<std::string>(Dst).c_str());
7371
Dst.clear();
7472

7573
// Accent string.
7674
Src = AccentUTF;
77-
EC = Conv.convert(Src, Dst, true);
75+
EC = Conv.convert(Src, Dst);
7876
EXPECT_TRUE(!EC);
7977
EXPECT_STREQ(AccentE, static_cast<std::string>(Dst).c_str());
8078
Dst.clear();
8179

8280
// Cyrillic string. Results in error because not representable in 1047.
8381
Src = CyrillicUTF;
84-
EC = Conv.convert(Src, Dst, true);
82+
EC = Conv.convert(Src, Dst);
8583
EXPECT_EQ(EC, std::errc::illegal_byte_sequence);
8684
}
8785

@@ -92,21 +90,21 @@ TEST(CharSet, ToUTF8) {
9290

9391
CharSetConverter Conv = CharSetConverter::create(text_encoding::id::IBM1047,
9492
text_encoding::id::UTF8);
95-
std::error_code EC = Conv.convert(Src, Dst, true);
93+
std::error_code EC = Conv.convert(Src, Dst);
9694
EXPECT_TRUE(!EC);
9795
EXPECT_STREQ(HelloA, static_cast<std::string>(Dst).c_str());
9896
Dst.clear();
9997

10098
// ABC string.
10199
Src = ABCStrE;
102-
EC = Conv.convert(Src, Dst, true);
100+
EC = Conv.convert(Src, Dst);
103101
EXPECT_TRUE(!EC);
104102
EXPECT_STREQ(ABCStrA, static_cast<std::string>(Dst).c_str());
105103
Dst.clear();
106104

107105
// Accent string.
108106
Src = AccentE;
109-
EC = Conv.convert(Src, Dst, true);
107+
EC = Conv.convert(Src, Dst);
110108
EXPECT_TRUE(!EC);
111109
EXPECT_STREQ(AccentUTF, static_cast<std::string>(Dst).c_str());
112110
}
@@ -144,11 +142,11 @@ TEST(CharSet, RoundTrip) {
144142

145143
SmallString<99> Dst1Str, Dst2Str, Dst3Str;
146144

147-
std::error_code EC = ConvToUTF16->convert(StringRef(SrcStr), Dst1Str, true);
145+
std::error_code EC = ConvToUTF16->convert(StringRef(SrcStr), Dst1Str);
148146
EXPECT_TRUE(!EC);
149-
EC = ConvToUTF32->convert(Dst1Str, Dst2Str, true);
147+
EC = ConvToUTF32->convert(Dst1Str, Dst2Str);
150148
EXPECT_TRUE(!EC);
151-
EC = ConvToEBCDIC->convert(Dst2Str, Dst3Str, true);
149+
EC = ConvToEBCDIC->convert(Dst2Str, Dst3Str);
152150
EXPECT_TRUE(!EC);
153151
EXPECT_STREQ(SrcStr, static_cast<std::string>(Dst3Str).c_str());
154152
}
@@ -168,7 +166,7 @@ TEST(CharSet, ShiftState2022) {
168166
}
169167

170168
// Check that the string is properly converted.
171-
std::error_code EC = ConvTo2022->convert(Src, Dst, true);
169+
std::error_code EC = ConvTo2022->convert(Src, Dst);
172170
EXPECT_TRUE(!EC);
173171
EXPECT_STREQ(EarthISO2022, static_cast<std::string>(Dst).c_str());
174172
}
@@ -188,7 +186,7 @@ TEST(CharSet, ShiftStateIBM939) {
188186
}
189187

190188
// Check that the string is properly converted.
191-
std::error_code EC = ConvToIBM939->convert(Src, Dst, true);
189+
std::error_code EC = ConvToIBM939->convert(Src, Dst);
192190
EXPECT_TRUE(!EC);
193191
EXPECT_STREQ(EarthIBM939, static_cast<std::string>(Dst).c_str());
194192
}

0 commit comments

Comments
 (0)