-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLetter.php
47 lines (38 loc) · 1.62 KB
/
Letter.php
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
<?php
namespace Tsuruya;
class Letter {
private string $char;
private string $translit;
private string $locale;
private int $bytes;
private int $bytesTranslit;
private int $index;
private int $pos;
private int $posTranslit;
public function __construct(string $char, string $locale, int $index, int $precPos = 0, int $precPosT = 0) {
$this->char = $char;
$this->locale = $locale;
$oldLocale = setlocale(LC_ALL,"0");
setlocale(LC_ALL, $this->locale);
$tmp = str_replace('€', '&#@EUR@#&', $char);
$tmp = iconv('UTF-8','ASCII//TRANSLIT', $tmp);
$tmp = str_replace('&#@EUR@#&', '€', $tmp);
$this->translit = $tmp;
setlocale(LC_ALL, $oldLocale);
$ord = ord($this->char);
$this->bytes = $ord < 128 ? 1 : ($ord < 224 ? 2 : ($ord < 240 ? 3 : 4));
$ord = ord($this->translit);
$this->bytesTranslit = $ord < 128 ? 1 : ($ord < 224 ? 2 : ($ord < 240 ? 3 : 4));
$this->index = $index;
$this->pos = $this->index == 0 ? 0 : ($this->bytes + $precPos);
$this->posTranslit = $this->index == 0 ? 0 : ($this->bytesTranslit + $precPosT);
}
public function get(bool $translit = false) { return $translit ? $this->translit : $this->char; }
public function getChar() { return $this->get(false); }
public function getTranslit() { return $this->get(true); }
public function getIndex() { return $this->index; }
public function getPos() { return $this->pos; }
public function getPosT() { return $this->posTranslit; }
public function getBytes() { return $this->bytes; }
}
?>