Line data Source code
1 : /* Copyright (C) 1989-2025 Free Software Foundation, Inc. 2 : Written by James Clark (jjc@jclark.com) 3 : 4 : This file is part of groff, the GNU roff typesetting system. 5 : 6 : groff is free software; you can redistribute it and/or modify it under 7 : the terms of the GNU General Public License as published by the Free 8 : Software Foundation, either version 3 of the License, or 9 : (at your option) any later version. 10 : 11 : groff is distributed in the hope that it will be useful, but WITHOUT ANY 12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 : for more details. 15 : 16 : You should have received a copy of the GNU General Public License 17 : along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 : 19 : #include <stddef.h> // size_t 20 : #include <stdint.h> // uintptr_t 21 : 22 : #define DONT_STORE 1 23 : #define MUST_ALREADY_EXIST 2 24 : 25 : class symbol { 26 : static const char **table; 27 : static int table_used; 28 : static int table_size; 29 : static char *block; 30 : static size_t block_size; 31 : const char *s; 32 : public: 33 : symbol(const char *p, int /* how */ = 0); 34 : symbol(); 35 : uintptr_t hash() const; 36 : int operator ==(symbol) const; 37 : int operator !=(symbol) const; 38 : const char *contents() const; 39 : bool is_null() const; 40 : bool is_empty() const; 41 : size_t json_length() const; 42 : const char *json_extract() const; 43 : void json_dump() const; 44 : }; 45 : 46 : 47 : extern const symbol NULL_SYMBOL; 48 : extern const symbol EMPTY_SYMBOL; 49 : 50 22640395 : inline symbol::symbol() : s(0 /* nullptr */) 51 : { 52 22640395 : } 53 : 54 72929713 : inline int symbol::operator==(symbol p) const 55 : { 56 72929713 : return s == p.s; 57 : } 58 : 59 28239860 : inline int symbol::operator!=(symbol p) const 60 : { 61 28239860 : return s != p.s; 62 : } 63 : 64 47653627 : inline uintptr_t symbol::hash() const 65 : { 66 47653627 : return reinterpret_cast<uintptr_t>(s); 67 : } 68 : 69 33200448 : inline const char *symbol::contents() const 70 : { 71 33200448 : return s; 72 : } 73 : 74 49720747 : inline bool symbol::is_null() const 75 : { 76 49720747 : return (0 /* nullptr */ == s); 77 : } 78 : 79 17207398 : inline bool symbol::is_empty() const 80 : { 81 17207398 : return ((s != 0 /* nullptr */) && (0 /* nullptr */ == *s)); 82 : } 83 : 84 : symbol concat(symbol, symbol); 85 : 86 : extern symbol default_symbol; 87 : 88 : // Local Variables: 89 : // fill-column: 72 90 : // mode: C++ 91 : // End: 92 : // vim: set cindent noexpandtab shiftwidth=2 textwidth=72: