-
Notifications
You must be signed in to change notification settings - Fork 5
/
text.php
49 lines (40 loc) · 1.74 KB
/
text.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
48
49
<?php
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
require_once './yoficator/ReflectionTypeHint.php';
require_once './yoficator/UTF8.php';
require_once './yoficator/Text/Yoficator.php';
$yoficator = null;
function yof($s) {
global $yoficator;
if ($yoficator === null) $yoficator = new Text_Yoficator();
return $yoficator->parse($s);
}
function tf($s) {
$s = preg_replace('/^-(?= )|(?<= )-(?= )|---/', '—', $s); // em dash is "---" or " - "
$s = preg_replace('/--/', '–', $s); // en dash is "--"
$s = preg_replace('/(?:(?<=\D\d\d\d\d)|(?<=^\d\d\d\d))-(?:(?=\d\d\d\d\D)|(?=\d\d\d\d$))/', '–', $s); // en dash in year ranges, like "1941-1945"
$s = preg_replace('/(?:^|(?<=(?:\d|\s)))-(?=\d)/', "−", $s); // minus in negative numbers like "-2" and math expressions like "24-11=13"
$s = preg_replace('/(?:"|\"\;)(?=[a-zA-Zа-яА-ЯйЙёЁру0-9])/', '«', $s);
$s = preg_replace('/(?<=[a-zA-Zа-яА-ЯйЙёЁру0-9])(?:"|\"\;)/', '»', $s);
return $s;
}
function nl2p($s) {
$ar = explode("\n\n", $s);
for ($s='', $i=0; $i<count($ar); $s.='<p>'.$ar[$i].'</p>', $i++);
return $s;
}
?>