1 /* GNU Ocrad - Optical Character Recognition program 2 Copyright (C) 2014-2019 Antonio Diaz Diaz. 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 class User_filter 19 { 20 public: 21 // default action: discard, leave unmodified, mark as unrecognized 22 enum Default { d_discard = 0, d_leave, d_mark }; 23 24 private: 25 struct Entry 26 { 27 int code; 28 int new_code; EntryEntry29 Entry( const int c, const int nc ) : code( c ), new_code( nc ) {} 30 }; 31 32 std::vector< int > table1; // -1 or new_code of first 256 UCS chars 33 std::vector< Entry > table2; // codes of UCS chars >= 256 34 std::string error_; 35 int retval_; 36 Default default_; 37 38 bool enable_char( const int code, int new_code ); 39 int parse_char( const std::string & line, unsigned &i ) const; 40 void set_file_error( const char * const file_name, const int linenum ); 41 42 public: 43 explicit User_filter( const char * const file_name ); error()44 const std::string & error() const { return error_; } retval()45 int retval() const { return retval_; } 46 int get_new_code( const int code ) const; // -1 means disabled discard()47 bool discard() const { return default_ == d_discard; } mark()48 bool mark() const { return default_ == d_mark; } 49 }; 50