File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,26 @@ TextInputStream::~TextInputStream() noexcept = default;
1515char *
1616TextInputStream::ReadLine ()
1717{
18+ if (!bom_checked) {
19+ bom_checked = true ;
20+
21+ /* try to strip a UTF-8 BOM;
22+ keep all bytes if it's not a BOM */
23+ auto dest = buffer.Write ();
24+ assert (dest.size () >= 3 );
25+ dest = dest.first (3 );
26+ size_t nbytes = is->LockRead (std::as_writable_bytes (dest));
27+ buffer.Append (nbytes);
28+
29+ auto r = buffer.Read ();
30+ if (r.size () >= 3 &&
31+ static_cast <unsigned char >(r[0 ]) == 0xEF &&
32+ static_cast <unsigned char >(r[1 ]) == 0xBB &&
33+ static_cast <unsigned char >(r[2 ]) == 0xBF ) {
34+ buffer.Consume (3 );
35+ }
36+ }
37+
1838 char *line = ReadBufferedLine (buffer);
1939 if (line != nullptr )
2040 return line;
Original file line number Diff line number Diff line change 1010class TextInputStream {
1111 InputStreamPtr is;
1212 StaticFifoBuffer<char , 4096 > buffer;
13+ bool bom_checked = false ;
1314
1415public:
1516 /* *
You can’t perform that action at this time.
0 commit comments