Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
NagTable | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
replaceNag | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This file is a part of ChessBrowser. |
4 | * |
5 | * ChessBrowser is free software: you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation, either version 3 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
17 | * |
18 | * @file NagTable |
19 | * @ingroup ChessBrowser |
20 | * @author Wugapodes |
21 | */ |
22 | |
23 | namespace MediaWiki\Extension\ChessBrowser; |
24 | |
25 | class NagTable { |
26 | // phpcs:disable MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment |
27 | public const MAP = [ |
28 | '$1' => "!", // U+0021 |
29 | '$2' => "?", // U+003F |
30 | '$3' => "‼", // U+203C |
31 | '$4' => "⁇", // U+2047 |
32 | '$5' => "⁉", // U+2049 |
33 | '$6' => "⁈", // U+2048 |
34 | '$7' => "□", // U+25A1 |
35 | '$10' => "=", // U+003D |
36 | '$13' => "∞", // U+221E |
37 | '$14' => "⩲", // U+2A72 |
38 | '$15' => "⩱", // U+2A71 |
39 | '$16' => "±", // U+00B1 |
40 | '$17' => "∓", // U+2213 |
41 | '$18' => "+−", // U+002B U+002D |
42 | '$19' => "−+", // U+002D U+002B |
43 | '$22' => "⨀", // U+2A00 |
44 | '$23' => "⨀", // U+2A00 |
45 | '$26' => "○", // U+25CB |
46 | '$27' => "○", // U+25CB |
47 | '$32' => "⟳", // U+27F3 |
48 | '$33' => "⟳", // U+27F3 |
49 | '$36' => "↑", // U+2191 |
50 | '$37' => "↑", // U+2191 |
51 | '$40' => "→", // U+2192 |
52 | '$41' => "→", // U+2192 |
53 | '$45' => "=/∞", // U+2A73 (roughly) |
54 | '$46' => "=/∞", // U+2A73 (roughly) |
55 | '$132' => "⇆", // U+21C6 |
56 | '$133' => "⇆", // U+21C6 |
57 | '$138' => "⨁", // U+2A01 |
58 | '$139' => "⨁", // U+2A01 |
59 | /* The following are non-standard */ |
60 | '$140' => "∆", // U+2206 |
61 | '$141' => "∇", // U+2207 |
62 | '$142' => "⌓", // U+2313 |
63 | '$143' => "<=", // ?? |
64 | '$144' => "==", // U+003D U+003D |
65 | '$145' => "RR", // ?? |
66 | '$146' => "N", // ?? |
67 | '$238' => "○", // U+25CB |
68 | '$239' => "⇔", // U+21D4 |
69 | '$240' => "⇗", // U+21D7 |
70 | '$241' => "⊞", // U+229E |
71 | '$242' => "⟫", // U+27EB |
72 | '$243' => "⟪", // U+27EA |
73 | '$244' => "✕", // U+2715 |
74 | '$245' => "⊥", // U+22A5 |
75 | ]; |
76 | |
77 | /** |
78 | * Replace NAGs in the PGN with their unicode equivalent. |
79 | * |
80 | * @param string $pgn The PGN to be replaced. |
81 | * @return string |
82 | */ |
83 | public static function replaceNag( string $pgn ): string { |
84 | // Replacement respects array order, but an ascending |
85 | // list is easier for humans to read and maintain so |
86 | // the NagTable::MAP is reversed before replacement. |
87 | $nags = array_keys( array_reverse( self::MAP ) ); |
88 | $symbols = array_values( array_reverse( self::MAP ) ); |
89 | return str_replace( $nags, $symbols, $pgn ); |
90 | } |
91 | } |