xref: /dokuwiki/inc/Utf8/Table.php (revision d4f83172d9533c4d84f450fe22ef630816b21d75)
1*f41bbe4cSAndreas Gohr<?php
2*f41bbe4cSAndreas Gohr
3*f41bbe4cSAndreas Gohrnamespace dokuwiki\Utf8;
4*f41bbe4cSAndreas Gohr
5*f41bbe4cSAndreas Gohr/**
6*f41bbe4cSAndreas Gohr * Provides static access to the UTF-8 conversion tables
7*f41bbe4cSAndreas Gohr *
8*f41bbe4cSAndreas Gohr * Lazy-Loads tables on first access
9*f41bbe4cSAndreas Gohr */
10*f41bbe4cSAndreas Gohrclass Table
11*f41bbe4cSAndreas Gohr{
12*f41bbe4cSAndreas Gohr    /**
13*f41bbe4cSAndreas Gohr     * Get the upper to lower case conversion table
14*f41bbe4cSAndreas Gohr     *
15*f41bbe4cSAndreas Gohr     * @return array
16*f41bbe4cSAndreas Gohr     */
17*f41bbe4cSAndreas Gohr    public static function upperCaseToLowerCase()
18*f41bbe4cSAndreas Gohr    {
19*f41bbe4cSAndreas Gohr        static $table = null;
20*f41bbe4cSAndreas Gohr        if ($table === null) $table = include __DIR__ . '/tables/case.php';
21*f41bbe4cSAndreas Gohr        return $table;
22*f41bbe4cSAndreas Gohr    }
23*f41bbe4cSAndreas Gohr
24*f41bbe4cSAndreas Gohr    /**
25*f41bbe4cSAndreas Gohr     * Get the lower to upper case conversion table
26*f41bbe4cSAndreas Gohr     *
27*f41bbe4cSAndreas Gohr     * @return array
28*f41bbe4cSAndreas Gohr     */
29*f41bbe4cSAndreas Gohr    public static function lowerCaseToUpperCase()
30*f41bbe4cSAndreas Gohr    {
31*f41bbe4cSAndreas Gohr        static $table = null;
32*f41bbe4cSAndreas Gohr        if ($table === null) {
33*f41bbe4cSAndreas Gohr            $uclc = self::upperCaseToLowerCase();
34*f41bbe4cSAndreas Gohr            $table = array_flip($uclc);
35*f41bbe4cSAndreas Gohr        }
36*f41bbe4cSAndreas Gohr        return $table;
37*f41bbe4cSAndreas Gohr    }
38*f41bbe4cSAndreas Gohr
39*f41bbe4cSAndreas Gohr    /**
40*f41bbe4cSAndreas Gohr     * Get the lower case accent table
41*f41bbe4cSAndreas Gohr     * @return array
42*f41bbe4cSAndreas Gohr     */
43*f41bbe4cSAndreas Gohr    public static function lowerAccents()
44*f41bbe4cSAndreas Gohr    {
45*f41bbe4cSAndreas Gohr        static $table = null;
46*f41bbe4cSAndreas Gohr        if ($table === null) {
47*f41bbe4cSAndreas Gohr            $table = include __DIR__ . '/tables/loweraccents.php';
48*f41bbe4cSAndreas Gohr        }
49*f41bbe4cSAndreas Gohr        return $table;
50*f41bbe4cSAndreas Gohr    }
51*f41bbe4cSAndreas Gohr
52*f41bbe4cSAndreas Gohr    /**
53*f41bbe4cSAndreas Gohr     * Get the lower case accent table
54*f41bbe4cSAndreas Gohr     * @return array
55*f41bbe4cSAndreas Gohr     */
56*f41bbe4cSAndreas Gohr    public static function upperAccents()
57*f41bbe4cSAndreas Gohr    {
58*f41bbe4cSAndreas Gohr        static $table = null;
59*f41bbe4cSAndreas Gohr        if ($table === null) {
60*f41bbe4cSAndreas Gohr            $table = include __DIR__ . '/tables/upperaccents.php';
61*f41bbe4cSAndreas Gohr        }
62*f41bbe4cSAndreas Gohr        return $table;
63*f41bbe4cSAndreas Gohr    }
64*f41bbe4cSAndreas Gohr
65*f41bbe4cSAndreas Gohr    /**
66*f41bbe4cSAndreas Gohr     * Get the romanization table
67*f41bbe4cSAndreas Gohr     * @return array
68*f41bbe4cSAndreas Gohr     */
69*f41bbe4cSAndreas Gohr    public static function romanization()
70*f41bbe4cSAndreas Gohr    {
71*f41bbe4cSAndreas Gohr        static $table = null;
72*f41bbe4cSAndreas Gohr        if ($table === null) {
73*f41bbe4cSAndreas Gohr            $table = include __DIR__ . '/tables/romanization.php';
74*f41bbe4cSAndreas Gohr        }
75*f41bbe4cSAndreas Gohr        return $table;
76*f41bbe4cSAndreas Gohr    }
77*f41bbe4cSAndreas Gohr
78*f41bbe4cSAndreas Gohr    /**
79*f41bbe4cSAndreas Gohr     * Get the special chars as a concatenated string
80*f41bbe4cSAndreas Gohr     * @return string
81*f41bbe4cSAndreas Gohr     */
82*f41bbe4cSAndreas Gohr    public static function specialChars()
83*f41bbe4cSAndreas Gohr    {
84*f41bbe4cSAndreas Gohr        static $string = null;
85*f41bbe4cSAndreas Gohr        if ($string === null) {
86*f41bbe4cSAndreas Gohr            $table = include __DIR__ . '/tables/specials.php';
87*f41bbe4cSAndreas Gohr            // FIXME should we cache this to file system?
88*f41bbe4cSAndreas Gohr            $string = Unicode::toUtf8($table);
89*f41bbe4cSAndreas Gohr        }
90*f41bbe4cSAndreas Gohr        return $string;
91*f41bbe4cSAndreas Gohr    }
92*f41bbe4cSAndreas Gohr}
93