Add initial bits for Qt6 support
[carla.git] / source / modules / ysfx / sources / ysfx_reader.cpp
blob9b3cb2ad9ceee2a5b6dd1cb2d9c958ebf93384f4
1 // Copyright 2021 Jean Pierre Cimalando
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // SPDX-License-Identifier: Apache-2.0
18 #include "ysfx_reader.hpp"
20 namespace ysfx {
22 //------------------------------------------------------------------------------
23 bool text_reader::read_next_line(std::string &line)
25 line.clear();
27 char next = read_next_char();
28 if (next == '\0')
29 return false;
31 while (next != '\0' && next != '\r' && next != '\n') {
32 line.push_back(next);
33 next = read_next_char();
36 if (next == '\r') {
37 next = peek_next_char();
38 if (next == '\n')
39 read_next_char();
42 return true;
45 //------------------------------------------------------------------------------
46 char string_text_reader::read_next_char()
48 const char *ptr = m_char_ptr;
50 if (!ptr || *ptr == '\0')
51 return '\0';
53 char next = *ptr;
54 m_char_ptr = ptr + 1;
55 return next;
58 char string_text_reader::peek_next_char()
60 const char *ptr = m_char_ptr;
62 if (!ptr)
63 return '\0';
65 return *ptr;
68 //------------------------------------------------------------------------------
69 char stdio_text_reader::read_next_char()
71 FILE *stream = m_stream;
73 if (!stream)
74 return '\0';
76 int next = fgetc(stream);
77 if (next == EOF)
78 return '\0';
80 return (unsigned char)next;
83 char stdio_text_reader::peek_next_char()
85 FILE *stream = m_stream;
87 if (!stream)
88 return '\0';
90 int next = fgetc(stream);
91 if (next == EOF)
92 return '\0';
94 ungetc(next, stream);
95 return (unsigned char)next;
98 } // namespace ysfx