Skip to content

Commit 312233f

Browse files
committed
pulled out repeated UTF-16 character generation code
1 parent 276f09b commit 312233f

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

simplecpp.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class simplecpp::TokenList::Stream {
245245
// character is non-ASCII character then replace it with 0xff
246246
if (isUtf16) {
247247
const unsigned char ch2 = static_cast<unsigned char>(get());
248-
const int ch16 = (bom == 0xfeff) ? (ch<<8 | ch2) : (ch2<<8 | ch);
248+
const int ch16 = makeUtf16Char(ch, ch2);
249249
ch = static_cast<unsigned char>(((ch16 >= 0x80) ? 0xff : ch16));
250250
}
251251

@@ -257,7 +257,7 @@ class simplecpp::TokenList::Stream {
257257
else if (isUtf16) {
258258
const int c1 = get();
259259
const int c2 = get();
260-
const int ch16 = (bom == 0xfeff) ? (c1<<8 | c2) : (c2<<8 | c1);
260+
const int ch16 = makeUtf16Char(c1, c2);
261261
if (ch16 != '\n') {
262262
unget();
263263
unget();
@@ -278,7 +278,7 @@ class simplecpp::TokenList::Stream {
278278
(void)get();
279279
const unsigned char ch2 = static_cast<unsigned char>(peek());
280280
unget();
281-
const int ch16 = (bom == 0xfeff) ? (ch<<8 | ch2) : (ch2<<8 | ch);
281+
const int ch16 = makeUtf16Char(ch, ch2);
282282
ch = static_cast<unsigned char>(((ch16 >= 0x80) ? 0xff : ch16));
283283
}
284284

@@ -303,6 +303,11 @@ class simplecpp::TokenList::Stream {
303303
}
304304

305305
private:
306+
inline int makeUtf16Char(const unsigned char ch, const unsigned char ch2) const
307+
{
308+
return (bom == 0xfeff) ? (ch<<8 | ch2) : (ch2<<8 | ch);
309+
}
310+
306311
unsigned short getAndSkipBOM()
307312
{
308313
const int ch1 = peek();

0 commit comments

Comments
 (0)