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