modifs.mineures sans commentaires
This commit is contained in:
parent
5c4a2e83ad
commit
b71cd8beb8
|
@ -154,10 +154,7 @@ class sh {
|
|||
return $retcode == 0;
|
||||
}
|
||||
// child, fork ok
|
||||
$shell = "/bin/bash";
|
||||
if (!file_exists($shell)) $shell = "/bin/sh";
|
||||
$shell = "/bin/sh";
|
||||
pcntl_exec($shell, ["-c", $cmd]);
|
||||
pcntl_exec("/bin/sh", ["-c", $cmd]);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
30
src/str.php
30
src/str.php
|
@ -354,25 +354,30 @@ class str {
|
|||
*/
|
||||
static final function camel2us(?string $camel, bool $upper=false, string $delimiter="_"): ?string {
|
||||
if ($camel === null || $camel === "") return $camel;
|
||||
$prefix = null;
|
||||
if (preg_match('/^(_+)(.*)/', $camel, $ms)) {
|
||||
$prefix = $ms[1];
|
||||
$camel = $ms[2];
|
||||
}
|
||||
$parts = [];
|
||||
if (preg_match(self::CAMEL_PATTERN0, $camel, $vs, PREG_OFFSET_CAPTURE)) {
|
||||
if (preg_match(self::CAMEL_PATTERN0, $camel, $ms, PREG_OFFSET_CAPTURE)) {
|
||||
# que des majuscules
|
||||
} elseif (preg_match(self::CAMEL_PATTERN1, $camel, $vs, PREG_OFFSET_CAPTURE)) {
|
||||
} elseif (preg_match(self::CAMEL_PATTERN1, $camel, $ms, PREG_OFFSET_CAPTURE)) {
|
||||
# préfixe en majuscule
|
||||
} elseif (preg_match(self::CAMEL_PATTERN2, $camel, $vs, PREG_OFFSET_CAPTURE)) {
|
||||
} elseif (preg_match(self::CAMEL_PATTERN2, $camel, $ms, PREG_OFFSET_CAPTURE)) {
|
||||
# préfixe en minuscule
|
||||
} else {
|
||||
throw ValueException::invalid_kind($camel, "camel string");
|
||||
}
|
||||
$parts[] = strtolower($vs[1][0]);
|
||||
$index = intval($vs[1][1]) + strlen($vs[1][0]);
|
||||
while (preg_match(self::CAMEL_PATTERN3, $camel, $vs, PREG_OFFSET_CAPTURE, $index) !== false && $vs) {
|
||||
$parts[] = strtolower($vs[1][0]);
|
||||
$index = intval($vs[1][1]) + strlen($vs[1][0]);
|
||||
$parts[] = strtolower($ms[1][0]);
|
||||
$index = intval($ms[1][1]) + strlen($ms[1][0]);
|
||||
while (preg_match(self::CAMEL_PATTERN3, $camel, $ms, PREG_OFFSET_CAPTURE, $index) !== false && $ms) {
|
||||
$parts[] = strtolower($ms[1][0]);
|
||||
$index = intval($ms[1][1]) + strlen($ms[1][0]);
|
||||
}
|
||||
$us = implode($delimiter, $parts);
|
||||
if ($upper) $us = strtoupper($us);
|
||||
return $us;
|
||||
return "$prefix$us";
|
||||
}
|
||||
|
||||
const US_PATTERN = '/([ _\-\t\r\n\f\v])/';
|
||||
|
@ -388,6 +393,11 @@ class str {
|
|||
*/
|
||||
static final function us2camel(?string $us, ?string $delimiters=null): ?string {
|
||||
if ($us === null || $us === "") return $us;
|
||||
$prefix = null;
|
||||
if (preg_match('/^(_+)(.*)/', $us, $ms)) {
|
||||
$prefix = $ms[1];
|
||||
$us = $ms[2];
|
||||
}
|
||||
if ($delimiters === null) $pattern = self::US_PATTERN;
|
||||
else $pattern = '/(['.preg_quote($delimiters).'])/';
|
||||
$parts = preg_split($pattern, $us);
|
||||
|
@ -398,6 +408,6 @@ class str {
|
|||
if ($i > 0) $part = ucfirst($part);
|
||||
$parts[$i] = $part;
|
||||
}
|
||||
return implode("", $parts);
|
||||
return $prefix.implode("", $parts);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,5 +20,9 @@ class strTest extends TestCase {
|
|||
self::assertSame("aaa_bbb", str::camel2us("aaaBbb"));
|
||||
self::assertSame("aa_bb", str::camel2us("AaBb"));
|
||||
self::assertSame("aaa_bbb", str::camel2us("AaaBbb"));
|
||||
|
||||
self::assertSame("_aaa", str::camel2us("_aaa"));
|
||||
self::assertSame("__aaa_bbb", str::camel2us("__aaaBbb"));
|
||||
self::assertSame("___aaa_bbb", str::camel2us("___AaaBbb"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue