Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
StringNormalizer
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 normalize
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Cognate;
4
5/**
6 * BIG WARNING!!!!!   L(・o・)」
7 * Any changes in this class that result in different normalizations will require the
8 * cognate_titles table to be rebuilt.
9 *
10 * @license GPL-2.0-or-later
11 * @author Addshore
12 */
13class StringNormalizer {
14
15    /**
16     * @var string[]
17     */
18    private $replacements = [
19        // U+02BC and U+2019 normalized to U+0027
20        'ʼ' => '\'',
21        '’' => '\'',
22        // U+2026 normalized to U+002EU+002EU+002E
23        '…' => '...',
24        // U+0020 normalized to U+005F
25        ' ' => '_',
26    ];
27
28    /**
29     * @param string $string
30     *
31     * @return string
32     */
33    public function normalize( $string ) {
34        return str_replace(
35            array_keys( $this->replacements ),
36            array_values( $this->replacements ),
37            $string
38        );
39    }
40
41}