Skip to content

Commit 51bfc07

Browse files
committed
remove function to get shift back characters, address comments
1 parent 6e7df09 commit 51bfc07

File tree

3 files changed

+7
-115
lines changed

3 files changed

+7
-115
lines changed

llvm/include/llvm/Support/CharSet.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ class CharSetConverterImplBase {
6363
/// set the shift state to the initial state.
6464
/// Otherwise this is a no-op.
6565
virtual std::error_code flush() const = 0;
66-
67-
virtual std::error_code flush(SmallVectorImpl<char> &Result) const = 0;
6866
};
6967
} // namespace details
7068

@@ -139,10 +137,6 @@ class CharSetConverter {
139137
}
140138

141139
std::error_code flush() const { return Converter->flush(); }
142-
143-
std::error_code flush(SmallVectorImpl<char> &Result) const {
144-
return Converter->flush(Result);
145-
}
146140
};
147141

148142
} // namespace llvm

llvm/lib/Support/CharSet.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class CharSetConverterTable : public details::CharSetConverterImplBase {
9191
std::error_code convert(StringRef Source, SmallVectorImpl<char> &Result,
9292
bool ShouldAutoFlush) const override;
9393
std::error_code flush() const override;
94-
std::error_code flush(SmallVectorImpl<char> &Result) const override;
9594
};
9695

9796
std::error_code CharSetConverterTable::convert(StringRef Source,
@@ -111,11 +110,6 @@ std::error_code CharSetConverterTable::flush() const {
111110
return std::error_code();
112111
}
113112

114-
std::error_code
115-
CharSetConverterTable::flush(SmallVectorImpl<char> &Result) const {
116-
return std::error_code();
117-
}
118-
119113
#ifdef HAVE_ICU
120114
class CharSetConverterICU : public details::CharSetConverterImplBase {
121115
UConverter *FromConvDesc;
@@ -144,7 +138,6 @@ class CharSetConverterICU : public details::CharSetConverterImplBase {
144138
std::error_code convert(StringRef Source, SmallVectorImpl<char> &Result,
145139
bool ShouldAutoFlush) const override;
146140
std::error_code flush() const override;
147-
std::error_code flush(SmallVectorImpl<char> &Result) const override;
148141
};
149142

150143
std::error_code CharSetConverterICU::convert(StringRef Source,
@@ -164,7 +157,7 @@ std::error_code CharSetConverterICU::convert(StringRef Source,
164157
const char *Input =
165158
InputLength ? const_cast<char *>(Source.data()) : nullptr;
166159
const char *In = Input;
167-
Output = InputLength ? static_cast<char *>(Result.data()) : nullptr;
160+
Output = static_cast<char *>(Result.data());
168161
Out = Output;
169162
ucnv_convertEx(ToConvDesc, FromConvDesc, &Output, Out + OutputLength,
170163
&Input, In + InputLength, /*pivotStart=*/NULL,
@@ -173,26 +166,22 @@ std::error_code CharSetConverterICU::convert(StringRef Source,
173166
/*flush=*/ShouldAutoFlush, &EC);
174167
if (U_FAILURE(EC)) {
175168
if (EC == U_BUFFER_OVERFLOW_ERROR &&
176-
Capacity < std::numeric_limits<size_t>::max())
169+
Capacity < std::numeric_limits<size_t>::max()) {
177170
HandleOverflow(Capacity, Output, OutputLength, Result);
178-
else
171+
continue;
172+
} else
179173
// Some other error occured.
180174
return std::error_code(EILSEQ, std::generic_category());
181-
} else if (U_SUCCESS(EC))
182-
break;
183-
} while (U_FAILURE(EC));
175+
}
176+
break;
177+
} while (true);
184178

185179
Result.resize(Output - Out);
186180
return std::error_code();
187181
}
188182

189183
std::error_code CharSetConverterICU::flush() const { return std::error_code(); }
190184

