| 1 |
{- |
| 2 |
- Language/TEI/ToXML/ValidateChar.hs - validate character data |
| 3 |
- |
| 4 |
- Copyright 2020 Einhard Leichtfuß |
| 5 |
- |
| 6 |
- This file is part of ding2tei-haskell. |
| 7 |
- |
| 8 |
- ding2tei-haskell is free software: you can redistribute it and/or modify |
| 9 |
- it under the terms of the GNU Affero General Public License as published |
| 10 |
- by the Free Software Foundation, either version 3 of the License, or |
| 11 |
- (at your option) any later version. |
| 12 |
- |
| 13 |
- ding2tei-haskell is distributed in the hope that it will be useful, |
| 14 |
- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
- GNU Affero General Public License for more details. |
| 17 |
- |
| 18 |
- You should have received a copy of the GNU Affero General Public License |
| 19 |
- along with ding2tei-haskell. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
-} |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
module Language.TEI.ToXML.ValidateChar |
| 28 |
( validateString |
| 29 |
, validateChar |
| 30 |
) where |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
validateString :: String -> String |
| 37 |
validateString = map validateChar |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
validateChar :: Char -> Char |
| 43 |
validateChar c = |
| 44 |
if c `elem` "\x9\xA\xD" |
| 45 |
|| '\x20' <= c && c <= '\xD7FF' |
| 46 |
|| '\xE000' <= c && c <= '\xFFFD' |
| 47 |
|| '\x10000' <= c && c <= '\x10FFFF' |
| 48 |
then c |
| 49 |
else error $ "Invalid character in input: " ++ show c |
| 50 |
|
| 51 |
|
| 52 |
-- vi: ft=haskell ts=2 sw=2 et |