Skip to content

Commit 5e3b81d

Browse files
authored
Merge pull request #8 from red-gate/TinyJsonDeser-Readability
Improved code readability for parsing `true`, `false` and `null`.
2 parents 6c9a0e9 + dc3a2dd commit 5e3b81d

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

Source/ULibs.TinyJsonDeser/JsonDeserializer.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,7 @@ private static bool TryParseBool(string json, ref int offset, out bool output)
247247
switch (json[offset])
248248
{
249249
case 't':
250-
if (offset < json.Length - 3 &&
251-
json[offset + 1] == 'r' &&
252-
json[offset + 2] == 'u' &&
253-
json[offset + 3] == 'e')
250+
if (offset < json.Length - 3 && json.Substring(offset, 4) == "true")
254251
{
255252
offset += 4;
256253
output = true;
@@ -260,11 +257,7 @@ private static bool TryParseBool(string json, ref int offset, out bool output)
260257
break;
261258

262259
case 'f':
263-
if (offset < json.Length - 4 &&
264-
json[offset + 1] == 'a' &&
265-
json[offset + 2] == 'l' &&
266-
json[offset + 3] == 's' &&
267-
json[offset + 4] == 'e')
260+
if (offset < json.Length - 4 && json.Substring(offset, 5) == "false")
268261
{
269262
offset += 5;
270263
return true;
@@ -279,11 +272,7 @@ private static bool TryParseBool(string json, ref int offset, out bool output)
279272

280273
private static bool TryParseNull(string json, ref int offset)
281274
{
282-
if (offset < json.Length - 3 &&
283-
json[offset] == 'n' &&
284-
json[offset + 1] == 'u' &&
285-
json[offset + 2] == 'l' &&
286-
json[offset + 3] == 'l')
275+
if (offset < json.Length - 3 && json.Substring(offset, 4) == "null")
287276
{
288277
offset += 4;
289278
return true;

Source/ULibs.TinyJsonDeser/RELEASENOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ULibs.TinyJsonDeser release notes
22

3+
## 1.0.1
4+
5+
### Features
6+
7+
- Improved code readability for parsing `true`, `false` and `null`.
8+
39
## 1.0.0
410

511
### Features

0 commit comments

Comments
 (0)