• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

WTF

ASCIICType.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1.  Redistributions of source code must retain the above copyright
00009  *     notice, this list of conditions and the following disclaimer. 
00010  * 2.  Redistributions in binary form must reproduce the above copyright
00011  *     notice, this list of conditions and the following disclaimer in the
00012  *     documentation and/or other materials provided with the distribution. 
00013  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
00014  *     its contributors may be used to endorse or promote products derived
00015  *     from this software without specific prior written permission. 
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
00018  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
00021  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #ifndef WTF_ASCIICType_h
00030 #define WTF_ASCIICType_h
00031 
00032 #include <wtf/Platform.h>
00033 #include <wtf/Assertions.h>
00034 
00035 // The behavior of many of the functions in the <ctype.h> header is dependent
00036 // on the current locale. But in the WebKit project, all uses of those functions
00037 // are in code processing something that's not locale-specific. These equivalents
00038 // for some of the <ctype.h> functions are named more explicitly, not dependent
00039 // on the C library locale, and we should also optimize them as needed.
00040 
00041 // All functions return false or leave the character unchanged if passed a character
00042 // that is outside the range 0-7F. So they can be used on Unicode strings or
00043 // characters if the intent is to do processing only if the character is ASCII.
00044 
00045 namespace WTF {
00046 
00047     inline bool isASCIIAlpha(char c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
00048     inline bool isASCIIAlpha(unsigned short c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
00049 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00050     inline bool isASCIIAlpha(wchar_t c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
00051 #endif
00052     inline bool isASCIIAlpha(int c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
00053 
00054     inline bool isASCIIAlphanumeric(char c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
00055     inline bool isASCIIAlphanumeric(unsigned short c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
00056 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00057     inline bool isASCIIAlphanumeric(wchar_t c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
00058 #endif
00059     inline bool isASCIIAlphanumeric(int c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
00060 
00061     inline bool isASCIIDigit(char c) { return (c >= '0') & (c <= '9'); }
00062     inline bool isASCIIDigit(unsigned short c) { return (c >= '0') & (c <= '9'); }
00063 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00064     inline bool isASCIIDigit(wchar_t c) { return (c >= '0') & (c <= '9'); }
00065 #endif
00066     inline bool isASCIIDigit(int c) { return (c >= '0') & (c <= '9'); }
00067 
00068     inline bool isASCIIHexDigit(char c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
00069     inline bool isASCIIHexDigit(unsigned short c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
00070 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00071     inline bool isASCIIHexDigit(wchar_t c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
00072 #endif
00073     inline bool isASCIIHexDigit(int c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
00074 
00075     inline bool isASCIILower(char c) { return c >= 'a' && c <= 'z'; }
00076     inline bool isASCIILower(unsigned short c) { return c >= 'a' && c <= 'z'; }
00077 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00078     inline bool isASCIILower(wchar_t c) { return c >= 'a' && c <= 'z'; }
00079 #endif
00080     inline bool isASCIILower(int c) { return c >= 'a' && c <= 'z'; }
00081 
00082     inline bool isASCIIUpper(char c) { return c >= 'A' && c <= 'Z'; }
00083     inline bool isASCIIUpper(unsigned short c) { return c >= 'A' && c <= 'Z'; }
00084 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00085     inline bool isASCIIUpper(wchar_t c) { return c >= 'A' && c <= 'Z'; }
00086 #endif
00087     inline bool isASCIIUpper(int c) { return c >= 'A' && c <= 'Z'; }
00088 
00089     /*
00090         Statistics from a run of Apple's page load test for callers of isASCIISpace:
00091 
00092             character          count
00093             ---------          -----
00094             non-spaces         689383
00095         20  space              294720
00096         0A  \n                 89059
00097         09  \t                 28320
00098         0D  \r                 0
00099         0C  \f                 0
00100         0B  \v                 0
00101     */
00102     inline bool isASCIISpace(char c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
00103     inline bool isASCIISpace(unsigned short c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
00104 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00105     inline bool isASCIISpace(wchar_t c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
00106 #endif
00107     inline bool isASCIISpace(int c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
00108 
00109     inline char toASCIILower(char c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
00110     inline unsigned short toASCIILower(unsigned short c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
00111 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00112     inline wchar_t toASCIILower(wchar_t c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
00113 #endif
00114     inline int toASCIILower(int c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
00115 
00116     inline char toASCIIUpper(char c) { return static_cast<char>(c & ~((c >= 'a' && c <= 'z') << 5)); }
00117     inline unsigned short toASCIIUpper(unsigned short c) { return static_cast<unsigned short>(c & ~((c >= 'a' && c <= 'z') << 5)); }
00118 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00119     inline wchar_t toASCIIUpper(wchar_t c) { return static_cast<wchar_t>(c & ~((c >= 'a' && c <= 'z') << 5)); }
00120 #endif
00121     inline int toASCIIUpper(int c) { return static_cast<int>(c & ~((c >= 'a' && c <= 'z') << 5)); }
00122 
00123     inline int toASCIIHexValue(char c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
00124     inline int toASCIIHexValue(unsigned short c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
00125 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00126     inline int toASCIIHexValue(wchar_t c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
00127 #endif
00128     inline int toASCIIHexValue(int c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
00129 
00130 }
00131 
00132 #endif

WTF

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal