GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — sql-parser/src/UtfString.php at master · phpmyadmin/sql-parser Expand file tree/ Copy pathUtfString.phpMore file actions 116 lines (103 loc) · 2.71 KB / Copy pathUtfString.phpFile metadata and controls116 lines (103 loc) · 2.71 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 <?php declare(strict_types=1); namespace PhpMyAdmin\SqlParser; use ArrayAccess; use Exception; use JsonSerializable; use Stringable; use function count; use function implode; use function mb_check_encoding; use function mb_str_split; /** * Implementation for UTF-8 strings. * * The subscript operator in PHP, when used with string will return a byte and not a character. Because in UTF-8 * strings a character may occupy more than one byte, the subscript operator may return an invalid character. * * Because the lexer relies on the subscript operator this class had to be implemented. * * Implements array-like access for UTF-8 strings. * * In this library, this class should be used to parse UTF-8 queries. * * @implements ArrayAccess<int, string> */ class UtfString implements ArrayAccess, Stringable, JsonSerializable { /** * The multi-byte characters. * * @var list<string> */ public array $characters; /** @param string $str the string */ public function __construct(string $str) { if (mb_check_encoding($str, 'UTF-8')) { $this->characters = mb_str_split($str, 1, 'UTF-8'); } else { $this->characters = []; } } /** * Checks if the given offset exists. * * @param int $offset the offset to be checked */ public function offsetExists(mixed $offset): bool { return $offset >= 0 && $offset < count($this->characters); } /** * Gets the character at given offset. * * @param int $offset the offset to be returned */ public function offsetGet(mixed $offset): string { return $this->characters[$offset] ?? ''; } /** * Sets the value of a character. * * @param int $offset the offset to be set * @param string $value the value to be set * * @throws Exception not implemented. */ public function offsetSet(mixed $offset, mixed $value): void { throw new Exception('Not implemented.'); } /** * Unsets an index. * * @param int $offset the value to be unset * * @throws Exception not implemented. */ public function offsetUnset(mixed $offset): void { throw new Exception('Not implemented.'); } /** * Returns the length in characters of the string. */ public function length(): int { return count($this->characters); } /** * Returns the contained string. */ public function __toString(): string { return implode('', $this->characters); } /** @return array<mixed> */ public function jsonSerialize(): array { return ['@type' => static::class, 'str' => (string) $this]; } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |