1 /* Copyright (C) 2018 Olga Yakovleva <yakovleva.o.v@gmail.com> */ 2 3 /* This program is free software: you can redistribute it and/or modify */ 4 /* it under the terms of the GNU Lesser General Public License as published by */ 5 /* the Free Software Foundation, either version 2.1 of the License, or */ 6 /* (at your option) any later version. */ 7 8 /* This program is distributed in the hope that it will be useful, */ 9 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 10 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 11 /* GNU Lesser General Public License for more details. */ 12 13 /* You should have received a copy of the GNU Lesser General Public License */ 14 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #ifndef RHVOICE_QUESTION_MATCHER_H 17 #define RHVOICE_QUESTION_MATCHER_H 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #define RHVOICE_PARSED_LABEL_STRING_MAX_LENGTH 1024 24 25 typedef struct 26 { 27 char* label_string; 28 short label_string_length; 29 short index[128]; 30 short* links; 31 } RHVoice_parsed_label_string; 32 33 int RHVoice_parse_label_string(const char* str,RHVoice_parsed_label_string* out); 34 void RHVoice_parsed_label_string_init(RHVoice_parsed_label_string* l); 35 void RHVoice_parsed_label_string_clear(RHVoice_parsed_label_string* l); 36 int RHVoice_parsed_label_string_copy(const RHVoice_parsed_label_string* from,RHVoice_parsed_label_string* to); 37 int RHVoice_question_match(const RHVoice_parsed_label_string* l,const char* q); 38 #ifdef __cplusplus 39 } 40 #endif 41 #endif 42 43 #ifndef RHVOICE_QUESTION_MATCHER_HPP 44 #define RHVOICE_QUESTION_MATCHER_HPP 45 46 #ifdef __cplusplus 47 48 namespace RHVoice 49 { 50 struct parsed_label_string 51 { parsed_label_stringparsed_label_string52 parsed_label_string() 53 { 54 init(); 55 } 56 parsed_label_stringparsed_label_string57 parsed_label_string(const parsed_label_string& other) 58 { 59 init(); 60 copy(other); 61 } 62 63 parsed_label_string& operator=(const parsed_label_string& other) 64 { 65 copy(other); 66 return *this; 67 } 68 ~parsed_label_stringparsed_label_string69 ~parsed_label_string() 70 { 71 clear(); 72 } 73 get_dataparsed_label_string74 const RHVoice_parsed_label_string* get_data() const 75 { 76 return &data; 77 } 78 79 void parse(const char* s); 80 matchparsed_label_string81 bool match(const char* q) const 82 { 83 return (RHVoice_question_match(&data,q)!=0); 84 } 85 86 private: 87 initparsed_label_string88 void init() 89 { 90 RHVoice_parsed_label_string_init(&data); 91 } 92 clearparsed_label_string93 void clear() 94 { 95 RHVoice_parsed_label_string_clear(&data); 96 } 97 98 void copy(const parsed_label_string& other); 99 100 RHVoice_parsed_label_string data; 101 }; 102 } 103 #endif 104 #endif 105