• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

WTF

  • kjs
  • wtf
ASCIICType.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef WTF_ASCIICType_h
30#define WTF_ASCIICType_h
31
32#include <wtf/Platform.h>
33#include <wtf/Assertions.h>
34
35// The behavior of many of the functions in the <ctype.h> header is dependent
36// on the current locale. But in the WebKit project, all uses of those functions
37// are in code processing something that's not locale-specific. These equivalents
38// for some of the <ctype.h> functions are named more explicitly, not dependent
39// on the C library locale, and we should also optimize them as needed.
40
41// All functions return false or leave the character unchanged if passed a character
42// that is outside the range 0-7F. So they can be used on Unicode strings or
43// characters if the intent is to do processing only if the character is ASCII.
44
45namespace WTF {
46
47 inline bool isASCIIAlpha(char c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
48 inline bool isASCIIAlpha(unsigned short c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
49#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
50 inline bool isASCIIAlpha(wchar_t c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
51#endif
52 inline bool isASCIIAlpha(int c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
53
54 inline bool isASCIIAlphanumeric(char c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
55 inline bool isASCIIAlphanumeric(unsigned short c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
56#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
57 inline bool isASCIIAlphanumeric(wchar_t c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
58#endif
59 inline bool isASCIIAlphanumeric(int c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
60
61 inline bool isASCIIDigit(char c) { return (c >= '0') & (c <= '9'); }
62 inline bool isASCIIDigit(unsigned short c) { return (c >= '0') & (c <= '9'); }
63#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
64 inline bool isASCIIDigit(wchar_t c) { return (c >= '0') & (c <= '9'); }
65#endif
66 inline bool isASCIIDigit(int c) { return (c >= '0') & (c <= '9'); }
67
68 inline bool isASCIIHexDigit(char c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
69 inline bool isASCIIHexDigit(unsigned short c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
70#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
71 inline bool isASCIIHexDigit(wchar_t c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
72#endif
73 inline bool isASCIIHexDigit(int c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
74
75 inline bool isASCIILower(char c) { return c >= 'a' && c <= 'z'; }
76 inline bool isASCIILower(unsigned short c) { return c >= 'a' && c <= 'z'; }
77#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
78 inline bool isASCIILower(wchar_t c) { return c >= 'a' && c <= 'z'; }
79#endif
80 inline bool isASCIILower(int c) { return c >= 'a' && c <= 'z'; }
81
82 inline bool isASCIIUpper(char c) { return c >= 'A' && c <= 'Z'; }
83 inline bool isASCIIUpper(unsigned short c) { return c >= 'A' && c <= 'Z'; }
84#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
85 inline bool isASCIIUpper(wchar_t c) { return c >= 'A' && c <= 'Z'; }
86#endif
87 inline bool isASCIIUpper(int c) { return c >= 'A' && c <= 'Z'; }
88
89 /*
90 Statistics from a run of Apple's page load test for callers of isASCIISpace:
91
92 character count
93 --------- -----
94 non-spaces 689383
95 20 space 294720
96 0A \n 89059
97 09 \t 28320
98 0D \r 0
99 0C \f 0
100 0B \v 0
101 */
102 inline bool isASCIISpace(char c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
103 inline bool isASCIISpace(unsigned short c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
104#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
105 inline bool isASCIISpace(wchar_t c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
106#endif
107 inline bool isASCIISpace(int c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
108
109 inline char toASCIILower(char c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
110 inline unsigned short toASCIILower(unsigned short c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
111#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
112 inline wchar_t toASCIILower(wchar_t c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
113#endif
114 inline int toASCIILower(int c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
115
116 inline char toASCIIUpper(char c) { return static_cast<char>(c & ~((c >= 'a' && c <= 'z') << 5)); }
117 inline unsigned short toASCIIUpper(unsigned short c) { return static_cast<unsigned short>(c & ~((c >= 'a' && c <= 'z') << 5)); }
118#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
119 inline wchar_t toASCIIUpper(wchar_t c) { return static_cast<wchar_t>(c & ~((c >= 'a' && c <= 'z') << 5)); }
120#endif
121 inline int toASCIIUpper(int c) { return static_cast<int>(c & ~((c >= 'a' && c <= 'z') << 5)); }
122
123 inline int toASCIIHexValue(char c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
124 inline int toASCIIHexValue(unsigned short c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
125#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
126 inline int toASCIIHexValue(wchar_t c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
127#endif
128 inline int toASCIIHexValue(int c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
129
130}
131
132#endif
Assertions.h
ASSERT
#define ASSERT(x)
Definition: Assertions.h:33
Platform.h
WTF
Definition: ASCIICType.h:45
WTF::isASCIISpace
bool isASCIISpace(char c)
Definition: ASCIICType.h:102
WTF::toASCIILower
char toASCIILower(char c)
Definition: ASCIICType.h:109
WTF::isASCIILower
bool isASCIILower(char c)
Definition: ASCIICType.h:75
WTF::isASCIIUpper
bool isASCIIUpper(char c)
Definition: ASCIICType.h:82
WTF::toASCIIHexValue
int toASCIIHexValue(char c)
Definition: ASCIICType.h:123
WTF::isASCIIAlpha
bool isASCIIAlpha(char c)
Definition: ASCIICType.h:47
WTF::isASCIIAlphanumeric
bool isASCIIAlphanumeric(char c)
Definition: ASCIICType.h:54
WTF::isASCIIHexDigit
bool isASCIIHexDigit(char c)
Definition: ASCIICType.h:68
WTF::toASCIIUpper
char toASCIIUpper(char c)
Definition: ASCIICType.h:116
WTF::isASCIIDigit
bool isASCIIDigit(char c)
Definition: ASCIICType.h:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

WTF

Skip menu "WTF"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal