File tree Expand file tree Collapse file tree 2 files changed +18
-9
lines changed
Expand file tree Collapse file tree 2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -112,16 +112,13 @@ bool Utf16Reader::getline(std::wstring& line)
112112 break ;
113113 }
114114 if (ch == L' \r ' ) {
115+ // CR encountered - check if followed by LF
115116 wchar_t next;
116- if (ReadChar (next)) {
117- if (next == L' \n ' ) {
118- // Found \r\n - line ending
119- break ;
120- }
121- // \r followed by something else - include only the next char
122- line += next;
117+ if (PeekChar (next) && next == L' \n ' ) {
118+ // CRLF sequence - consume the LF
119+ ReadChar (next);
123120 }
124- // Single \r as line ending
121+ // CR alone or CRLF - line ending (LF already consumed if present)
125122 break ;
126123 }
127124 else {
@@ -136,7 +133,10 @@ bool Utf16Reader::eof() const
136133 return file_.eof ();
137134}
138135
139- void Utf16Reader::close () { file_.close (); }
136+ void Utf16Reader::close ()
137+ {
138+ file_.close ();
139+ }
140140
141141bool Utf16Reader::ReadChar (wchar_t & ch)
142142{
@@ -148,6 +148,14 @@ bool Utf16Reader::ReadChar(wchar_t& ch)
148148 return true ;
149149}
150150
151+ bool Utf16Reader::PeekChar (wchar_t & ch)
152+ {
153+ ch = file_.peek ();
154+ if (ch == WEOF) {
155+ return false ;
156+ }
157+ return true ;
158+ }
151159
152160
153161Utf16Writer::Utf16Writer (const std::filesystem::path& filename)
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ class Utf16Reader {
1313
1414private:
1515 bool ReadChar (wchar_t & ch);
16+ bool PeekChar (wchar_t & ch);
1617 std::ifstream file_;
1718};
1819
You can’t perform that action at this time.
0 commit comments