Skip to content

Commit c0c76eb

Browse files
authored
Compare to empty string (#39)
1 parent dc722da commit c0c76eb

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

src/HJSON/HJSONParser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private function _array()
171171
$this->white();
172172
if ($kw !== null) {
173173
$c = $this->getComment($wat);
174-
if (trim($c)) {
174+
if (trim($c) !== '') {
175175
$kw[] = $c;
176176
}
177177
}
@@ -193,7 +193,7 @@ private function _array()
193193
}
194194
if ($kw !== null) {
195195
$c = $this->getComment($wat);
196-
if (trim($c)) {
196+
if (trim($c) !== '') {
197197
$kw[] = $c;
198198
}
199199
}
@@ -276,7 +276,7 @@ private function object($withoutBraces = false)
276276
private function pushWhite($key, &$kw, $wat)
277277
{
278278
$kw->c->$key = $this->getComment($wat);
279-
if (trim($key)) {
279+
if (trim($key) !== '') {
280280
$kw->o[] = $key;
281281
}
282282
}
@@ -348,7 +348,7 @@ private function next($c = false)
348348
{
349349
// If a c parameter is provided, verify that it matches the current character.
350350

351-
if ($c && $c !== $this->ch) {
351+
if ($c !== false && $c !== $this->ch) {
352352
$this->error("Expected '$c' instead of '{$this->ch}'");
353353
}
354354

src/HJSON/HJSONStringifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private function mlString($string, $gap)
168168
$res = $this->eol . $gap . "'''";
169169
for ($i = 0; $i < count($a); $i++) {
170170
$res .= $this->eol;
171-
if ($a[$i]) {
171+
if ($a[$i] !== '') {
172172
$res .= $gap . $a[$i];
173173
}
174174
}
@@ -178,7 +178,7 @@ private function mlString($string, $gap)
178178

179179
private function quoteName($name)
180180
{
181-
if (!$name) {
181+
if ($name === '') {
182182
return '""';
183183
}
184184

@@ -202,7 +202,7 @@ private function str($value, $hasComment = null, $noIndent = null, $isRootObject
202202
return $str && !$startsWithNL($str);
203203
};
204204
$wsc = function ($str) {
205-
if (!$str) {
205+
if ($str === '') {
206206
return "";
207207
}
208208
for ($i = 0; $i < mb_strlen($str); $i++) {

tests/assets/strings_result.hjson

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
'''
3131
multiline4: ←→±≠Я
3232
multiline5: åäö
33+
multiline6:
34+
'''
35+
bar
36+
0
37+
'''
3338
foo1a: asdf\"'a\s\w
3439
foo1b: asdf\"'a\s\w
3540
foo1c: asdf\"'a\s\w

tests/assets/strings_result.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"multiline3": "first line\n indented line\nlast line\n",
1515
"multiline4": "←→±≠Я",
1616
"multiline5": "åäö",
17+
"multiline6": "bar\n0",
1718
"foo1a": "asdf\\\"'a\\s\\w",
1819
"foo1b": "asdf\\\"'a\\s\\w",
1920
"foo1c": "asdf\\\"'a\\s\\w",

tests/assets/strings_test.hjson

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
åäö
4848
'''
4949

50+
multiline6: "bar\n0"
51+
5052
# escapes/no escape
5153

5254
foo1a: asdf\"'a\s\w

0 commit comments

Comments
 (0)