Skip to content

Commit 890f034

Browse files
committed
Simplify for and satisfy phpcs
1 parent 3545a00 commit 890f034

2 files changed

Lines changed: 3 additions & 7 deletions

File tree

src/HJSON/HJSONParser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ private function value()
105105
if ($this->peek(0) !== '\'' || $this->peek(1) !== '\'') {
106106
return $this->string('\'');
107107
}
108+
// Falls through on multiline strings
108109
default:
109110
return $this->tfnns();
110111
}

src/HJSON/HJSONStringifier.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ class HJSONStringifier
1919
// needsQuotes tests if the string can be written as a quoteless string (includes needsEscape but without \\ and \")
2020
private $needsQuotes = '/^\\s|^"|^\'|^\'\'\'|^#|^\\/\\*|^\\/\\/|^\\{|^\\}|^\\[|^\\]|^:|^,|\\s$|[\x00-\x1f\x7f-\x9f\x{00ad}\x{0600}-\x{0604}\x{070f}\x{17b4}\x{17b5}\x{200c}-\x{200f}\x{2028}-\x{202f}\x{2060}-\x{206f}\x{feff}\x{fff0}-\x{ffff}\x]/u';
2121
// needsEscapeML tests if the string can be written as a multiline string (includes needsEscape but without \n, \r, \\ and \")
22-
private $needsEscapeML = '/\'\'\'|[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f\x{00ad}\x{0600}-\x{0604}\x{070f}\x{17b4}\x{17b5}\x{200c}-\x{200f}\x{2028}-\x{202f}\x{2060}-\x{206f}\x{feff}\x{fff0}-\x{ffff}\x]/u';
23-
private $onlyWhitespace = '/^\\s+$/';
22+
private $needsEscapeML = '/^\\s+$|\'\'\'|[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f\x{00ad}\x{0600}-\x{0604}\x{070f}\x{17b4}\x{17b5}\x{200c}-\x{200f}\x{2028}-\x{202f}\x{2060}-\x{206f}\x{feff}\x{fff0}-\x{ffff}\x]/u';
2423
private $startsWithKeyword = '/^(true|false|null)\s*((,|\]|\}|#|\/\/|\/\*).*)?$/';
2524
private $needsEscapeName = '/[,\{\[\}\]\s:#"\']|\/\/|\/\*|\'\'\'/';
2625
private $gap = '';
@@ -142,11 +141,7 @@ private function quote($string = null, $gap = null, $hasComment = null, $isRootO
142141

143142
if (!preg_match($this->needsEscape, $string)) {
144143
return '"' . $string . '"';
145-
} elseif (
146-
!preg_match($this->needsEscapeML, $string) &&
147-
!preg_match($this->onlyWhitespace, $string) &&
148-
!$isRootObject
149-
) {
144+
} elseif (!preg_match($this->needsEscapeML, $string) && !$isRootObject) {
150145
return $this->mlString($string, $gap);
151146
} else {
152147
return '"' . $this->quoteReplace($string) . '"';

0 commit comments

Comments
 (0)