Skip to content

Commit b3cd3ab

Browse files
committed
pulled out repeated UTF-16 character generation code
1 parent 4dc4772 commit b3cd3ab

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
@@ -244,7 +244,7 @@ class simplecpp::TokenList::Stream {
244244
// character is non-ASCII character then replace it with 0xff
245245
if (isUtf16) {
246246
const unsigned char ch2 = static_cast<unsigned char>(get());
247-
const int ch16 = (bom == 0xfeff) ? (ch<<8 | ch2) : (ch2<<8 | ch);
247+
const int ch16 = makeUtf16Char(ch, ch2);
248248
ch = static_cast<unsigned char>(((ch16 >= 0x80) ? 0xff : ch16));
249249
}
250250

@@ -256,7 +256,7 @@ class simplecpp::TokenList::Stream {
256256
else if (isUtf16) {
257257
const int c1 = get();
258258
const int c2 = get();
259-
const int ch16 = (bom == 0xfeff) ? (c1<<8 | c2) : (c2<<8 | c1);
259+
const int ch16 = makeUtf16Char(c1, c2);
260260
if (ch16 != '\n') {
261261
unget();
262262
unget();
@@ -277,7 +277,7 @@ class simplecpp::TokenList::Stream {
277277
(void)get();
278278
const unsigned char ch2 = static_cast<unsigned char>(peek());
279279
unget();
280-
const int ch16 = (bom == 0xfeff) ? (ch<<8 | ch2) : (ch2<<8 | ch);
280+
const int ch16 = makeUtf16Char(ch, ch2);
281281
ch = static_cast<unsigned char>(((ch16 >= 0x80) ? 0xff : ch16));
282282
}
283283

@@ -302,6 +302,11 @@ class simplecpp::TokenList::Stream {
302302
}
303303

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

0 commit comments

Comments
 (0)