Skip to content

Commit

Permalink
Compare to empty string (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
trobro authored Oct 23, 2023
1 parent dc722da commit c0c76eb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/HJSON/HJSONParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private function _array()
$this->white();
if ($kw !== null) {
$c = $this->getComment($wat);
if (trim($c)) {
if (trim($c) !== '') {
$kw[] = $c;
}
}
Expand All @@ -193,7 +193,7 @@ private function _array()
}
if ($kw !== null) {
$c = $this->getComment($wat);
if (trim($c)) {
if (trim($c) !== '') {
$kw[] = $c;
}
}
Expand Down Expand Up @@ -276,7 +276,7 @@ private function object($withoutBraces = false)
private function pushWhite($key, &$kw, $wat)
{
$kw->c->$key = $this->getComment($wat);
if (trim($key)) {
if (trim($key) !== '') {
$kw->o[] = $key;
}
}
Expand Down Expand Up @@ -348,7 +348,7 @@ private function next($c = false)
{
// If a c parameter is provided, verify that it matches the current character.

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

Expand Down
6 changes: 3 additions & 3 deletions src/HJSON/HJSONStringifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private function mlString($string, $gap)
$res = $this->eol . $gap . "'''";
for ($i = 0; $i < count($a); $i++) {
$res .= $this->eol;
if ($a[$i]) {
if ($a[$i] !== '') {
$res .= $gap . $a[$i];
}
}
Expand All @@ -178,7 +178,7 @@ private function mlString($string, $gap)

private function quoteName($name)
{
if (!$name) {
if ($name === '') {
return '""';
}

Expand All @@ -202,7 +202,7 @@ private function str($value, $hasComment = null, $noIndent = null, $isRootObject
return $str && !$startsWithNL($str);
};
$wsc = function ($str) {
if (!$str) {
if ($str === '') {
return "";
}
for ($i = 0; $i < mb_strlen($str); $i++) {
Expand Down
5 changes: 5 additions & 0 deletions tests/assets/strings_result.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
'''
multiline4: ←→±≠Я
multiline5: åäö
multiline6:
'''
bar
0
'''
foo1a: asdf\"'a\s\w
foo1b: asdf\"'a\s\w
foo1c: asdf\"'a\s\w
Expand Down
1 change: 1 addition & 0 deletions tests/assets/strings_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"multiline3": "first line\n indented line\nlast line\n",
"multiline4": "←→±≠Я",
"multiline5": "åäö",
"multiline6": "bar\n0",
"foo1a": "asdf\\\"'a\\s\\w",
"foo1b": "asdf\\\"'a\\s\\w",
"foo1c": "asdf\\\"'a\\s\\w",
Expand Down
2 changes: 2 additions & 0 deletions tests/assets/strings_test.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
åäö
'''

multiline6: "bar\n0"

# escapes/no escape

foo1a: asdf\"'a\s\w
Expand Down

0 comments on commit c0c76eb

Please sign in to comment.