41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
*/
|
|
|
|
use \php\Boot;
|
|
|
|
/**
|
|
* This class provides advanced methods on Strings. It is ideally used with
|
|
* `using StringTools` and then acts as an [extension](https://haxe.org/manual/lf-static-extension.html)
|
|
* to the `String` class.
|
|
* If the first argument to any of the methods is null, the result is
|
|
* unspecified.
|
|
*/
|
|
class StringTools {
|
|
/**
|
|
* Replace all occurrences of the String `sub` in the String `s` by the
|
|
* String `by`.
|
|
* If `sub` is the empty String `""`, `by` is inserted after each character
|
|
* of `s` except the last one. If `by` is also the empty String `""`, `s`
|
|
* remains unchanged.
|
|
* If `sub` or `by` are null, the result is unspecified.
|
|
*
|
|
* @param string $s
|
|
* @param string $sub
|
|
* @param string $by
|
|
*
|
|
* @return string
|
|
*/
|
|
public static function replace ($s, $sub, $by) {
|
|
#/nix/store/ljakxdz94hcvn9b4k9y292dn5lhh20iy-haxe-4.2.5/lib/haxe/std/php/_std/StringTools.hx:104: lines 104-106
|
|
if ($sub === "") {
|
|
#/nix/store/ljakxdz94hcvn9b4k9y292dn5lhh20iy-haxe-4.2.5/lib/haxe/std/php/_std/StringTools.hx:105: characters 4-89
|
|
return implode($by, preg_split("//u", $s, -1, PREG_SPLIT_NO_EMPTY));
|
|
}
|
|
#/nix/store/ljakxdz94hcvn9b4k9y292dn5lhh20iy-haxe-4.2.5/lib/haxe/std/php/_std/StringTools.hx:107: characters 3-40
|
|
return str_replace($sub, $by, $s);
|
|
}
|
|
}
|
|
|
|
Boot::registerClass(StringTools::class, 'StringTools');
|