From 3b06ee0d381dc1be5f40ca98ad4278046d869d21 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 17 Nov 2019 20:57:39 +0100 Subject: checked in initial customized verison for Archlinux32 --- include/utf8/trim.php | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 include/utf8/trim.php (limited to 'include/utf8/trim.php') diff --git a/include/utf8/trim.php b/include/utf8/trim.php new file mode 100644 index 0000000..3d22840 --- /dev/null +++ b/include/utf8/trim.php @@ -0,0 +1,74 @@ + +* @see http://www.php.net/ltrim +* @see http://dev.splitbrain.org/view/darcs/dokuwiki/inc/utf8.php +* @return string +* @package utf8 +* @subpackage strings +*/ +function utf8_ltrim( $str, $charlist=false) +{ + if($charlist === false) + return ltrim($str); + + // Quote charlist for use in a characterclass + $charlist = preg_replace('!([\\\\\\-\\]\\[/^])!', '\\\${1}', $charlist); + + return preg_replace('/^['.$charlist.']+/u', '', $str); +} + +/** +* UTF-8 aware replacement for rtrim() +* Note: you only need to use this if you are supplying the charlist +* optional arg and it contains UTF-8 characters. Otherwise rtrim will +* work normally on a UTF-8 string +* @author Andreas Gohr +* @see http://www.php.net/rtrim +* @see http://dev.splitbrain.org/view/darcs/dokuwiki/inc/utf8.php +* @return string +* @package utf8 +* @subpackage strings +*/ +function utf8_rtrim($str, $charlist=false) +{ + if($charlist === false) + return rtrim($str); + + // Quote charlist for use in a characterclass + $charlist = preg_replace('!([\\\\\\-\\]\\[/^])!', '\\\${1}', $charlist); + + return preg_replace('/['.$charlist.']+$/u', '', $str); +} + +//--------------------------------------------------------------- +/** +* UTF-8 aware replacement for trim() +* Note: you only need to use this if you are supplying the charlist +* optional arg and it contains UTF-8 characters. Otherwise trim will +* work normally on a UTF-8 string +* @author Andreas Gohr +* @see http://www.php.net/trim +* @see http://dev.splitbrain.org/view/darcs/dokuwiki/inc/utf8.php +* @return string +* @package utf8 +* @subpackage strings +*/ +function utf8_trim( $str, $charlist=false) +{ + if($charlist === false) + return trim($str); + + return utf8_ltrim(utf8_rtrim($str, $charlist), $charlist); +} -- cgit v1.2.3-54-g00ecf