191-
std::error_code
192-
CharSetConverterICU::flush(SmallVectorImpl<char> &Result) const {
193-
return std::error_code();
194-
}
195-
196185
#elif defined(HAVE_ICONV)
197186
class CharSetConverterIconv : public details::CharSetConverterImplBase {
198187
iconv_t ConvDesc;
@@ -203,7 +192,6 @@ class CharSetConverterIconv : public details::CharSetConverterImplBase {
203192
std::error_code convert(StringRef Source, SmallVectorImpl<char> &Result,
204193
bool ShouldAutoFlush) const override;
205194
std::error_code flush() const override;
206-
std::error_code flush(SmallVectorImpl<char> &Result) const override;
207195
};
208196

209197
std::error_code CharSetConverterIconv::convert(StringRef Source,
@@ -263,11 +251,6 @@ std::error_code CharSetConverterIconv::flush() const {
263251
return std::error_code();
264252
}
265253

266-
std::error_code
267-
CharSetConverterIconv::flush(SmallVectorImpl<char> &Result) const {
268-
return convert("", Result, /*ShouldAutoFlush=*/true);
269-
}
270-
271254
#endif // HAVE_ICONV
272255
} // namespace
273256

llvm/unittests/Support/CharSetTest.cpp

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -193,89 +193,4 @@ TEST(CharSet, ShiftStateIBM939) {
193193
EXPECT_STREQ(EarthIBM939, static_cast<std::string>(Dst).c_str());
194194
}
195195

196-
#if not defined(HAVE_ICU) && defined(HAVE_ICONV)
197-
198-
// Identical to EarthUTF, except the final character (球) has its last byte
199-
// taken away from it.
200-
static const char EarthUTFBroken[] = "\x45\x61\x72\x74\x68\xe5\x9c\xb0\xe7\x90";
201-
static const char EarthISO2022ShiftBack[] =
202-
"\x45\x61\x72\x74\x68\x1B\x24\x42\x43\x4F\x35\x65";
203-
static const char ShiftBackOnly[] = "\x1B\x28\x42";
204-
205-
// String "地球".
206-
static const char EarthKanjiOnlyUTF[] = "\xe5\x9c\xb0\xe7\x90\x83";
207-
static const char EarthKanjiOnlyISO2022[] =
208-
"\x1B\x24\x42\x43\x4F\x35\x65\x1b\x28\x42";
209-
static const char EarthKanjiOnlyIBM939[] = "\x0e\x45\xc2\x48\xdb\x0f";
210-
211-
TEST(CharSet, ShiftState2022Flush) {
212-
StringRef Src0(EarthUTFBroken);
213-
StringRef Src1(EarthKanjiOnlyUTF);
214-
SmallString<64> Dst0;
215-
SmallString<64> Dst1;
216-
ErrorOr<CharSetConverter> ConvTo2022Flush =
217-
CharSetConverter::create("UTF-8", "ISO-2022-JP");
218-
if (!ConvTo2022Flush) {
219-
ASSERT_EQ(ConvTo2022Flush.getError(),
220-
std::make_error_code(std::errc::invalid_argument));
221-
return;
222-
}
223-
224-
// This should emit an error; there is a malformed multibyte character in the
225-
// input string.
226-
std::error_code EC0 = ConvTo2022Flush->convert(Src0, Dst0, true);
227-
EXPECT_TRUE(EC0);
228-
std::error_code EC1 = ConvTo2022Flush->flush();
229-
EXPECT_TRUE(!EC1);
230-
std::error_code EC2 = ConvTo2022Flush->convert(Src1, Dst1, true);
231-
EXPECT_TRUE(!EC2);
232-
EXPECT_STREQ(EarthKanjiOnlyISO2022, static_cast<std::string>(Dst1).c_str());
233-
}
234-
235-
TEST(CharSet, ShiftStateIBM939Flush) {
236-
StringRef Src0(EarthUTFBroken);
237-
StringRef Src1(EarthKanjiOnlyUTF);
238-
SmallString<64> Dst0;
239-
SmallString<64> Dst1;
240-
ErrorOr<CharSetConverter> ConvTo939Flush =
241-
CharSetConverter::create("UTF-8", "IBM-939");
242-
if (!ConvTo939Flush) {
243-
ASSERT_EQ(ConvTo939Flush.getError(),
244-
std::make_error_code(std::errc::invalid_argument));
245-
return;
246-
}
247-
248-
// This should emit an error; there is a malformed multibyte character in the
249-
// input string.
250-
std::error_code EC0 = ConvTo939Flush->convert(Src0, Dst0, true);
251-
EXPECT_TRUE(EC0);
252-
std::error_code EC1 = ConvTo939Flush->flush();
253-
EXPECT_TRUE(!EC1);
254-
std::error_code EC2 = ConvTo939Flush->convert(Src1, Dst1, true);
255-
EXPECT_TRUE(!EC2);
256-
EXPECT_STREQ(EarthKanjiOnlyIBM939, static_cast<std::string>(Dst1).c_str());
257-
}
258-
259-
TEST(CharSet, ShiftState2022Flush1) {
260-
StringRef Src0(EarthUTF);
261-
SmallString<64> Dst0;
262-
SmallString<64> Dst1;
263-
ErrorOr<CharSetConverter> ConvTo2022Flush =
264-
CharSetConverter::create("UTF-8", "ISO-2022-JP");
265-
if (!ConvTo2022Flush) {
266-
ASSERT_EQ(ConvTo2022Flush.getError(),
267-
std::make_error_code(std::errc::invalid_argument));
268-
return;
269-
}
270-
271-
std::error_code EC0 = ConvTo2022Flush->convert(Src0, Dst0, false);
272-
EXPECT_TRUE(!EC0);
273-
EXPECT_STREQ(EarthISO2022ShiftBack, static_cast<std::string>(Dst0).c_str());
274-
std::error_code EC1 = ConvTo2022Flush->flush(Dst1);
275-
EXPECT_TRUE(!EC1);
276-
EXPECT_STREQ(ShiftBackOnly, static_cast<std::string>(Dst1).c_str());
277-
}
278-
279-
#endif
280-
281196
} // namespace

0 commit comments

Comments
 (0)