chattr.h
Go to the documentation of this file.
1 // cwchessboard -- A C++ chessboard tool set
2 //
3 //! @file chattr.h Character attribute definitions and arrays.
4 //
5 // Copyright (C) 1998, Andrea Cocito.
6 // Copyright (C) 2008, by
7 //
8 // Carlo Wood, Run on IRC <carlo@alinoe.com>
9 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
10 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
11 //
12 // This program is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef CHATTR_H
26 #define CHATTR_H
27 
28 #ifndef USE_PCH
29 #include <stdint.h>
30 #include <limits.h>
31 #endif
32 
33 typedef uint16_t attr_t;
34 
35 //
36 // Character attribute macros
37 //
38 attr_t const pgn_blank = 0x0001; //!< ' ' | '\\t' | '\\v' | '\\f'. Note that '\\f' is normally not legal in a PGN.
39 attr_t const pgn_eol = 0x0002; //!< '\\r' | '\\n'
40 attr_t const pgn_white_space = pgn_blank | pgn_eol; //!< (pgn_blank | pgn_eol)
41 attr_t const pgn_file = 0x0004; //!< abcdefgh
42 attr_t const pgn_rank = 0x0008; //!< 12345678
43 attr_t const pgn_piece = 0x0010; //!< RNBQK
44 attr_t const pgn_check = 0x0020; //!< +#
45 attr_t const pgn_punctuation_junk = 0x0040; //!< ,;
46 attr_t const pgn_digit = 0x0080; //!< 0123456789
47 attr_t const pgn_alpha = 0x0100; //!< abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
48 attr_t const pgn_alnum = pgn_alpha | pgn_digit; //!< (pgn_alpha | pgn_digit)
49 attr_t const pgn_tagname_begin = pgn_alnum; //!< pgn_alnum
50 attr_t const pgn_tagname_continuation = 0x0200; //!< (pgn_alnum | '_')
51 attr_t const pgn_tag_separator_junk = 0x0400; //!< :=
52 attr_t const pgn_printable_string = 0x0800; //!< ascii range(-96, -1) | ascii range(35, 91) | ' ' | ascii range(93, 126) | '!'
53 attr_t const pgn_quote_or_eol = 0x1000; //!< (ntl_eol | '"')
54 attr_t const pgn_comment_start = 0x2000; //!< {;
55 attr_t const pgn_printable_comment = 0x4000; //!< ascii range(-96, -1) | ascii range(32, 124) | '~' | pgn_blank | pgn_eol
56 attr_t const pgn_printable = 0x8000; //!< ascii range(-96, -1) | ascii range(32, 126)
57 
58 extern char const ToLowerTab_8859_1[];
59 extern char const ToUpperTab_8859_1[];
60 extern attr_t const PGN_CharAttrTab[];
61 
62 //! @brief Convert a character to its lower-case equivalent.
63 inline char to_lower(char c) { return ToLowerTab_8859_1[c - CHAR_MIN]; }
64 //! @brief Convert a character to its upper-case equivalent.
65 inline char to_upper(char c) { return ToUpperTab_8859_1[c - CHAR_MIN]; }
66 
67 //
68 // Character classification functions.
69 // NOTE: The is_upper and is_lower macros do not apply to the complete
70 // ISO 8859-1 character set, unlike the to_upper and to_lower macros above.
71 // is_upper and is_lower only apply for comparisons of the US ASCII subset.
72 //
73 
74 //! @brief Test whether a character is a blank.
75 inline attr_t is_blank(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_blank; }
76 //! @brief Test whether a character is an end-of-line character.
77 inline attr_t is_eol(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_eol; }
78 //! @brief Test whether a character is white space.
79 inline attr_t is_white_space(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_white_space; }
80 //! @brief Test whether a character is a file symbol.
81 inline attr_t is_file(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_file; }
82 //! @brief Test whether a character is a rank symbol.
83 inline attr_t is_rank(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_rank; }
84 //! @brief Test whether a character is a chess piece symbol.
85 inline attr_t is_piece(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_piece; }
86 //! @brief Test whether a character is a check or mate symbol.
87 inline attr_t is_check(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_check; }
88 //! @brief Test whether a character is punctuation junk.
89 inline attr_t is_punctuation_junk(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_punctuation_junk; }
90 //! @brief Test whether a character is a digit.
91 inline attr_t is_digit(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_digit; }
92 //! @brief Test whether a character is alphabetic.
93 inline attr_t is_alpha(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_alpha; }
94 //! @brief Test whether a character is alphanumeric.
95 inline attr_t is_alnum(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_alnum; }
96 //! @brief Test whether a character could be the first character of a tagname.
97 inline attr_t is_tagname_begin(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_tagname_begin; }
98 //! @brief Test whether a character could be part of a tagname.
99 inline attr_t is_tagname_continuation(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_tagname_continuation; }
100 //! @brief Test whether a character could tag separator junk.
101 inline attr_t is_tag_separator_junk(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_tag_separator_junk; }
102 //! @brief Test whether a character is allowed in a string.
103 inline attr_t is_printable_string(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_printable_string; }
104 //! @brief Test whether a character is a quote or EOL.
105 inline attr_t is_quote_or_eol(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_quote_or_eol; }
106 //! @brief Test whether a character is a comment start.
107 inline attr_t is_comment_start(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_comment_start; }
108 //! @brief Test whether a character is allowed in a brace comment.
109 inline attr_t is_printable_comment(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_printable_comment; }
110 //! @brief Test whether a character is allowed in a semi-colon comment.
111 inline attr_t is_printable(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_printable; }
112 
113 #endif // CHATTR_H
attr_t const pgn_digit
0123456789
Definition: chattr.h:46
char to_lower(char c)
Convert a character to its lower-case equivalent.
Definition: chattr.h:63
attr_t is_piece(char c)
Test whether a character is a chess piece symbol.
Definition: chattr.h:85
attr_t const pgn_file
abcdefgh
Definition: chattr.h:41
attr_t is_quote_or_eol(char c)
Test whether a character is a quote or EOL.
Definition: chattr.h:105
attr_t is_tagname_begin(char c)
Test whether a character could be the first character of a tagname.
Definition: chattr.h:97
attr_t const pgn_eol
&#39;\r&#39; |& #39;\n&#39;
Definition: chattr.h:39
attr_t const pgn_tag_separator_junk
:=
Definition: chattr.h:51
attr_t is_alpha(char c)
Test whether a character is alphabetic.
Definition: chattr.h:93
attr_t const pgn_piece
RNBQK.
Definition: chattr.h:43
attr_t const pgn_tagname_continuation
(pgn_alnum |& #39;_&#39;)
Definition: chattr.h:50
attr_t const pgn_tagname_begin
pgn_alnum
Definition: chattr.h:49
attr_t is_printable(char c)
Test whether a character is allowed in a semi-colon comment.
Definition: chattr.h:111
attr_t is_blank(char c)
Test whether a character is a blank.
Definition: chattr.h:75
char to_upper(char c)
Convert a character to its upper-case equivalent.
Definition: chattr.h:65
attr_t is_printable_string(char c)
Test whether a character is allowed in a string.
Definition: chattr.h:103
attr_t is_check(char c)
Test whether a character is a check or mate symbol.
Definition: chattr.h:87
attr_t is_digit(char c)
Test whether a character is a digit.
Definition: chattr.h:91
attr_t is_rank(char c)
Test whether a character is a rank symbol.
Definition: chattr.h:83
attr_t is_white_space(char c)
Test whether a character is white space.
Definition: chattr.h:79
attr_t is_file(char c)
Test whether a character is a file symbol.
Definition: chattr.h:81
attr_t const pgn_alnum
(pgn_alpha | pgn_digit)
Definition: chattr.h:48
attr_t const pgn_comment_start
{;
Definition: chattr.h:54
attr_t const pgn_alpha
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
Definition: chattr.h:47
attr_t const pgn_white_space
(pgn_blank | pgn_eol)
Definition: chattr.h:40
attr_t is_alnum(char c)
Test whether a character is alphanumeric.
Definition: chattr.h:95
attr_t is_comment_start(char c)
Test whether a character is a comment start.
Definition: chattr.h:107
attr_t const pgn_quote_or_eol
(ntl_eol |& #39;"&#39;)
Definition: chattr.h:53
attr_t const pgn_punctuation_junk
,;
Definition: chattr.h:45
attr_t is_punctuation_junk(char c)
Test whether a character is punctuation junk.
Definition: chattr.h:89
attr_t const pgn_printable_string
ascii range(-96, -1) | ascii range(35, 91) |& #39;& #39; | ascii range(93, 126) |& #39;!&#39;
Definition: chattr.h:52
attr_t const pgn_check
+#
Definition: chattr.h:44
attr_t const pgn_printable
ascii range(-96, -1) | ascii range(32, 126)
Definition: chattr.h:56
attr_t const pgn_blank
&#39;& #39; |& #39;\t&#39; |& #39;\v&#39; |& #39;\f&#39;. Note that& #39;\f&#39; is normally not legal in a PGN.
Definition: chattr.h:38
attr_t is_eol(char c)
Test whether a character is an end-of-line character.
Definition: chattr.h:77
attr_t is_printable_comment(char c)
Test whether a character is allowed in a brace comment.
Definition: chattr.h:109
attr_t is_tagname_continuation(char c)
Test whether a character could be part of a tagname.
Definition: chattr.h:99
attr_t const pgn_rank
12345678
Definition: chattr.h:42
attr_t is_tag_separator_junk(char c)
Test whether a character could tag separator junk.
Definition: chattr.h:101
attr_t const pgn_printable_comment
ascii range(-96, -1) | ascii range(32, 124) |& #39;~&#39; | pgn_blank | pgn_eol
Definition: chattr.h:55

Copyright © 2006 - 2010 Carlo Wood.  All rights reserved.