Skip to content

Commit ab58fd6

Browse files
committed
Update changelog
1 parent a2bca4d commit ab58fd6

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

CHANGES.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22

33
## v2.3.0 (2017-07-15) ##
44

5-
* Add `float.export` option that forces float encoder to use `var_export` for
6-
encoding floating point numbers
7-
* Float encoder now delegates integer encoding to the integer encoder
5+
* Added `string.utf8` option which causes the string encoder to escape all
6+
valid multibyte UTF-8 characters using the PHP7 unicode code point syntax.
7+
* Added `string.binary` option which causes the string encoder to encode all
8+
non UTF-8 strings using a `base64_encode()`.
9+
* Added `integer.type` option that accepts values `binary`, `octal`, `decimal`
10+
or `hexadecimal` which can be used to change the output syntax of integers.
11+
* Added `hex.capitalize` option that causes all hexadecimal character in
12+
output to appear in upper case
13+
* Added `float.export` option that forces float encoder to use `var_export`
14+
for encoding floating point numbers
15+
* Float encoder now delegates integer encoding to the integer encoder (to
16+
allow different integer types).
817

918
## v2.2.0 (2017-07-08) ##
1019

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ apply to following calls.
147147
When set to `false`, generation of all extra whitespace is disabled and all
148148
other settings that affect whitespace are ignored.
149149

150+
* **hex.capitalize** : &lt;boolean&gt; (false)<br>
151+
When set to `true` all hexadecimal characters in the output are written
152+
using upper case instead of lower case.
153+
150154
* **null.capitalize** : &lt;boolean&gt; (false)<br>
151155
When set to `true`, all `null` values are written in upper case instead of
152156
lower case.
@@ -155,25 +159,45 @@ apply to following calls.
155159
When set to `true`, all `true` and `false` values are written in upper case
156160
instead of lower case.
157161

162+
* **integer.type** : &lt;"binary"|"octal"|"decimal"|"hexadecimal"&gt; ("decimal")<br>
163+
Change the output syntax of integers. For example, using the type `"hexadecimal"`
164+
would output the number `15` as `0xf`.
165+
158166
* **float.integers** : &lt;boolean|"all"&gt; (false)<br>
159167
When set to `true`, any float that represents an integer and has a value
160168
that is accurately represented by the floating point number will be encoded
161169
as an integer instead of a float. (e.g. the value `2.0` will be encoded as
162170
`2`). To include the values that are not accurately represented, you may set
163171
option to `"all"`.
164172

173+
* **float.export** : &lt;boolean&gt; (false)<br>
174+
When set to `true` floats are encoded using `var_export()`, which causes a
175+
slightly different output on non integer floating point numbers compared to
176+
the standard implemented method. In some cases, this may produce more
177+
accurate numbers but with less cleaner representation.
178+
165179
* **float.precision** : &lt;integer|false&gt; (17)<br>
166180
The maximum precision of encoded floating point values, which usually also
167181
means the maximum number of digits in encoded floats. If the value is set to
168182
`false`, the PHP ini setting `serialize_precision` will be used instead.
169183
Note that due to the way floating point values work, a value greater than 17
170184
does not provide any additional precision.
171185

186+
* **string.binary** : &lt;boolean&gt; (false)<br>
187+
When set to `true` any string that is not valid UTF-8 will be encoded in
188+
base 64 and wrapped with `base64_decode()` call.
189+
172190
* **string.escape** : &lt;boolean&gt; (true)<br>
173191
When set to `true`, all strings containing bytes outside the 32-126 ASCII
174192
range will be written with double quotes and the characters outside the
175193
range will be escaped.
176194

195+
* **string.utf8** : &lt;boolean&gt; (false)<br>
196+
When both this option and `string.escape` are set to `true`, all valid
197+
multibyte UTF-8 characters in strings are encoded using the PHP7 unicode
198+
code point syntax. Note that this syntax does not work in PHP versions
199+
earlier than 7.0.
200+
177201
* **array.short** : &lt;boolean&gt; (true)<br>
178202
When set to `true`, arrays are enclosed using square brackets `[]` instead
179203
using of the long array notation `array()`.

src/Encoder/StringEncoder.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,11 @@ private function getDoubleQuotedString($string, $options)
111111
$string = $this->encodeUtf8($string, $options);
112112
}
113113

114-
$format = $options['hex.capitalize'] ? '\x%02X' : '\x%02x';
115-
116-
return sprintf('"%s"', preg_replace_callback(
117-
'/[^\x20-\x7E]/',
118-
function ($matches) use ($format) {
119-
return sprintf($format, ord($matches[0]));
120-
},
121-
$string
122-
));
114+
$hexFormat = function ($matches) use ($options) {
115+
return sprintf($options['hex.capitalize'] ? '\x%02X' : '\x%02x', ord($matches[0]));
116+
};
117+
118+
return sprintf('"%s"', preg_replace_callback('/[^\x20-\x7E]/', $hexFormat, $string));
123119
}
124120

125121
/**
@@ -130,7 +126,6 @@ function ($matches) use ($format) {
130126
*/
131127
private function encodeUtf8($string, $options)
132128
{
133-
$format = $options['hex.capitalize'] ? '\u{%X}' : '\u{%x}';
134129
$pattern =
135130
'/ [\xC2-\xDF][\x80-\xBF]
136131
| \xE0[\xA0-\xBF][\x80-\xBF]
@@ -140,8 +135,8 @@ private function encodeUtf8($string, $options)
140135
| [\xF1-\xF3][\x80-\xBF]{3}
141136
| \xF4[\x80-\x8F][\x80-\xBF]{2}/x';
142137

143-
return preg_replace_callback($pattern, function ($match) use ($format) {
144-
return sprintf($format, $this->getCodePoint($match[0]));
138+
return preg_replace_callback($pattern, function ($match) use ($options) {
139+
return sprintf($options['hex.capitalize'] ? '\u{%X}' : '\u{%x}', $this->getCodePoint($match[0]));
145140
}, $string);
146141
}
147142

0 commit comments

Comments
 (0)