Skip to content

Commit d720094

Browse files
committed
Ran clang-format
1 parent fac0e47 commit d720094

2 files changed

Lines changed: 35 additions & 39 deletions

File tree

include/vsg/io/json.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ namespace vsg
4141

4242
inline bool white_space(char c) const
4343
{
44-
return (c==' ' || c=='\t' || c=='\r' || c=='\n');
44+
return (c == ' ' || c == '\t' || c == '\r' || c == '\n');
4545
}
4646

4747
bool read_string(std::string& value);
4848

4949
vsg::ref_ptr<vsg::Object> read_array();
5050
vsg::ref_ptr<vsg::Object> read_object();
5151
};
52-
VSG_type_name(vsg::JSONParser)
52+
VSG_type_name(vsg::JSONParser);
5353

5454
/// json ReaderWriter
5555
class json : public vsg::Inherit<vsg::ReaderWriter, json>
@@ -67,6 +67,6 @@ namespace vsg
6767

6868
bool getFeatures(Features& features) const override;
6969
};
70-
VSG_type_name(vsg::json)
70+
VSG_type_name(vsg::json);
7171

72-
}
72+
} // namespace vsg

src/vsg/io/json.cpp

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1313
#include <vsg/core/Objects.h>
1414
#include <vsg/core/Value.h>
1515
#include <vsg/io/Path.h>
16-
#include <vsg/io/mem_stream.h>
1716
#include <vsg/io/json.h>
17+
#include <vsg/io/mem_stream.h>
1818

1919
#include <fstream>
2020

@@ -34,14 +34,14 @@ bool JSONParser::read_string(std::string& value)
3434
if (buffer[pos] != '"') return false;
3535

3636
// read string
37-
auto end_of_value = buffer.find('"', pos+1);
37+
auto end_of_value = buffer.find('"', pos + 1);
3838
if (end_of_value == std::string::npos) return false;
3939

4040
// could have escape characters.
4141

42-
value = buffer.substr(pos+1, end_of_value-pos-1);
42+
value = buffer.substr(pos + 1, end_of_value - pos - 1);
4343

44-
pos = end_of_value+1;
44+
pos = end_of_value + 1;
4545

4646
return true;
4747
}
@@ -58,7 +58,7 @@ vsg::ref_ptr<vsg::Object> JSONParser::read_array()
5858

