1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* ***** BEGIN LICENSE BLOCK ***** 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 4 * 5 * The contents of this file are subject to the Mozilla Public License Version 6 * 1.1 (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * http://www.mozilla.org/MPL/ 9 * 10 * Software distributed under the License is distributed on an "AS IS" basis, 11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 12 * for the specific language governing rights and limitations under the 13 * License. 14 * 15 * The Original Code is mozilla.org code. 16 * 17 * The Initial Developer of the Original Code is 18 * Netscape Communications Corporation. 19 * Portions created by the Initial Developer are Copyright (C) 1999 20 * the Initial Developer. All Rights Reserved. 21 * 22 * Contributor(s): 23 * 24 * Alternatively, the contents of this file may be used under the terms of 25 * either of the GNU General Public License Version 2 or later (the "GPL"), 26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 27 * in which case the provisions of the GPL or the LGPL are applicable instead 28 * of those above. If you wish to allow use of your version of this file only 29 * under the terms of either the GPL or the LGPL, and not to allow others to 30 * use your version of this file under the terms of the MPL, indicate your 31 * decision by deleting the provisions above and replace them with the notice 32 * and other provisions required by the GPL or the LGPL. If you do not delete 33 * the provisions above, a recipient may use your version of this file under 34 * the terms of any one of the MPL, the GPL or the LGPL. 35 * 36 * ***** END LICENSE BLOCK ***** */ 37 38 #ifndef _MORKCH_ 39 # define _MORKCH_ 1 40 41 # ifndef _MORK_ 42 # include "mork.h" 43 # endif 44 45 /* this byte char predicate header file derives from public domain Mithril */ 46 /* (that means much of this has a copyright dedicated to the public domain) */ 47 48 /* Use all 8 pred bits; lose some pred bits only if we need to reuse them. */ 49 50 /* ch pred bits: W:white D:digit V:value U:upper L:lower N:name M:more */ 51 # define morkCh_kW (1 << 0) 52 # define morkCh_kD (1 << 1) 53 # define morkCh_kV (1 << 2) 54 # define morkCh_kU (1 << 3) 55 # define morkCh_kL (1 << 4) 56 # define morkCh_kX (1 << 5) 57 # define morkCh_kN (1 << 6) 58 # define morkCh_kM (1 << 7) 59 60 extern const mork_flags morkCh_Type[]; /* 256 byte predicate bits ch map */ 61 62 /* is a numeric decimal digit: (note memory access might be slower) */ 63 /* define morkCh_IsDigit(c) ( morkCh_Type[ (mork_ch)(c) ] & morkCh_kD ) */ 64 # define morkCh_IsDigit(c) (((mork_ch)c) >= '0' && ((mork_ch)c) <= '9') 65 66 /* is a numeric octal digit: */ 67 # define morkCh_IsOctal(c) (((mork_ch)c) >= '0' && ((mork_ch)c) <= '7') 68 69 /* is a numeric hexadecimal digit: */ 70 # define morkCh_IsHex(c) (morkCh_Type[(mork_ch)(c)] & morkCh_kX) 71 72 /* is value (can be printed in Mork value without needing hex or escape): */ 73 # define morkCh_IsValue(c) (morkCh_Type[(mork_ch)(c)] & morkCh_kV) 74 75 /* is white space : */ 76 # define morkCh_IsWhite(c) (morkCh_Type[(mork_ch)(c)] & morkCh_kW) 77 78 /* is name (can start a Mork name): */ 79 # define morkCh_IsName(c) (morkCh_Type[(mork_ch)(c)] & morkCh_kN) 80 81 /* is name (can continue a Mork name): */ 82 # define morkCh_IsMore(c) (morkCh_Type[(mork_ch)(c)] & morkCh_kM) 83 84 /* is alphabetic upper or lower case */ 85 # define morkCh_IsAlpha(c) \ 86 (morkCh_Type[(mork_ch)(c)] & (morkCh_kL | morkCh_kU)) 87 88 /* is alphanumeric, including lower case, upper case, and digits */ 89 # define morkCh_IsAlphaNum(c) \ 90 (morkCh_Type[(mork_ch)(c)] & (morkCh_kL | morkCh_kU | morkCh_kD)) 91 92 /* ````` repeated testing of predicate bits in single flag byte ````` */ 93 94 # define morkCh_GetFlags(c) (morkCh_Type[(mork_ch)(c)]) 95 96 # define morkFlags_IsDigit(f) ((f)&morkCh_kD) 97 # define morkFlags_IsHex(f) ((f)&morkCh_kX) 98 # define morkFlags_IsValue(f) ((f)&morkCh_kV) 99 # define morkFlags_IsWhite(f) ((f)&morkCh_kW) 100 # define morkFlags_IsName(f) ((f)&morkCh_kN) 101 # define morkFlags_IsMore(f) ((f)&morkCh_kM) 102 # define morkFlags_IsAlpha(f) ((f) & (morkCh_kL | morkCh_kU)) 103 # define morkFlags_IsAlphaNum(f) ((f) & (morkCh_kL | morkCh_kU | morkCh_kD)) 104 105 # define morkFlags_IsUpper(f) ((f)&morkCh_kU) 106 # define morkFlags_IsLower(f) ((f)&morkCh_kL) 107 108 /* ````` character case (e.g. for case insensitive operations) ````` */ 109 110 # define morkCh_IsAscii(c) (((mork_u1)c) <= 0x7F) 111 # define morkCh_IsSevenBitChar(c) (((mork_u1)c) <= 0x7F) 112 113 /* ````` character case (e.g. for case insensitive operations) ````` */ 114 115 # define morkCh_ToLower(c) ((c) - 'A' + 'a') 116 # define morkCh_ToUpper(c) ((c) - 'a' + 'A') 117 118 /* extern int morkCh_IsUpper (int c); */ 119 # define morkCh_IsUpper(c) (morkCh_Type[(mork_ch)(c)] & morkCh_kU) 120 121 /* extern int morkCh_IsLower (int c); */ 122 # define morkCh_IsLower(c) (morkCh_Type[(mork_ch)(c)] & morkCh_kL) 123 124 #endif 125 /* _MORKCH_ */ 126