summaryrefslogtreecommitdiffstats
path: root/src/UtfString.php
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-07-16 16:45:04 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-07-16 16:45:04 +0300
commit9e3a9ee729eaada8585fa8f33ba7d8ac2231495a (patch)
tree430342d6b6d83dc8d89e5f55d6875451f687f0ee /src/UtfString.php
parent56ce2d7a37a1ed1d6aabf2b7908ae5da43863497 (diff)
downloadsql-parser-9e3a9ee729eaada8585fa8f33ba7d8ac2231495a.zip
sql-parser-9e3a9ee729eaada8585fa8f33ba7d8ac2231495a.tar.gz
sql-parser-9e3a9ee729eaada8585fa8f33ba7d8ac2231495a.tar.bz2
Fixed support for multi-byte strings.
Diffstat (limited to 'src/UtfString.php')
-rw-r--r--src/UtfString.php43
1 files changed, 6 insertions, 37 deletions
diff --git a/src/UtfString.php b/src/UtfString.php
index 27e3f93..1e863a4 100644
--- a/src/UtfString.php
+++ b/src/UtfString.php
@@ -93,7 +93,7 @@ class UtfString implements \ArrayAccess
*/
public function offsetExists($offset)
{
- return $offset < $this->charLen;
+ return ($offset >= 0) && ($offset < $this->charLen);
}
/**
@@ -190,26 +190,13 @@ class UtfString implements \ArrayAccess
return 3;
} elseif ($byte < 248) {
return 4;
- } elseif ($byte === 252) {
+ } elseif ($byte < 252) {
return 5; // unofficial
}
return 6; // unofficial
}
/**
- * Returns the number of remaining characters.
- *
- * @return int
- */
- public function remaining()
- {
- if ($this->charIdx < $this->charLen) {
- return $this->charLen - $this->charIdx;
- }
- return 0;
- }
-
- /**
* Returns the length in characters of the string.
*
* @return int
@@ -220,30 +207,12 @@ class UtfString implements \ArrayAccess
}
/**
- * Gets the values of the indexes.
- *
- * @param int &$byte Reference to the byte index.
- * @param int &$char Reference to the character index.
- *
- * @return void
- */
- public function getIndexes(&$byte, &$char)
- {
- $byte = $this->byteIdx;
- $char = $this->charIdx;
- }
-
- /**
- * Sets the values of the indexes.
+ * Returns the contained string.
*
- * @param int $byte The byte index.
- * @param int $char The character index.
- *
- * @return void
+ * @return strin
*/
- public function setIndexes($byte = 0, $char = 0)
+ public function __toString()
{
- $this->byteIdx = $byte;
- $this->charIdx = $char;
+ return $this->str;
}
}