1*4420c1ceSMichael Pfeiffer /* 2*4420c1ceSMichael Pfeiffer * Copyright 2008, Haiku. 3*4420c1ceSMichael Pfeiffer * Distributed under the terms of the MIT license. 4*4420c1ceSMichael Pfeiffer * 5*4420c1ceSMichael Pfeiffer * Authors: 6*4420c1ceSMichael Pfeiffer * Michael Pfeiffer <laplace@users.sourceforge.net> 7*4420c1ceSMichael Pfeiffer */ 8*4420c1ceSMichael Pfeiffer 9*4420c1ceSMichael Pfeiffer #ifndef _CHARACTER_CLASSES_H 10*4420c1ceSMichael Pfeiffer #define _CHARACTER_CLASSES_H 11*4420c1ceSMichael Pfeiffer 12*4420c1ceSMichael Pfeiffer #define kCr '\n' 13*4420c1ceSMichael Pfeiffer #define kLf '\r' 14*4420c1ceSMichael Pfeiffer #define kTab '\t' 15*4420c1ceSMichael Pfeiffer #define kEof -1 16*4420c1ceSMichael Pfeiffer IsWhitespaceSeparator(int ch)17*4420c1ceSMichael Pfeifferinline bool IsWhitespaceSeparator(int ch) 18*4420c1ceSMichael Pfeiffer { 19*4420c1ceSMichael Pfeiffer return ch == ' ' || ch == kTab; 20*4420c1ceSMichael Pfeiffer } 21*4420c1ceSMichael Pfeiffer IsWhitespace(int ch)22*4420c1ceSMichael Pfeifferinline bool IsWhitespace(int ch) 23*4420c1ceSMichael Pfeiffer { 24*4420c1ceSMichael Pfeiffer return ch == ' ' || ch == kTab || ch == kLf || ch == kCr; 25*4420c1ceSMichael Pfeiffer } 26*4420c1ceSMichael Pfeiffer IsIdentChar(int ch)27*4420c1ceSMichael Pfeifferinline bool IsIdentChar(int ch) { 28*4420c1ceSMichael Pfeiffer // TODO check '.' if is an identifier character 29*4420c1ceSMichael Pfeiffer // in one of the PPD files delivered with BeOS R5 30*4420c1ceSMichael Pfeiffer // '.' is used inside of an identifier 31*4420c1ceSMichael Pfeiffer // if (ch == '.' || ch == '/' || ch == ':') return false; 32*4420c1ceSMichael Pfeiffer if (ch == '/' || ch == ':') return false; 33*4420c1ceSMichael Pfeiffer return 33 <= ch && ch <= 126; 34*4420c1ceSMichael Pfeiffer } 35*4420c1ceSMichael Pfeiffer IsOptionChar(int ch)36*4420c1ceSMichael Pfeifferinline bool IsOptionChar(int ch) 37*4420c1ceSMichael Pfeiffer { 38*4420c1ceSMichael Pfeiffer if (ch == '.') return true; 39*4420c1ceSMichael Pfeiffer return IsIdentChar(ch); 40*4420c1ceSMichael Pfeiffer } 41*4420c1ceSMichael Pfeiffer IsChar(int ch)42*4420c1ceSMichael Pfeifferinline bool IsChar(int ch) 43*4420c1ceSMichael Pfeiffer { 44*4420c1ceSMichael Pfeiffer if (ch == '"') return false; 45*4420c1ceSMichael Pfeiffer return 32 <= ch && ch <= 255 || IsWhitespace(ch); 46*4420c1ceSMichael Pfeiffer } 47*4420c1ceSMichael Pfeiffer IsPrintableWithoutWhitespaces(int ch)48*4420c1ceSMichael Pfeifferinline bool IsPrintableWithoutWhitespaces(int ch) 49*4420c1ceSMichael Pfeiffer { 50*4420c1ceSMichael Pfeiffer if (ch == '"') return false; 51*4420c1ceSMichael Pfeiffer return 33 <= ch && ch <= 126; 52*4420c1ceSMichael Pfeiffer } 53*4420c1ceSMichael Pfeiffer IsPrintableWithWhitespaces(int ch)54*4420c1ceSMichael Pfeifferinline bool IsPrintableWithWhitespaces(int ch) 55*4420c1ceSMichael Pfeiffer { 56*4420c1ceSMichael Pfeiffer return IsPrintableWithoutWhitespaces(ch) || IsWhitespace(ch); 57*4420c1ceSMichael Pfeiffer } 58*4420c1ceSMichael Pfeiffer IsStringChar(int ch)59*4420c1ceSMichael Pfeifferinline bool IsStringChar(int ch) 60*4420c1ceSMichael Pfeiffer { 61*4420c1ceSMichael Pfeiffer if (IsWhitespaceSeparator(ch)) return true; 62*4420c1ceSMichael Pfeiffer if (ch == '"') return true; 63*4420c1ceSMichael Pfeiffer if (ch == '/') return false; 64*4420c1ceSMichael Pfeiffer return IsPrintableWithoutWhitespaces(ch); 65*4420c1ceSMichael Pfeiffer } 66*4420c1ceSMichael Pfeiffer 67*4420c1ceSMichael Pfeiffer #endif 68