5959
// buffer[pos] == '['
6060
// advance past open bracket
61-
pos = buffer.find_first_not_of(" \t\r\n", pos+1);
61+
pos = buffer.find_first_not_of(" \t\r\n", pos + 1);
6262
if (pos == std::string::npos)
6363
{
6464
vsg::info(indent, "read_array() contents after [");
@@ -69,7 +69,7 @@ vsg::ref_ptr<vsg::Object> JSONParser::read_array()
6969

7070
auto objects = vsg::Objects::create();
7171

72-
while(pos != std::string::npos && pos < buffer.size() && buffer[pos] != ']')
72+
while (pos != std::string::npos && pos < buffer.size() && buffer[pos] != ']')
7373
{
7474
// now look to pair with value after " : "
7575
if (buffer[pos] == '{')
@@ -95,27 +95,27 @@ vsg::ref_ptr<vsg::Object> JSONParser::read_array()
9595
}
9696
else
9797
{
98-
auto end_of_field = buffer.find_first_of(",}]", pos+1);
98+
auto end_of_field = buffer.find_first_of(",}]", pos + 1);
9999
if (end_of_field == std::string::npos) break;
100100

101101
auto end_of_value = end_of_field - 1;
102-
while(end_of_value > 0 && white_space(buffer[end_of_value])) --end_of_value;
102+
while (end_of_value > 0 && white_space(buffer[end_of_value])) --end_of_value;
103103

104-
if (buffer.compare(pos, end_of_value-pos, "null")==0)
104+
if (buffer.compare(pos, end_of_value - pos, "null") == 0)
105105
{
106106
objects->children.push_back(nullptr);
107107
}
108-
else if (buffer.compare(pos, end_of_value-pos, "true")==0)
108+
else if (buffer.compare(pos, end_of_value - pos, "true") == 0)
109109
{
110110
objects->children.push_back(vsg::boolValue::create(true));
111111
}
112-
else if (buffer.compare(pos, end_of_value-pos, "false")==0)
112+
else if (buffer.compare(pos, end_of_value - pos, "false") == 0)
113113
{
114114
objects->children.push_back(vsg::boolValue::create(false));
115115
}
116116
else
117117
{
118-
mstr.set(reinterpret_cast<const uint8_t*>(&buffer.at(pos)), end_of_value-pos+1);
118+
mstr.set(reinterpret_cast<const uint8_t*>(&buffer.at(pos)), end_of_value - pos + 1);
119119

120120
double value;
121121
mstr >> value;
@@ -146,25 +146,24 @@ vsg::ref_ptr<vsg::Object> JSONParser::read_object()
146146

147147
// buffer[pos] == '{'
148148
// advance past open bracket
149-
pos = buffer.find_first_not_of(" \t\r\n", pos+1);
149+
pos = buffer.find_first_not_of(" \t\r\n", pos + 1);
150150
if (pos == std::string::npos) return {};
151151

152152
indent += 4;
153153

154-
155154
auto object = vsg::Object::create();
156155

157-
while(pos != std::string::npos && pos < buffer.size() && buffer[pos] != '}')
156+
while (pos != std::string::npos && pos < buffer.size() && buffer[pos] != '}')
158157
{
159158
if (buffer[pos] == '"')
160159
{
161-
auto end_of_string = buffer.find('"', pos+1);
160+
auto end_of_string = buffer.find('"', pos + 1);
162161
if (end_of_string == std::string::npos) break;
163162

164-
std::string_view name(&buffer[pos+1], end_of_string-pos-1);
163+
std::string_view name(&buffer[pos + 1], end_of_string - pos - 1);
165164

166165
// skip white space
167-
pos = buffer.find_first_not_of(" \t\r\n", end_of_string+1);
166+
pos = buffer.find_first_not_of(" \t\r\n", end_of_string + 1);
168167
if (pos == std::string::npos)
169168
{
170169
vsg::info(indent, "read_object() deliminator error end of buffer.");
@@ -174,12 +173,12 @@ vsg::ref_ptr<vsg::Object> JSONParser::read_object()
174173
// make sure next charater is the {name : value} deliminator
175174
if (buffer[pos] != ':')
176175
{
177-
vsg::info(indent, "read_object() deliminator error buffer[",pos,"] = ", buffer[pos]);
176+
vsg::info(indent, "read_object() deliminator error buffer[", pos, "] = ", buffer[pos]);
178177
break;
179178
}
180179

181180
// skip white space
182-
pos = buffer.find_first_not_of(" \t\r\n", pos+1);
181+
pos = buffer.find_first_not_of(" \t\r\n", pos + 1);
183182
if (pos == std::string::npos)
184183
{
185184
break;
@@ -207,28 +206,28 @@ vsg::ref_ptr<vsg::Object> JSONParser::read_object()
207206
}
208207
else
209208
{
210-
auto end_of_field = buffer.find_first_of(",}]", pos+1);
209+
auto end_of_field = buffer.find_first_of(",}]", pos + 1);
211210
if (end_of_field == std::string::npos) break;
212211

213212
auto end_of_value = end_of_field - 1;
214-
while(end_of_value > 0 && white_space(buffer[end_of_value])) --end_of_value;
213+
while (end_of_value > 0 && white_space(buffer[end_of_value])) --end_of_value;
215214

216-
if (buffer.compare(pos, end_of_value-pos, "null")==0)
215+
if (buffer.compare(pos, end_of_value - pos, "null") == 0)
217216
{
218217
// non op?
219218
object->setObject(std::string(name), nullptr);
220219
}
221-
else if (buffer.compare(pos, end_of_value-pos, "true")==0)
220+
else if (buffer.compare(pos, end_of_value - pos, "true") == 0)
222221
{
223222
object->setValue(std::string(name), true);
224223
}
225-
else if (buffer.compare(pos, end_of_value-pos, "false")==0)
224+
else if (buffer.compare(pos, end_of_value - pos, "false") == 0)
226225
{
227226
object->setValue(std::string(name), false);
228227
}
229228
else
230229
{
231-
mstr.set(reinterpret_cast<const uint8_t*>(&buffer.at(pos)), end_of_value-pos+1);
230+
mstr.set(reinterpret_cast<const uint8_t*>(&buffer.at(pos)), end_of_value - pos + 1);
232231

233232
double value;
234233
mstr >> value;
@@ -238,7 +237,6 @@ vsg::ref_ptr<vsg::Object> JSONParser::read_object()
238237
// skip to end of field
239238
pos = end_of_field;
240239
}
241-
242240
}
243241
else if (buffer[pos] == ',')
244242
{
@@ -280,7 +278,7 @@ vsg::ref_ptr<vsg::Object> json::_read(std::istream& fin, vsg::ref_ptr<const vsg:
280278
fin.seekg(0, fin.end);
281279
size_t fileSize = fin.tellg();
282280

283-
if (fileSize==0) return {};
281+
if (fileSize == 0) return {};
284282

285283
JSONParser parser;
286284

@@ -295,13 +293,13 @@ vsg::ref_ptr<vsg::Object> json::_read(std::istream& fin, vsg::ref_ptr<const vsg:
295293
parser.pos = parser.buffer.find_first_not_of(" \t\r\n", 0);
296294
if (parser.pos == std::string::npos) return {};
297295

298-
if (parser.buffer[parser.pos]=='{')
296+
if (parser.buffer[parser.pos] == '{')
299297
{
300-
result = parser.read_object();
298+
result = parser.read_object();
301299
}
302-
else if (parser.buffer[parser.pos]=='[')
300+
else if (parser.buffer[parser.pos] == '[')
303301
{
304-
result = parser.read_array();
302+
result = parser.read_array();
305303
}
306304
else
307305
{
@@ -311,10 +309,9 @@ vsg::ref_ptr<vsg::Object> json::_read(std::istream& fin, vsg::ref_ptr<const vsg:
311309
return result;
312310
}
313311

314-
315312
vsg::ref_ptr<vsg::Object> json::read(const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> options) const
316313
{
317-
vsg::Path ext = (options && options->extensionHint) ? options->extensionHint : vsg::lowerCaseFileExtension(filename);
314+
vsg::Path ext = (options && options->extensionHint) ? options->extensionHint : vsg::lowerCaseFileExtension(filename);
318315
if (!supportedExtension(ext)) return {};
319316

320317
vsg::Path filenameToUse = vsg::findFile(filename, options);
@@ -341,7 +338,6 @@ vsg::ref_ptr<vsg::Object> json::read(const uint8_t* ptr, size_t size, vsg::ref_p
341338
return _read(fin, options);
342339
}
343340

344-
345341
bool json::getFeatures(Features& features) const
346342
{
347343
vsg::ReaderWriter::FeatureMask supported_features = static_cast<vsg::ReaderWriter::FeatureMask>(vsg::ReaderWriter::READ_FILENAME | vsg::ReaderWriter::READ_ISTREAM | vsg::ReaderWriter::READ_MEMORY);

0 commit comments

Comments
 (0)