diff options
| author | Greg Roach <fisharebest@gmail.com> | 2014-08-29 13:46:05 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2014-08-29 13:46:05 +0100 |
| commit | eb53f53782422363cfdc4d01ad9b8c24d42026f3 (patch) | |
| tree | bc15e49922a8e21d8d73365d796b9f0ce2a3d49c /includes | |
| parent | ebc39acca2ca96117728927ff2cc4869252cc448 (diff) | |
| download | webtrees-eb53f53782422363cfdc4d01ad9b8c24d42026f3.tar.gz webtrees-eb53f53782422363cfdc4d01ad9b8c24d42026f3.tar.bz2 webtrees-eb53f53782422363cfdc4d01ad9b8c24d42026f3.zip | |
Move global I18N functions to I18N class
Diffstat (limited to 'includes')
| -rw-r--r-- | includes/functions/functions_export.php | 18 | ||||
| -rw-r--r-- | includes/functions/functions_rtl.php | 10 | ||||
| -rw-r--r-- | includes/functions/functions_utf-8.php | 72 | ||||
| -rw-r--r-- | includes/session.php | 1 |
4 files changed, 14 insertions, 87 deletions
diff --git a/includes/functions/functions_export.php b/includes/functions/functions_export.php index a529c552d3..29fd732ae8 100644 --- a/includes/functions/functions_export.php +++ b/includes/functions/functions_export.php @@ -38,8 +38,8 @@ function reformat_record_export($rec) { // Split long lines // The total length of a GEDCOM line, including level number, cross-reference number, // tag, value, delimiters, and terminator, must not exceed 255 (wide) characters. - // Use quick strlen() check before using slower utf8_strlen() check - if (strlen($line)>WT_GEDCOM_LINE_LENGTH && utf8_strlen($line)>WT_GEDCOM_LINE_LENGTH) { + // Use quick strlen() check before using slower WT_I18N::strlen() check + if (strlen($line)>WT_GEDCOM_LINE_LENGTH && WT_I18N::strlen($line)>WT_GEDCOM_LINE_LENGTH) { list($level, $tag)=explode(' ', $line, 3); if ($tag!='CONT' && $tag!='CONC') { $level++; @@ -49,29 +49,29 @@ function reformat_record_export($rec) { $pos=WT_GEDCOM_LINE_LENGTH; if ($WORD_WRAPPED_NOTES) { // Split on a space, and remove it (for compatibility with some desktop apps) - while ($pos && utf8_substr($line, $pos-1, 1)!=' ') { + while ($pos && WT_I18N::substr($line, $pos-1, 1)!=' ') { --$pos; } if ($pos==strpos($line, ' ', 3)+1) { // No spaces in the data! Can’t split it :-( break; } else { - $newrec.=utf8_substr($line, 0, $pos-1).WT_EOL; - $line=$level.' CONC '.utf8_substr($line, $pos); + $newrec.=WT_I18N::substr($line, 0, $pos-1).WT_EOL; + $line=$level.' CONC '.WT_I18N::substr($line, $pos); } } else { // Split on a non-space (standard gedcom behaviour) - while ($pos && utf8_substr($line, $pos-1, 1)==' ') { + while ($pos && WT_I18N::substr($line, $pos-1, 1)==' ') { --$pos; } if ($pos==strpos($line, ' ', 3)) { // No non-spaces in the data! Can’t split it :-( break; } - $newrec.=utf8_substr($line, 0, $pos).WT_EOL; - $line=$level.' CONC '.utf8_substr($line, $pos); + $newrec.=WT_I18N::substr($line, 0, $pos).WT_EOL; + $line=$level.' CONC '.WT_I18N::substr($line, $pos); } - } while (utf8_strlen($line)>WT_GEDCOM_LINE_LENGTH); + } while (WT_I18N::strlen($line)>WT_GEDCOM_LINE_LENGTH); } $newrec.=$line.WT_EOL; } diff --git a/includes/functions/functions_rtl.php b/includes/functions/functions_rtl.php index b1ee549195..b194d3b2d7 100644 --- a/includes/functions/functions_rtl.php +++ b/includes/functions/functions_rtl.php @@ -1039,21 +1039,21 @@ function finishCurrentSpan(&$result, $theEnd=false) { function utf8_wordwrap($string, $width=75, $sep="\n", $cut=false) { $out=''; while ($string) { - if (utf8_strlen($string) <= $width){ //Do not wrap any text that is less than the output area. + if (WT_I18N::strlen($string) <= $width){ //Do not wrap any text that is less than the output area. $out.=$string; $string=''; } else { - $sub1=utf8_substr($string, 0, $width+1); - if (utf8_substr($string,utf8_strlen($sub1)-1,1)==' ') //include words that end by a space immediately after the area. + $sub1=WT_I18N::substr($string, 0, $width+1); + if (WT_I18N::substr($string,WT_I18N::strlen($sub1)-1,1)==' ') //include words that end by a space immediately after the area. $sub=$sub1; else - $sub=utf8_substr($string, 0, $width); + $sub=WT_I18N::substr($string, 0, $width); $spacepos=strrpos($sub, ' '); if ($spacepos==false) { // No space on line? if ($cut) { $out.=$sub.$sep; - $string=utf8_substr($string, utf8_strlen($sub)); + $string=WT_I18N::substr($string, WT_I18N::strlen($sub)); } else { $spacepos=strpos($string, ' '); if ($spacepos==false) { diff --git a/includes/functions/functions_utf-8.php b/includes/functions/functions_utf-8.php deleted file mode 100644 index c3f5fb699f..0000000000 --- a/includes/functions/functions_utf-8.php +++ /dev/null @@ -1,72 +0,0 @@ -<?php -// UTF-8 versions of PHP string functions -// -// webtrees: Web based Family History software -// Copyright (C) 2014 webtrees development team. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -function utf8_substr($string, $pos, $len=PHP_INT_MAX) { - if ($len<0) { - return ''; - } - $strlen=strlen($string); - if ($pos==0) { - $start=0; - } elseif ($pos>0) { - $start=0; - while ($pos>0 && $start<$strlen) { - ++$start; - while ($start<$strlen && (ord($string[$start]) & 0xC0) == 0x80) { - ++$start; - } - --$pos; - } - } else { - $start=$strlen-1; - do { - --$start; - while ($start && (ord($string[$start]) & 0xC0) == 0x80) { - --$start; - } - ++$pos; - } while ($start && $pos<0); - } - if ($len==PHP_INT_MAX || $len<0) { - return substr($string, $start); - } - $end=$start; - while ($len>0) { - ++$end; - while ($end<$strlen && (ord($string[$end]) & 0xC0) == 0x80) { - ++$end; - } - --$len; - } - return substr($string, $start, $end-$start); -} - -function utf8_strlen($string) { - $pos=0; - $len=strlen($string); - $utf8_len=0; - while ($pos<$len) { - if ((ord($string[$pos]) & 0xC0) != 0x80) { - ++$utf8_len; - } - ++$pos; - } - return $utf8_len; -} diff --git a/includes/session.php b/includes/session.php index e22edeeb7e..0cf4fd2180 100644 --- a/includes/session.php +++ b/includes/session.php @@ -232,7 +232,6 @@ require WT_ROOT.'includes/functions/functions_print.php'; require WT_ROOT.'includes/functions/functions_mediadb.php'; require WT_ROOT.'includes/functions/functions_date.php'; require WT_ROOT.'includes/functions/functions_charts.php'; -require WT_ROOT.'includes/functions/functions_utf-8.php'; // Set a custom error handler set_error_handler(function ($errno, $errstr) { |
