Back to index

lightning-sunbird  0.9+nobinonly
morkCh.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-  */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037  
00038 #ifndef _MORKCH_
00039 #define _MORKCH_ 1
00040 
00041 #ifndef _MORK_
00042 #include "mork.h"
00043 #endif
00044 
00045 /* this byte char predicate header file derives from public domain Mithril */
00046 /* (that means much of this has a copyright dedicated to the public domain) */
00047 
00048 /* Use all 8 pred bits; lose some pred bits only if we need to reuse them. */
00049 
00050 /* ch pred bits: W:white D:digit V:value U:upper L:lower N:name  M:more */
00051 #define morkCh_kW      (1 << 0)
00052 #define morkCh_kD      (1 << 1)
00053 #define morkCh_kV      (1 << 2)
00054 #define morkCh_kU      (1 << 3)
00055 #define morkCh_kL      (1 << 4)
00056 #define morkCh_kX      (1 << 5)
00057 #define morkCh_kN      (1 << 6)
00058 #define morkCh_kM      (1 << 7)
00059 
00060 extern const mork_flags morkCh_Type[]; /* 256 byte predicate bits ch map */
00061 
00062 /* is a numeric decimal digit: (note memory access might be slower) */
00063 /* define morkCh_IsDigit(c)  ( morkCh_Type[ (mork_ch)(c) ] & morkCh_kD ) */
00064 #define morkCh_IsDigit(c)    ( ((mork_ch) c) >= '0' && ((mork_ch) c) <= '9' )
00065 
00066 /* is a numeric octal digit: */
00067 #define morkCh_IsOctal(c)    ( ((mork_ch) c) >= '0' && ((mork_ch) c) <= '7' )
00068 
00069 /* is a numeric hexadecimal digit: */
00070 #define morkCh_IsHex(c) ( morkCh_Type[ (mork_ch)(c) ] & morkCh_kX )
00071 
00072 /* is value (can be printed in Mork value without needing hex or escape): */
00073 #define morkCh_IsValue(c)    ( morkCh_Type[ (mork_ch)(c) ] & morkCh_kV )
00074 
00075 /* is white space : */
00076 #define morkCh_IsWhite(c)    ( morkCh_Type[ (mork_ch)(c) ] & morkCh_kW )
00077 
00078 /* is name (can start a Mork name): */
00079 #define morkCh_IsName(c)     ( morkCh_Type[ (mork_ch)(c) ] & morkCh_kN )
00080 
00081 /* is name (can continue a Mork name): */
00082 #define morkCh_IsMore(c) ( morkCh_Type[ (mork_ch)(c) ] & morkCh_kM )
00083 
00084 /* is alphabetic upper or lower case */
00085 #define morkCh_IsAlpha(c)    \
00086   ( morkCh_Type[ (mork_ch)(c) ] & (morkCh_kL|morkCh_kU) )
00087 
00088 /* is alphanumeric, including lower case, upper case, and digits */
00089 #define morkCh_IsAlphaNum(c) \
00090   (morkCh_Type[ (mork_ch)(c) ]&(morkCh_kL|morkCh_kU|morkCh_kD))
00091 
00092 /* ````` repeated testing of predicate bits in single flag byte ````` */
00093 
00094 #define morkCh_GetFlags(c) ( morkCh_Type[ (mork_ch)(c) ] )
00095 
00096 #define morkFlags_IsDigit(f)    ( (f) & morkCh_kD )
00097 #define morkFlags_IsHex(f)      ( (f) & morkCh_kX )
00098 #define morkFlags_IsValue(f)    ( (f) & morkCh_kV )
00099 #define morkFlags_IsWhite(f)    ( (f) & morkCh_kW )
00100 #define morkFlags_IsName(f)     ( (f) & morkCh_kN )
00101 #define morkFlags_IsMore(f)     ( (f) & morkCh_kM )
00102 #define morkFlags_IsAlpha(f)    ( (f) & (morkCh_kL|morkCh_kU) )
00103 #define morkFlags_IsAlphaNum(f) ( (f) & (morkCh_kL|morkCh_kU|morkCh_kD) )
00104 
00105 #define morkFlags_IsUpper(f)    ( (f) & morkCh_kU )
00106 #define morkFlags_IsLower(f)    ( (f) & morkCh_kL )
00107 
00108 /* ````` character case (e.g. for case insensitive operations) ````` */
00109 
00110   
00111 #define morkCh_IsAscii(c)         ( ((mork_u1) c) <= 0x7F )
00112 #define morkCh_IsSevenBitChar(c)  ( ((mork_u1) c) <= 0x7F )
00113 
00114 /* ````` character case (e.g. for case insensitive operations) ````` */
00115 
00116 #define morkCh_ToLower(c)    ((c)-'A'+'a')
00117 #define morkCh_ToUpper(c)    ((c)-'a'+'A')
00118 
00119 /* extern int morkCh_IsUpper (int c); */
00120 #define morkCh_IsUpper(c)    ( morkCh_Type[ (mork_ch)(c) ] & morkCh_kU )
00121 
00122 /* extern int morkCh_IsLower (int c); */
00123 #define morkCh_IsLower(c)    ( morkCh_Type[ (mork_ch)(c) ] & morkCh_kL )
00124 
00125 #endif
00126 /* _MORKCH_ */