summaryrefslogtreecommitdiff
path: root/inc/utf8.php
diff options
context:
space:
mode:
authorchris <chris@jalakai.co.uk>2006-08-27 17:32:54 +0200
committerchris <chris@jalakai.co.uk>2006-08-27 17:32:54 +0200
commitf50163d1d772ac773f6d03ed049e4a0329674db9 (patch)
tree6444af39f7037eec981df00a1e01822064d5b074 /inc/utf8.php
parentced0762eb24c25ac27438d5bef2a6ff434e55dca (diff)
downloadrpg-f50163d1d772ac773f6d03ed049e4a0329674db9.tar.gz
rpg-f50163d1d772ac773f6d03ed049e4a0329674db9.tar.bz2
utf8_correctIdx bounds checking and more unittests
darcs-hash:20060827153254-9b6ab-3c76fde7cb5534ca12628e9aa6e6d59d9bb02f45.gz
Diffstat (limited to 'inc/utf8.php')
-rw-r--r--inc/utf8.php20
1 files changed, 12 insertions, 8 deletions
diff --git a/inc/utf8.php b/inc/utf8.php
index 0323bed4b..ef056bfa4 100644
--- a/inc/utf8.php
+++ b/inc/utf8.php
@@ -776,15 +776,19 @@ function utf8_bad_replace($str, $replace = '') {
* @author chris smith <chris@jalakai.co.uk>
*/
function utf8_correctIdx(&$str,$i,$next=false) {
-
+
+ if ($i <= 0) return 0;
+
+ $limit = strlen($str);
+ if ($i>=$limit) return $limit;
+
if ($next) {
- $limit = strlen($str);
- while (($i<$limit) && ((ord($str[$i]) & 0xC0) == 0x80)) $i++;
- } else {
- while ($i && ((ord($str[$i]) & 0xC0) == 0x80)) $i--;
- }
-
- return $i;
+ while (($i<$limit) && ((ord($str[$i]) & 0xC0) == 0x80)) $i++;
+ } else {
+ while ($i && ((ord($str[$i]) & 0xC0) == 0x80)) $i--;
+ }
+
+ return $i;
}
// only needed if no mb_string available