Line data Source code
1 : // -*- C++ -*- 2 : /* Copyright (C) 1989-2020 Free Software Foundation, Inc. 3 : Written by James Clark (jjc@jclark.com) 4 : 5 : This file is part of groff, the GNU roff typesetting system. 6 : 7 : groff is free software; you can redistribute it and/or modify it under 8 : the terms of the GNU General Public License as published by the Free 9 : Software Foundation, either version 3 of the License, or 10 : (at your option) any later version. 11 : 12 : groff is distributed in the hope that it will be useful, but WITHOUT ANY 13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 : for more details. 16 : 17 : You should have received a copy of the GNU General Public License 18 : along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 : 20 : enum token_type { 21 : TOKEN_OTHER, 22 : TOKEN_UPPER, 23 : TOKEN_LOWER, 24 : TOKEN_ACCENT, 25 : TOKEN_PUNCT, 26 : TOKEN_HYPHEN, 27 : TOKEN_RANGE_SEP 28 : }; 29 : 30 : class token_info { 31 : private: 32 : token_type type; 33 : const char *sort_key; 34 : const char *other_case; 35 : public: 36 : token_info(); 37 : void set(token_type, const char *sk = 0, const char *oc = 0); 38 : void lower_case(const char *start, const char *end, string &result) const; 39 : void upper_case(const char *start, const char *end, string &result) const; 40 : void sortify(const char *start, const char *end, string &result) const; 41 : int sortify_non_empty(const char *start, const char *end) const; 42 : int is_upper() const; 43 : int is_lower() const; 44 : int is_accent() const; 45 : int is_other() const; 46 : int is_punct() const; 47 : int is_hyphen() const; 48 : int is_range_sep() const; 49 : }; 50 : 51 0 : inline int token_info::is_upper() const 52 : { 53 0 : return type == TOKEN_UPPER; 54 : } 55 : 56 0 : inline int token_info::is_lower() const 57 : { 58 0 : return type == TOKEN_LOWER; 59 : } 60 : 61 0 : inline int token_info::is_accent() const 62 : { 63 0 : return type == TOKEN_ACCENT; 64 : } 65 : 66 : inline int token_info::is_other() const 67 : { 68 : return type == TOKEN_OTHER; 69 : } 70 : 71 0 : inline int token_info::is_punct() const 72 : { 73 0 : return type == TOKEN_PUNCT; 74 : } 75 : 76 0 : inline int token_info::is_hyphen() const 77 : { 78 0 : return type == TOKEN_HYPHEN; 79 : } 80 : 81 0 : inline int token_info::is_range_sep() const 82 : { 83 0 : return type == TOKEN_RANGE_SEP; 84 : } 85 : 86 : bool get_token(const char **ptr, const char *end); 87 : const token_info *lookup_token(const char *start, const char *end);