-
Notifications
You must be signed in to change notification settings - Fork 0
/
Diacritic.php
40 lines (33 loc) · 938 Bytes
/
Diacritic.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
<?php
/**
* @package go\ewp
*/
namespace go\ewp;
/**
* Convert diacritic to plain latin and vice versa
*
* @author Oleg Grigoriev <go.vasac@gmail.com>
*/
class Diacritic
{
/**
* @param string $text
* @return string
*/
public static function diacritic2latin($text)
{
return \strtolower(\str_replace(self::$rds, self::$rdr, $text));
}
/**
* @param string $text
* @return string
*/
public static function latin2diacritic($text)
{
return \str_replace(self::$rls, self::$rlr, $text);
}
private static $rds = ['Ĉ', 'Ĝ', 'Ĥ', 'Ĵ', 'Ŝ', 'Ŭ', 'ĉ', 'ĝ', 'ĥ', 'ĵ', 'ŝ', 'ŭ', 'U~', 'u~'];
private static $rdr = ['cx', 'gx', 'hx', 'jx', 'sx', 'ux', 'cx', 'gx', 'hx', 'jx', 'sx', 'ux', 'Ux', 'ux'];
private static $rls = ['cx', 'gx', 'hx', 'jx', 'sx', 'ux', 'u~'];
private static $rlr = ['ĉ', 'ĝ', 'ĥ', 'ĵ', 'ŝ', 'ŭ', 'ŭ'];
}