File indexing completed on 2024-05-12 15:43:16

0001 /*
0002  *  This file is part of the KDE libraries
0003  *  Copyright (C) 2003 Apple Computer, Inc.
0004  *  Copyright (C) 2012 Bernd Buschinski (b.buschinski@googlemail.com)
0005  *
0006  *  This library is free software; you can redistribute it and/or
0007  *  modify it under the terms of the GNU Library General Public
0008  *  License as published by the Free Software Foundation; either
0009  *  version 2 of the License, or (at your option) any later version.
0010  *
0011  *  This library is distributed in the hope that it will be useful,
0012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  *  Library General Public License for more details.
0015  *
0016  *  You should have received a copy of the GNU Library General Public License
0017  *  along with this library; see the file COPYING.LIB.  If not, write to
0018  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  *  Boston, MA 02110-1301, USA.
0020  *
0021  */
0022 
0023 #ifndef COMMONUNICODE_H_
0024 #define COMMONUNICODE_H_
0025 
0026 namespace KJS
0027 {
0028 namespace CommonUnicode
0029 {
0030 
0031 inline bool isLineTerminator(unsigned short c)
0032 {
0033     switch (c) {
0034     case 0x000A:  // LINE FEED
0035     case 0x000D:  // CARRIAGE RETURN
0036     case 0x2028:  // LINE SEPARATOR
0037     case 0x2029:  // PARAGRAPH SEPARATOR
0038         return true;
0039     default:
0040         return false;
0041     }
0042 }
0043 
0044 inline bool isWhiteSpace(unsigned short c)
0045 {
0046     switch (c) {
0047     case 0x0009:
0048     case 0x000B:
0049     case 0x000C:
0050     // Unicode category Zs
0051     case 0x0020:  // SPACE
0052     case 0x00A0:  // NO-BREAK SPACE
0053     case 0x1680:  // OGHAM SPACE MARK
0054     case 0x180E:  // MONGOLIAN VOWEL SEPARATOR
0055     case 0x2000:  // EN QUAD
0056     case 0x2001:  // EM QUAD
0057     case 0x2002:  // EN SPACE
0058     case 0x2003:  // EM SPACE
0059     case 0x2004:  // THREE-PER-EM SPACE
0060     case 0x2005:  // FOUR-PER-EM SPACE
0061     case 0x2006:  // SIX-PER-EM SPACE
0062     case 0x2007:  // FIGURE SPACE
0063     case 0x2008:  // PUNCTUATION SPACE
0064     case 0x2009:  // THIN SPACE
0065     case 0x200A:  // HAIR SPACE
0066     case 0x202F:  // NARROW NO-BREAK SPACE
0067     case 0x205F:  // MEDIUM MATHEMATICAL SPACE
0068     case 0x3000:  // IDEOGRAPHIC SPACE
0069     // Unicode Byte-Order-Mark, Ecmascript 5.1r6 - 7.2
0070     case 0xFEFF:  // ZERO WIDTH NO-BREAK SPACE, BOM
0071         return true;
0072     default:
0073         return false;
0074     }
0075 }
0076 
0077 inline bool isStrWhiteSpace(unsigned short c)
0078 {
0079     return isWhiteSpace(c) || isLineTerminator(c);
0080 }
0081 
0082 } //namespace CommonUnicode
0083 } //namespace KJS
0084 
0085 #endif //COMMONUNICODE_H_