Skip to content

Commit e9d0ce7

Browse files
Thomas Suckowmeta-codesync[bot]
authored andcommitted
Str\to_int can be suprising, update comment
Summary: None of the documentation indicates this method would fail for 0 padded integers. In WWW we can't even see the implementation. https://fb.workplace.com/groups/hackforhiphop/posts/2658306750884590 So we update the comment/docblock for the method. Apparently it is also going to get autoformatted. Reviewed By: viratyosin Differential Revision: D92540052 fbshipit-source-id: 1fcd98ca82ef14d4123c8710248ec2def9a8587a
1 parent 4fb8e97 commit e9d0ce7

1 file changed

Lines changed: 12 additions & 20 deletions

File tree

hphp/hsl/src/str/transform.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
*
2424
* @guide /hack/built-in-types/string
2525
*/
26-
function capitalize(
27-
string $string,
28-
)[]: string {
26+
function capitalize(string $string)[]: string {
2927
if ($string === '') {
3028
return '';
3129
}
32-
return _Str\uppercase_l(slice($string, 0, 1)) . slice($string, 1);
30+
return _Str\uppercase_l(slice($string, 0, 1)).slice($string, 1);
3331
}
3432

3533
/**
@@ -62,7 +60,7 @@ function capitalize_words(
6260
$substr_len = \strcspn($string, $delimiters, $offset);
6361
$words[] = tuple(
6462
\substr($string, $offset, $substr_len),
65-
$offset + $substr_len < $length ? $string[$offset + $substr_len] : ''
63+
$offset + $substr_len < $length ? $string[$offset + $substr_len] : '',
6664
);
6765
$offset += $substr_len + 1;
6866
}
@@ -90,7 +88,7 @@ function format_number(
9088
string $thousands_separator = ',',
9189
)[]: string {
9290
return \number_format(
93-
(float) $number,
91+
(float)$number,
9492
$decimals,
9593
$decimal_point,
9694
$thousands_separator,
@@ -102,9 +100,7 @@ function format_number(
102100
*
103101
* @guide /hack/built-in-types/string
104102
*/
105-
function lowercase(
106-
string $string,
107-
)[]: string {
103+
function lowercase(string $string)[]: string {
108104
return _Str\lowercase_l($string);
109105
}
110106

@@ -157,10 +153,7 @@ function pad_right(
157153
*
158154
* @guide /hack/built-in-types/string
159155
*/
160-
function repeat(
161-
string $string,
162-
int $multiplier,
163-
)[]: string {
156+
function repeat(string $string, int $multiplier)[]: string {
164157
if ($multiplier < 0) {
165158
throw new \InvalidArgumentException('Expected non-negative multiplier');
166159
}
@@ -352,13 +345,14 @@ function splice(
352345
}
353346

354347
/**
355-
* Returns the given string as an integer, or null if the string isn't numeric.
348+
* Returns the given string as an integer, or null if the string would not match exactly with the result of casting the integer back to a string.
349+
*
350+
* Note this means "01" is considered null.
351+
* Consider using `Math\from_base('011', 10)` instead or trimming leading 0's.
356352
*
357353
* @guide /hack/built-in-types/string
358354
*/
359-
function to_int(
360-
string $string,
361-
)[]: ?int {
355+
function to_int(string $string)[]: ?int {
362356
if ((string)(int)$string === $string) {
363357
return (int)$string;
364358
}
@@ -370,8 +364,6 @@ function to_int(
370364
*
371365
* @guide /hack/built-in-types/string
372366
*/
373-
function uppercase(
374-
string $string,
375-
)[]: string {
367+
function uppercase(string $string)[]: string {
376368
return _Str\uppercase_l($string);
377369
}

0 commit comments

Comments
 (0)