00001 // cwchessboard -- A C++ chessboard tool set 00002 // 00003 //! @file chattr.h Character attribute definitions and arrays. 00004 // 00005 // Copyright (C) 1998, Andrea Cocito. 00006 // Copyright (C) 2008, by 00007 // 00008 // Carlo Wood, Run on IRC <carlo@alinoe.com> 00009 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 00010 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 00011 // 00012 // This program is free software: you can redistribute it and/or modify 00013 // it under the terms of the GNU General Public License as published by 00014 // the Free Software Foundation, either version 2 of the License, or 00015 // (at your option) any later version. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU General Public License 00023 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00024 00025 #ifndef CHATTR_H 00026 #define CHATTR_H 00027 00028 #ifndef USE_PCH 00029 #include <stdint.h> 00030 #include <limits.h> 00031 #endif 00032 00033 typedef uint16_t attr_t; 00034 00035 // 00036 // Character attribute macros 00037 // 00038 attr_t const pgn_blank = 0x0001; //!< ' ' | '\t' | '\v' | '\f'. Note that '\f' is normally not legal in a PGN. 00039 attr_t const pgn_eol = 0x0002; //!< '\r' | '\n' 00040 attr_t const pgn_white_space = pgn_blank | pgn_eol; //!< (pgn_blank | pgn_eol) 00041 attr_t const pgn_file = 0x0004; //!< abcdefgh 00042 attr_t const pgn_rank = 0x0008; //!< 12345678 00043 attr_t const pgn_piece = 0x0010; //!< RNBQK 00044 attr_t const pgn_check = 0x0020; //!< +# 00045 attr_t const pgn_punctuation_junk = 0x0040; //!< ,; 00046 attr_t const pgn_digit = 0x0080; //!< 0123456789 00047 attr_t const pgn_alpha = 0x0100; //!< abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 00048 attr_t const pgn_alnum = pgn_alpha | pgn_digit; //!< (pgn_alpha | pgn_digit) 00049 attr_t const pgn_tagname_begin = pgn_alnum; //!< pgn_alnum 00050 attr_t const pgn_tagname_continuation = 0x0200; //!< (pgn_alnum | '_') 00051 attr_t const pgn_tag_separator_junk = 0x0400; //!< := 00052 attr_t const pgn_printable_string = 0x0800; //!< ascii range(-96, -1) | ascii range(35, 91) | ' ' | ascii range(93, 126) | '!' 00053 attr_t const pgn_quote_or_eol = 0x1000; //!< (ntl_eol | '"') 00054 attr_t const pgn_comment_start = 0x2000; //!< {; 00055 attr_t const pgn_printable_comment = 0x4000; //!< ascii range(-96, -1) | ascii range(32, 124) | '~' | pgn_blank | pgn_eol 00056 attr_t const pgn_printable = 0x8000; //!< ascii range(-96, -1) | ascii range(32, 126) 00057 00058 extern char const ToLowerTab_8859_1[]; 00059 extern char const ToUpperTab_8859_1[]; 00060 extern attr_t const PGN_CharAttrTab[]; 00061 00062 //! @brief Convert a character to its lower-case equivalent. 00063 inline char to_lower(char c) { return ToLowerTab_8859_1[c - CHAR_MIN]; } 00064 //! @brief Convert a character to its upper-case equivalent. 00065 inline char to_upper(char c) { return ToUpperTab_8859_1[c - CHAR_MIN]; } 00066 00067 // 00068 // Character classification functions. 00069 // NOTE: The is_upper and is_lower macros do not apply to the complete 00070 // ISO 8859-1 character set, unlike the to_upper and to_lower macros above. 00071 // is_upper and is_lower only apply for comparisons of the US ASCII subset. 00072 // 00073 00074 //! @brief Test whether a character is a blank. 00075 inline attr_t is_blank(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_blank; } 00076 //! @brief Test whether a character is an end-of-line character. 00077 inline attr_t is_eol(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_eol; } 00078 //! @brief Test whether a character is white space. 00079 inline attr_t is_white_space(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_white_space; } 00080 //! @brief Test whether a character is a file symbol. 00081 inline attr_t is_file(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_file; } 00082 //! @brief Test whether a character is a rank symbol. 00083 inline attr_t is_rank(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_rank; } 00084 //! @brief Test whether a character is a chess piece symbol. 00085 inline attr_t is_piece(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_piece; } 00086 //! @brief Test whether a character is a check or mate symbol. 00087 inline attr_t is_check(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_check; } 00088 //! @brief Test whether a character is punctuation junk. 00089 inline attr_t is_punctuation_junk(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_punctuation_junk; } 00090 //! @brief Test whether a character is a digit. 00091 inline attr_t is_digit(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_digit; } 00092 //! @brief Test whether a character is alphabetic. 00093 inline attr_t is_alpha(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_alpha; } 00094 //! @brief Test whether a character is alphanumeric. 00095 inline attr_t is_alnum(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_alnum; } 00096 //! @brief Test whether a character could be the first character of a tagname. 00097 inline attr_t is_tagname_begin(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_tagname_begin; } 00098 //! @brief Test whether a character could be part of a tagname. 00099 inline attr_t is_tagname_continuation(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_tagname_continuation; } 00100 //! @brief Test whether a character could tag separator junk. 00101 inline attr_t is_tag_separator_junk(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_tag_separator_junk; } 00102 //! @brief Test whether a character is allowed in a string. 00103 inline attr_t is_printable_string(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_printable_string; } 00104 //! @brief Test whether a character is a quote or EOL. 00105 inline attr_t is_quote_or_eol(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_quote_or_eol; } 00106 //! @brief Test whether a character is a comment start. 00107 inline attr_t is_comment_start(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_comment_start; } 00108 //! @brief Test whether a character is allowed in a brace comment. 00109 inline attr_t is_printable_comment(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_printable_comment; } 00110 //! @brief Test whether a character is allowed in a semi-colon comment. 00111 inline attr_t is_printable(char c) { return PGN_CharAttrTab[c - CHAR_MIN] & pgn_printable; } 00112 00113 #endif // CHATTR_H