summaryrefslogtreecommitdiff
path: root/inc/utf8.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/utf8.php')
-rw-r--r--inc/utf8.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/inc/utf8.php b/inc/utf8.php
index 16722ab2e..0323bed4b 100644
--- a/inc/utf8.php
+++ b/inc/utf8.php
@@ -762,6 +762,31 @@ function utf8_bad_replace($str, $replace = '') {
return $result;
}
+/**
+ * adjust a byte index into a utf8 string to a utf8 character boundary
+ *
+ * @param $str string utf8 character string
+ * @param $i int byte index into $str
+ * @param $next bool direction to search for boundary,
+ * false = up (current character)
+ * true = down (next character)
+ *
+ * @return int byte index into $str now pointing to a utf8 character boundary
+ *
+ * @author chris smith <chris@jalakai.co.uk>
+ */
+function utf8_correctIdx(&$str,$i,$next=false) {
+
+ 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;
+}
+
// only needed if no mb_string available
if(!UTF8_MBSTRING){