Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Raduly, Csaba | |
11 | * Szabo, Janos Zoltan – initial implementation | |
12 | * Szalai, Gabor | |
13 | * | |
14 | ******************************************************************************/ | |
970ed795 EL |
15 | #ifndef _TEXT_HH |
16 | #define _TEXT_HH | |
17 | ||
18 | #include "Types.h" | |
19 | #include "Encdec.hh" | |
20 | #include <sys/types.h> | |
21 | #include <regex.h> | |
22 | /** | |
23 | * \defgroup TEXT TEXT-related stuff. | |
24 | * | |
25 | * @{ | |
26 | */ | |
27 | class CHARSTRING; | |
28 | class Token_Match; | |
29 | struct TTCN_TEXTdescriptor_values { | |
30 | boolean leading_zero; | |
31 | boolean repeatable; | |
32 | int min_length; | |
33 | int max_length; | |
34 | int convert; | |
35 | int just; | |
36 | }; | |
37 | ||
38 | struct TTCN_TEXTdescriptor_bool { | |
39 | const CHARSTRING* true_encode_token; | |
40 | const Token_Match* true_decode_token; | |
41 | const CHARSTRING* false_encode_token; | |
42 | const Token_Match* false_decode_token; | |
43 | }; | |
44 | ||
45 | struct TTCN_TEXTdescriptor_enum { | |
46 | const CHARSTRING* encode_token; | |
47 | const Token_Match* decode_token; | |
48 | }; | |
49 | ||
50 | ||
51 | struct TTCN_TEXTdescriptor_param_values { | |
52 | TTCN_TEXTdescriptor_values coding_params; | |
53 | TTCN_TEXTdescriptor_values decoding_params; | |
54 | }; | |
55 | ||
56 | union TTCN_TEXTdescriptor_union { | |
57 | const TTCN_TEXTdescriptor_param_values* parameters; | |
58 | const TTCN_TEXTdescriptor_bool* bool_values; | |
59 | const TTCN_TEXTdescriptor_enum* enum_values; | |
60 | }; | |
61 | ||
62 | struct TTCN_TEXTdescriptor_t { | |
63 | const CHARSTRING* begin_encode; | |
64 | const Token_Match* begin_decode; | |
65 | const CHARSTRING* end_encode; | |
66 | const Token_Match* end_decode; | |
67 | const CHARSTRING* separator_encode; | |
68 | const Token_Match* separator_decode; | |
69 | const Token_Match* select_token; | |
70 | TTCN_TEXTdescriptor_union val; | |
71 | }; | |
72 | ||
73 | class Token_Match { | |
74 | regex_t posix_regexp_begin; ///< regexp for the anchored match | |
75 | regex_t posix_regexp_first; ///< regexp for floating match | |
76 | const char *token_str; // not owned or freed by Token_Match | |
77 | size_t fixed_len; ///< length of fixed string, or zero | |
78 | boolean null_match; ///< true if the token_str was NULL or empty | |
79 | public: | |
80 | Token_Match(const char *posix_str, boolean case_sensitive = TRUE, | |
81 | boolean fixed = FALSE); | |
82 | ~Token_Match(); | |
83 | ||
84 | inline operator const char*() const { return token_str; } | |
85 | /** Match anchored at the beginning | |
86 | * | |
87 | * @param buf the buffer to search | |
88 | * @return length of the match or -1 if not matched | |
89 | * | |
90 | * It may call TTCN_error() in case of error, causing a DTE | |
91 | */ | |
92 | int match_begin(TTCN_Buffer& buf) const; | |
93 | /** Floating match | |
94 | * | |
95 | * @param buf the buffer to search | |
96 | * @return the offset where the match begins, or -1 if not matched | |
97 | * | |
98 | * It may call TTCN_error() in case of error, causing a DTE | |
99 | */ | |
100 | int match_first(TTCN_Buffer& buf) const; | |
101 | }; | |
102 | ||
103 | class Limit_Token_List { | |
104 | private: | |
105 | size_t num_of_tokens; | |
106 | size_t size_of_list; | |
107 | const Token_Match **list; | |
108 | int *last_match; | |
109 | int last_ret_val; | |
110 | const char* last_pos; | |
111 | /// Copy constructor disabled | |
112 | Limit_Token_List(const Limit_Token_List&); | |
113 | /// Assignment disabled | |
114 | Limit_Token_List& operator=(const Limit_Token_List&); | |
115 | public: | |
116 | Limit_Token_List(); | |
117 | ~Limit_Token_List(); | |
118 | ||
119 | void add_token(const Token_Match *); | |
120 | void remove_tokens(size_t); | |
121 | int match(TTCN_Buffer&,size_t lim=0); | |
122 | inline boolean has_token(size_t ml=0) const { return num_of_tokens != ml; } | |
123 | }; | |
124 | ||
125 | extern const TTCN_TEXTdescriptor_t INTEGER_text_; | |
126 | extern const TTCN_TEXTdescriptor_t BOOLEAN_text_; | |
127 | extern const TTCN_TEXTdescriptor_t CHARSTRING_text_; | |
128 | extern const TTCN_TEXTdescriptor_t BITSTRING_text_; | |
129 | extern const TTCN_TEXTdescriptor_t HEXSTRING_text_; | |
130 | extern const TTCN_TEXTdescriptor_t OCTETSTRING_text_; | |
a38c6d4c | 131 | extern const TTCN_TEXTdescriptor_t UNIVERSAL_CHARSTRING_text_; |
970ed795 EL |
132 | |
133 | /** @} end of TEXT group */ | |
134 | ||
135 | #endif // _TEXT_HH |