Skip to content

Commit 967bcf3

Browse files
committed
pulled out repeated UTF-16 character generation code
1 parent c45d90b commit 967bcf3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

simplecpp.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class simplecpp::TokenList::Stream {
230230
// character is non-ASCII character then replace it with 0xff
231231
if (isUtf16) {
232232
const unsigned char ch2 = static_cast<unsigned char>(get());
233-
const int ch16 = (bom == 0xfeff) ? (ch<<8 | ch2) : (ch2<<8 | ch);
233+
const int ch16 = makeUtf16Char(ch, ch2);
234234
ch = static_cast<unsigned char>(((ch16 >= 0x80) ? 0xff : ch16));
235235
}
236236

@@ -242,7 +242,7 @@ class simplecpp::TokenList::Stream {
242242
else if (isUtf16) {
243243
const int c1 = get();
244244
const int c2 = get();
245-
const int ch16 = (bom == 0xfeff) ? (c1<<8 | c2) : (c2<<8 | c1);
245+
const int ch16 = makeUtf16Char(c1, c2);
246246
if (ch16 != '\n') {
247247
unget();
248248
unget();
@@ -263,7 +263,7 @@ class simplecpp::TokenList::Stream {
263263
(void)get();
264264
const unsigned char ch2 = static_cast<unsigned char>(peek());
265265
unget();
266-
const int ch16 = (bom == 0xfeff) ? (ch<<8 | ch2) : (ch2<<8 | ch);
266+
const int ch16 = makeUtf16Char(ch, ch2);
267267
ch = static_cast<unsigned char>(((ch16 >= 0x80) ? 0xff : ch16));
268268
}
269269

@@ -288,6 +288,11 @@ class simplecpp::TokenList::Stream {
288288
}
289289

290290
private:
291+
inline int makeUtf16Char(const unsigned char ch, const unsigned char ch2) const
292+
{
293+
return (bom == 0xfeff) ? (ch<<8 | ch2) : (ch2<<8 | ch);
294+
}
295+
291296
unsigned short getAndSkipBOM()
292297
{
293298
const int ch1 = peek();

0 commit comments

Comments
 (0)