1 | /* |
2 | * This file is part of the KDE libraries |
3 | * Copyright (C) 2003 Apple Computer, Inc. |
4 | * Copyright (C) 2012 Bernd Buschinski (b.buschinski@googlemail.com) |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public License |
17 | * along with this library; see the file COPYING.LIB. If not, write to |
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | * Boston, MA 02110-1301, USA. |
20 | * |
21 | */ |
22 | |
23 | #ifndef COMMONUNICODE_H_ |
24 | #define COMMONUNICODE_H_ |
25 | |
26 | namespace KJS { |
27 | namespace CommonUnicode { |
28 | |
29 | inline bool isLineTerminator(unsigned short c) |
30 | { |
31 | switch (c) { |
32 | case 0x000A: // LINE FEED |
33 | case 0x000D: // CARRIAGE RETURN |
34 | case 0x2028: // LINE SEPARATOR |
35 | case 0x2029: // PARAGRAPH SEPARATOR |
36 | return true; |
37 | default: |
38 | return false; |
39 | } |
40 | } |
41 | |
42 | inline bool isWhiteSpace(unsigned short c) |
43 | { |
44 | switch (c) { |
45 | case 0x0009: |
46 | case 0x000B: |
47 | case 0x000C: |
48 | // Unicode category Zs |
49 | case 0x0020: // SPACE |
50 | case 0x00A0: // NO-BREAK SPACE |
51 | case 0x1680: // OGHAM SPACE MARK |
52 | case 0x180E: // MONGOLIAN VOWEL SEPARATOR |
53 | case 0x2000: // EN QUAD |
54 | case 0x2001: // EM QUAD |
55 | case 0x2002: // EN SPACE |
56 | case 0x2003: // EM SPACE |
57 | case 0x2004: // THREE-PER-EM SPACE |
58 | case 0x2005: // FOUR-PER-EM SPACE |
59 | case 0x2006: // SIX-PER-EM SPACE |
60 | case 0x2007: // FIGURE SPACE |
61 | case 0x2008: // PUNCTUATION SPACE |
62 | case 0x2009: // THIN SPACE |
63 | case 0x200A: // HAIR SPACE |
64 | case 0x202F: // NARROW NO-BREAK SPACE |
65 | case 0x205F: // MEDIUM MATHEMATICAL SPACE |
66 | case 0x3000: // IDEOGRAPHIC SPACE |
67 | // Unicode Byte-Order-Mark, Ecmascript 5.1r6 - 7.2 |
68 | case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE, BOM |
69 | return true; |
70 | default: |
71 | return false; |
72 | } |
73 | } |
74 | |
75 | inline bool isStrWhiteSpace(unsigned short c) |
76 | { |
77 | return isWhiteSpace(c) || isLineTerminator(c); |
78 | } |
79 | |
80 | } //namespace CommonUnicode |
81 | } //namespace KJS |
82 | |
83 | #endif //COMMONUNICODE_H_ |
84 | |