Commit | Line | Data |
---|---|---|
970ed795 | 1 | /////////////////////////////////////////////////////////////////////////////// |
3abe9331 | 2 | // Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
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 | #ifndef UNIVERSAL_CHARSTRING_HH | |
9 | #define UNIVERSAL_CHARSTRING_HH | |
10 | ||
11 | #include "Basetype.hh" | |
12 | #include "Template.hh" | |
13 | #include "Optional.hh" | |
14 | #include "Error.hh" | |
15 | #include "CharCoding.hh" | |
16 | ||
17 | #include <regex.h> | |
18 | #include "Charstring.hh" | |
19 | ||
20 | class CHARSTRING; | |
21 | class CHARSTRING_ELEMENT; | |
22 | class CHARSTRING_template; | |
23 | class UNIVERSAL_CHARSTRING_ELEMENT; | |
24 | class UNIVERSAL_CHARSTRING_template; | |
25 | class INTEGER; | |
26 | class Module_Param; | |
27 | ||
28 | extern boolean operator==(const universal_char& left_value, | |
29 | const universal_char& right_value); | |
30 | extern boolean operator<(const universal_char& left_value, | |
31 | const universal_char& right_value); | |
32 | ||
33 | /** Runtime class for Unicode character strings. | |
34 | * | |
35 | * This class implements the following string types: | |
36 | * - TTCN-3 \c universal \c charstring | |
37 | * - ASN.1 | |
38 | * - \c UTF8String | |
39 | * - \c TeletexString | |
40 | * - \c VideotexString | |
41 | * - \c GraphicsString | |
42 | * - \c GeneralString | |
43 | * - \c UniversalString | |
44 | * - \c BMPString | |
45 | * - \c ObjectDescriptor | |
46 | * | |
47 | * Note: an object of this class is effectively immutable after creation. | |
48 | * | |
49 | * There is no terminating {0,0,0,0} at the end. | |
50 | */ | |
51 | class UNIVERSAL_CHARSTRING : public Base_Type { | |
52 | ||
53 | friend class CHARSTRING; | |
54 | friend class CHARSTRING_ELEMENT; | |
55 | friend class UNIVERSAL_CHARSTRING_ELEMENT; | |
56 | friend class TTCN_Buffer; | |
57 | friend class UNIVERSAL_CHARSTRING_template; | |
58 | ||
59 | friend UNIVERSAL_CHARSTRING oct2unichar(const OCTETSTRING& invalue, | |
60 | const CHARSTRING& string_encoding); | |
61 | friend UNIVERSAL_CHARSTRING oct2unichar(const OCTETSTRING& invalue); | |
62 | friend UNIVERSAL_CHARSTRING replace(const UNIVERSAL_CHARSTRING& value, | |
63 | int index, int len, const UNIVERSAL_CHARSTRING& repl); | |
64 | friend UNIVERSAL_CHARSTRING regexp(const UNIVERSAL_CHARSTRING& instr, | |
65 | const UNIVERSAL_CHARSTRING* expression_val, | |
66 | const UNIVERSAL_CHARSTRING_template* expression_tmpl, | |
67 | int groupno); | |
68 | ||
69 | friend boolean operator==(const universal_char& uchar_value, | |
70 | const UNIVERSAL_CHARSTRING& other_value); | |
71 | friend UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value, | |
72 | const UNIVERSAL_CHARSTRING& other_value); | |
73 | friend boolean operator==(const char *string_value, | |
74 | const UNIVERSAL_CHARSTRING& other_value); | |
75 | friend UNIVERSAL_CHARSTRING operator+(const char *string_value, | |
76 | const UNIVERSAL_CHARSTRING& other_value); | |
77 | friend UNIVERSAL_CHARSTRING operator+(const char *string_value, | |
78 | const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
79 | friend UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value, | |
80 | const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
81 | friend boolean operator==(const char *string_value, | |
82 | const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
83 | ||
84 | /** Internal data type, no user serviceable parts inside */ | |
85 | struct universal_charstring_struct; | |
86 | /** Internal data */ | |
87 | universal_charstring_struct *val_ptr; | |
88 | /** Character string values are stored in an optimal way */ | |
89 | CHARSTRING cstr; | |
90 | bool charstring; | |
91 | ||
92 | void init_struct(int n_uchars); | |
93 | void copy_value(); | |
94 | UNIVERSAL_CHARSTRING(int n_uchars, bool cstring = false); | |
3abe9331 | 95 | |
96 | /** An extended version of set_param(), which also accepts string patterns if | |
97 | * the second parameter is set (needed by UNIVERSAL_CHARSTRING_template to | |
98 | * concatenate string patterns). | |
99 | * @return TRUE, if the module parameter was a string pattern, otherwise FALSE */ | |
100 | boolean set_param_internal(Module_Param& param, boolean allow_pattern); | |
970ed795 EL |
101 | |
102 | public: | |
103 | ||
104 | /** Construct an empty string */ | |
105 | UNIVERSAL_CHARSTRING(); | |
106 | /** Construct a string containing a single character. | |
107 | * | |
108 | * @param uc_group Unicode group (most significant part) | |
109 | * @param uc_plane Unicode plane | |
110 | * @param uc_row Unicode row | |
111 | * @param uc_cell Unicode cell (least significant) | |
112 | * | |
113 | */ | |
114 | UNIVERSAL_CHARSTRING(unsigned char uc_group, unsigned char uc_plane, | |
115 | unsigned char uc_row, unsigned char uc_cell); | |
116 | /** Construct a string containing a single character | |
117 | * | |
118 | * @param other_value | |
119 | */ | |
120 | UNIVERSAL_CHARSTRING(const universal_char& other_value); | |
121 | /** Construct a string from a given number of characters | |
122 | * | |
123 | * @param n_uchars | |
124 | * @param uchars_ptr | |
125 | */ | |
126 | UNIVERSAL_CHARSTRING(int n_uchars, const universal_char *uchars_ptr); | |
127 | /** Construct a string from a C string | |
128 | * | |
129 | * @param chars_ptr pointer to the source string. A NULL pointer | |
130 | * will result in an empty UNIVERSAL_CHARSTRING. | |
131 | * | |
132 | * All characters in the string will have group==plane==row==0 | |
133 | */ | |
134 | UNIVERSAL_CHARSTRING(const char *chars_ptr); | |
135 | /** Construct a string from a known number of single-byte characters | |
136 | * | |
137 | * @param n_chars number of characters | |
138 | * @param chars_ptr pointer to the source string. | |
139 | * | |
140 | * @pre if n_chars > 0, chars_ptr must point to a valid string, | |
141 | * else an access violation will occur. | |
142 | * | |
143 | * All characters in the string will have group==plane==row==0 | |
144 | */ | |
145 | UNIVERSAL_CHARSTRING(int n_chars, const char *chars_ptr); | |
146 | /** Construct a copy of another CHARSTRING | |
147 | * | |
148 | * @param other_value | |
149 | */ | |
150 | UNIVERSAL_CHARSTRING(const CHARSTRING& other_value); | |
151 | /** Construct a string containing a single CHARSTRING_ELEMENT | |
152 | * | |
153 | * @param other_value | |
154 | */ | |
155 | UNIVERSAL_CHARSTRING(const CHARSTRING_ELEMENT& other_value); | |
156 | /** Copy constructor | |
157 | * | |
158 | * @param other_value | |
159 | */ | |
160 | UNIVERSAL_CHARSTRING(const UNIVERSAL_CHARSTRING& other_value); | |
161 | /** Construct a string containing a single UNIVERSAL_CHARSTRING_ELEMENT | |
162 | * | |
163 | * @param other_value | |
164 | */ | |
165 | UNIVERSAL_CHARSTRING(const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
166 | ||
167 | ~UNIVERSAL_CHARSTRING(); | |
168 | void clean_up(); | |
169 | ||
170 | UNIVERSAL_CHARSTRING& operator=(const universal_char& other_value); | |
171 | UNIVERSAL_CHARSTRING& operator=(const char* other_value); | |
172 | UNIVERSAL_CHARSTRING& operator=(const CHARSTRING& other_value); | |
173 | UNIVERSAL_CHARSTRING& operator=(const CHARSTRING_ELEMENT& other_value); | |
174 | UNIVERSAL_CHARSTRING& operator=(const UNIVERSAL_CHARSTRING& other_value); | |
175 | UNIVERSAL_CHARSTRING& operator=(const UNIVERSAL_CHARSTRING_ELEMENT& | |
176 | other_value); | |
177 | ||
178 | /** @name Comparison operators | |
179 | * @{ | |
180 | */ | |
181 | boolean operator==(const universal_char& other_value) const; | |
182 | boolean operator==(const char* other_value) const; | |
183 | boolean operator==(const CHARSTRING& other_value) const; | |
184 | boolean operator==(const CHARSTRING_ELEMENT& other_value) const; | |
185 | boolean operator==(const UNIVERSAL_CHARSTRING& other_value) const; | |
186 | boolean operator==(const UNIVERSAL_CHARSTRING_ELEMENT& | |
187 | other_value) const; | |
188 | ||
189 | boolean operator!=(const universal_char& other_value) const | |
190 | { return !(*this == other_value); } | |
191 | boolean operator!=(const char* other_value) const | |
192 | { return !(*this == other_value); } | |
193 | boolean operator!=(const CHARSTRING& other_value) const | |
194 | { return !(*this == other_value); } | |
195 | boolean operator!=(const CHARSTRING_ELEMENT& other_value) const | |
196 | { return !(*this == other_value); } | |
197 | boolean operator!=(const UNIVERSAL_CHARSTRING& other_value) const | |
198 | { return !(*this == other_value); } | |
199 | boolean operator!=(const UNIVERSAL_CHARSTRING_ELEMENT& | |
200 | other_value) const { return !(*this == other_value); } | |
201 | /** @} */ | |
202 | ||
203 | /** @name Concatenation | |
204 | * | |
205 | * | |
206 | * @{ | |
207 | */ | |
208 | UNIVERSAL_CHARSTRING operator+(const universal_char& other_value) const; | |
209 | UNIVERSAL_CHARSTRING operator+(const char* other_value) const; | |
210 | UNIVERSAL_CHARSTRING operator+(const CHARSTRING& other_value) const; | |
211 | UNIVERSAL_CHARSTRING operator+(const CHARSTRING_ELEMENT& other_value) const; | |
212 | UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING& other_value) const; | |
213 | UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING_ELEMENT& | |
214 | other_value) const; | |
215 | /** @} */ | |
216 | ||
217 | /** @name Rotation | |
218 | * @{ */ | |
219 | UNIVERSAL_CHARSTRING operator<<=(int rotate_count) const; | |
220 | UNIVERSAL_CHARSTRING operator<<=(const INTEGER& rotate_count) const; | |
221 | UNIVERSAL_CHARSTRING operator>>=(int rotate_count) const; | |
222 | UNIVERSAL_CHARSTRING operator>>=(const INTEGER& rotate_count) const; | |
223 | /** @} */ | |
224 | ||
225 | /** @name Indexing | |
226 | * @{ */ | |
227 | UNIVERSAL_CHARSTRING_ELEMENT operator[](int index_value); | |
228 | UNIVERSAL_CHARSTRING_ELEMENT operator[](const INTEGER& index_value); | |
229 | const UNIVERSAL_CHARSTRING_ELEMENT operator[](int index_value) const; | |
230 | const UNIVERSAL_CHARSTRING_ELEMENT operator[] | |
231 | (const INTEGER& index_value) const; | |
232 | /** @} */ | |
233 | ||
234 | operator const universal_char*() const; | |
235 | ||
236 | inline boolean is_bound() const { | |
237 | if (charstring) return cstr.is_bound(); | |
238 | else return val_ptr != NULL; } | |
239 | inline boolean is_value() const { | |
240 | if (charstring) return cstr.is_value(); | |
241 | else return val_ptr != NULL; } | |
242 | inline void must_bound(const char *err_msg) const | |
243 | { if (charstring) cstr.must_bound(err_msg); | |
244 | else if (val_ptr == NULL) TTCN_error("%s", err_msg); } | |
245 | ||
246 | int lengthof() const; | |
247 | ||
248 | void dump() const; | |
249 | ||
250 | private: | |
251 | // convert this string to character string for pattern matching: ([A-P]{8})* | |
252 | char* convert_to_regexp_form() const; | |
253 | ||
254 | /* returns the CHARSTRING representation of this. Quadruples are converted | |
255 | into the form: \q{group,plane,row,cell} */ | |
256 | CHARSTRING get_stringRepr_for_pattern() const; | |
257 | ||
258 | void convert_cstr_to_uni(); | |
259 | //checks if an valid BOM is at the head of the string. Returns the length of BOM | |
260 | int check_BOM(CharCoding::CharCodingType expected_coding, unsigned int length, | |
261 | const unsigned char* ostr); | |
262 | ||
263 | /** Returns the universal charstring in the format a string would appear in C or TTCN-3 code. | |
264 | * Inserts double quotation marks to the begining and end of the string and | |
265 | * doubles the backlsashes in escaped characters. | |
266 | * Used for JSON encoding. | |
267 | * | |
268 | * @param p_buf The buffer containing the universal charstring in UTF-8 encoding | |
269 | * | |
270 | * Example: "He said\nhis name was \"Al\"." -> "\"He said\\nhis name was \\\"Al\\\".\"" | |
271 | * Example2: char(0, 0, 1, 113) in TTCN-3 -> "\u0171" | |
272 | * @note The returned character buffer needs to be freed after use. */ | |
273 | char* to_JSON_string(const TTCN_Buffer& p_buf) const; | |
274 | ||
275 | /** Converts the universal charstring from JSON string format to normal format. | |
276 | * The double quotation marks from the beginning and end of the JSON string are | |
277 | * removed and double-escaped characters are changed to simple-escaped ones. | |
278 | * JSON characters stored as \u + 4 hex digits are converted to the characters | |
279 | * they represent. | |
280 | * Returns false if any invalid characters were found, otherwise true. | |
281 | * Used for JSON decoding. | |
282 | * | |
283 | * Example: "\"He said\\nhis name was \\\"Al\\\".\"" -> "He said\nhis name was \"Al\"." | |
284 | * Example2: "\u0061" -> "a" | |
285 | * | |
286 | * @param check_quotes turn the checking of double quotes (mentioned above) on or off */ | |
287 | boolean from_JSON_string(boolean check_quotes); | |
288 | ||
289 | /** Checks the coding of the characters in the received buffer, if they are | |
290 | * encoded in UTF-8 this function will decode them. | |
291 | * @return The universal charstring containing the decoded characters */ | |
292 | static UNIVERSAL_CHARSTRING from_UTF8_buffer(TTCN_Buffer& p_buff); | |
293 | ||
294 | public: | |
295 | ||
296 | #ifdef TITAN_RUNTIME_2 | |
297 | boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const UNIVERSAL_CHARSTRING*>(other_value)); } | |
298 | void set_value(const Base_Type* other_value) { *this = *(static_cast<const UNIVERSAL_CHARSTRING*>(other_value)); } | |
299 | Base_Type* clone() const { return new UNIVERSAL_CHARSTRING(*this); } | |
300 | const TTCN_Typedescriptor_t* get_descriptor() const { return &UNIVERSAL_CHARSTRING_descr_; } | |
301 | #else | |
302 | inline boolean is_present() const { return is_bound(); } | |
303 | #endif | |
304 | ||
305 | void log() const; | |
306 | ||
307 | /** Initializes this object with a module parameter value or concatenates a module | |
308 | * parameter value to the end of this string. | |
309 | * @note UFT-8 strings (whose characters were not in quadruple notation) will | |
310 | * be decoded */ | |
311 | void set_param(Module_Param& param); | |
3abe9331 | 312 | Module_Param* get_param(Module_Param_Name& param_name) const; |
970ed795 EL |
313 | |
314 | void encode_text(Text_Buf& text_buf) const; | |
315 | void decode_text(Text_Buf& text_buf); | |
316 | ||
317 | void encode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, | |
318 | TTCN_EncDec::coding_t p_coding, ...) const; | |
319 | void decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& p_buf, | |
320 | TTCN_EncDec::coding_t p_coding, ...); | |
321 | ||
322 | ASN_BER_TLV_t* BER_encode_TLV(const TTCN_Typedescriptor_t& p_td, | |
323 | unsigned p_coding) const; | |
324 | ||
325 | boolean BER_decode_TLV(const TTCN_Typedescriptor_t& p_td, | |
326 | const ASN_BER_TLV_t& p_tlv, unsigned L_form); | |
327 | ||
a38c6d4c | 328 | int TEXT_encode(const TTCN_Typedescriptor_t&, |
329 | TTCN_Buffer&) const; | |
330 | int TEXT_decode(const TTCN_Typedescriptor_t&, TTCN_Buffer&, Limit_Token_List&, | |
331 | boolean no_err=FALSE, boolean first_call=TRUE); | |
af710487 | 332 | int XER_encode(const XERdescriptor_t&, TTCN_Buffer&, unsigned int, int, embed_values_enc_struct_t*) const; |
333 | int XER_decode(const XERdescriptor_t&, XmlReaderWrap& reader, unsigned int, embed_values_dec_struct_t*); | |
970ed795 EL |
334 | /** Decodes UTF-8 into the internal representation (UCS4-BE) |
335 | * | |
336 | * @param n_octets number of UTF-8 bytes (not characters) | |
337 | * @param octets_ptr pointer to the bytes | |
338 | * | |
339 | * @pre the UNIVERSAL_CHARSTRING is unbound or clean_up() has been called | |
340 | * (otherwise memory leak will occur) | |
341 | */ | |
342 | void decode_utf8(int n_octets, const unsigned char *octets_ptr, | |
343 | CharCoding::CharCodingType expected_coding = CharCoding::UTF_8, bool checkBOM = false); | |
344 | void decode_utf16(int n_octets, const unsigned char *octets_ptr, | |
345 | CharCoding::CharCodingType expected_coding); | |
346 | void decode_utf32(int n_octets, const unsigned char *octets_ptr, | |
347 | CharCoding::CharCodingType expected_coding); | |
348 | /** Appends the content of this string to the supplied buffer, in UTF-8 | |
349 | * | |
350 | * @param[out] buf buffer to receive the encoded result | |
351 | */ | |
352 | void encode_utf8(TTCN_Buffer& buf, bool addBOM = false) const; | |
353 | void encode_utf16(TTCN_Buffer& buf, CharCoding::CharCodingType expected_coding) const; | |
354 | void encode_utf32(TTCN_Buffer& buf, CharCoding::CharCodingType expected_coding) const; | |
355 | ||
356 | /** Encodes accordingly to the JSON encoding rules. | |
357 | * The universal charstring will be encoded with UTF-8 before being added to | |
358 | * the JSON code. | |
359 | * Returns the length of the encoded data. | |
360 | * @note Since JSON has its own set of escaped characters, the ones in the | |
361 | * universal charstring need to be double-escaped. */ | |
362 | int JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&) const; | |
363 | ||
364 | /** Decodes accordingly to the JSON encoding rules. | |
365 | * Returns the length of the decoded data. */ | |
366 | int JSON_decode(const TTCN_Typedescriptor_t&, JSON_Tokenizer&, boolean); | |
367 | ||
368 | private: | |
369 | #ifdef TITAN_RUNTIME_2 | |
370 | virtual int encode_raw(TTCN_Buffer& p_buf) const; | |
3f84031e | 371 | /** Encodes this universal charstring with UTF-8 and adds the result to the end |
372 | * of a JSON buffer as raw data. | |
373 | * Used during the negative testing of the JSON encoder. | |
374 | * @return The number of bytes added. */ | |
375 | int JSON_encode_negtest_raw(JSON_Tokenizer&) const; | |
970ed795 EL |
376 | #endif |
377 | }; | |
378 | ||
379 | class UNIVERSAL_CHARSTRING_ELEMENT { | |
380 | friend class UNIVERSAL_CHARSTRING; | |
381 | friend UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value, | |
382 | const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
383 | friend boolean operator==(const char *string_value, | |
384 | const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
385 | friend UNIVERSAL_CHARSTRING operator+(const char *string_value, | |
386 | const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
387 | friend UNIVERSAL_CHARSTRING CHARSTRING::operator+ | |
388 | (const UNIVERSAL_CHARSTRING_ELEMENT& other_value) const; | |
389 | ||
390 | boolean bound_flag; | |
391 | UNIVERSAL_CHARSTRING& str_val; | |
392 | int uchar_pos; | |
393 | ||
394 | public: | |
395 | UNIVERSAL_CHARSTRING_ELEMENT(boolean par_bound_flag, | |
396 | UNIVERSAL_CHARSTRING& par_str_val, int par_uchar_pos); | |
397 | ||
398 | UNIVERSAL_CHARSTRING_ELEMENT& operator=(const universal_char& other_value); | |
399 | UNIVERSAL_CHARSTRING_ELEMENT& operator=(const char* other_value); | |
400 | UNIVERSAL_CHARSTRING_ELEMENT& operator=(const CHARSTRING& other_value); | |
401 | UNIVERSAL_CHARSTRING_ELEMENT& operator= | |
402 | (const CHARSTRING_ELEMENT& other_value); | |
403 | UNIVERSAL_CHARSTRING_ELEMENT& operator= | |
404 | (const UNIVERSAL_CHARSTRING& other_value); | |
405 | UNIVERSAL_CHARSTRING_ELEMENT& operator= | |
406 | (const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
407 | ||
408 | boolean operator==(const universal_char& other_value) const; | |
409 | boolean operator==(const char* other_value) const; | |
410 | boolean operator==(const CHARSTRING& other_value) const; | |
411 | boolean operator==(const CHARSTRING_ELEMENT& other_value) const; | |
412 | boolean operator==(const UNIVERSAL_CHARSTRING& other_value) const; | |
413 | boolean operator==(const UNIVERSAL_CHARSTRING_ELEMENT& | |
414 | other_value) const; | |
415 | ||
416 | boolean operator!=(const universal_char& other_value) const | |
417 | { return !(*this == other_value); } | |
418 | boolean operator!=(const char* other_value) const | |
419 | { return !(*this == other_value); } | |
420 | boolean operator!=(const CHARSTRING& other_value) const | |
421 | { return !(*this == other_value); } | |
422 | boolean operator!=(const CHARSTRING_ELEMENT& other_value) const | |
423 | { return !(*this == other_value); } | |
424 | boolean operator!=(const UNIVERSAL_CHARSTRING& other_value) const | |
425 | { return !(*this == other_value); } | |
426 | boolean operator!=(const UNIVERSAL_CHARSTRING_ELEMENT& | |
427 | other_value) const { return !(*this == other_value); } | |
428 | ||
429 | UNIVERSAL_CHARSTRING operator+(const universal_char& other_value) const; | |
430 | UNIVERSAL_CHARSTRING operator+(const char* other_value) const; | |
431 | UNIVERSAL_CHARSTRING operator+(const CHARSTRING& other_value) const; | |
432 | UNIVERSAL_CHARSTRING operator+(const CHARSTRING_ELEMENT& other_value) const; | |
433 | UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING& other_value) const; | |
434 | UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING_ELEMENT& | |
435 | other_value) const; | |
436 | ||
437 | inline boolean is_bound() const { return bound_flag; } | |
438 | inline boolean is_present() const { return bound_flag; } | |
439 | inline boolean is_value() const { return bound_flag; } | |
440 | inline void must_bound(const char *err_msg) const | |
441 | { if (!bound_flag) TTCN_error("%s", err_msg); } | |
442 | ||
443 | const universal_char& get_uchar() const; | |
444 | void log() const; | |
445 | }; | |
446 | ||
447 | extern boolean operator==(const universal_char& uchar_value, | |
448 | const UNIVERSAL_CHARSTRING& other_value); | |
449 | extern boolean operator==(const universal_char& uchar_value, | |
450 | const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
451 | ||
452 | inline boolean operator!=(const universal_char& uchar_value, | |
453 | const UNIVERSAL_CHARSTRING& other_value) | |
454 | { | |
455 | return !(uchar_value == other_value); | |
456 | } | |
457 | ||
458 | inline boolean operator!=(const universal_char& uchar_value, | |
459 | const UNIVERSAL_CHARSTRING_ELEMENT& other_value) | |
460 | { | |
461 | return !(uchar_value == other_value); | |
462 | } | |
463 | ||
464 | inline boolean operator!=(const universal_char& uchar_value, | |
465 | const universal_char& other_value) | |
466 | { | |
467 | return !(uchar_value == other_value); | |
468 | } | |
469 | ||
470 | extern UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value, | |
471 | const UNIVERSAL_CHARSTRING& other_value); | |
472 | extern UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value, | |
473 | const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
474 | ||
475 | extern boolean operator==(const char *string_value, | |
476 | const UNIVERSAL_CHARSTRING& other_value); | |
477 | extern boolean operator==(const char *string_value, | |
478 | const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
479 | ||
480 | inline boolean operator!=(const char *string_value, | |
481 | const UNIVERSAL_CHARSTRING& other_value) | |
482 | { | |
483 | return !(string_value == other_value); | |
484 | } | |
485 | ||
486 | inline boolean operator!=(const char *string_value, | |
487 | const UNIVERSAL_CHARSTRING_ELEMENT& other_value) | |
488 | { | |
489 | return !(string_value == other_value); | |
490 | } | |
491 | ||
492 | extern UNIVERSAL_CHARSTRING operator+(const char *string_value, | |
493 | const UNIVERSAL_CHARSTRING& other_value); | |
494 | extern UNIVERSAL_CHARSTRING operator+(const char *string_value, | |
495 | const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
496 | ||
497 | ||
498 | class UNIVERSAL_CHARSTRING_template : public Restricted_Length_Template { | |
499 | private: | |
500 | UNIVERSAL_CHARSTRING single_value; | |
501 | CHARSTRING* pattern_string; | |
502 | union { | |
503 | struct { | |
504 | unsigned int n_values; | |
505 | UNIVERSAL_CHARSTRING_template *list_value; | |
506 | } value_list; | |
507 | struct { | |
508 | boolean min_is_set, max_is_set; | |
509 | universal_char min_value, max_value; | |
510 | } value_range; | |
511 | mutable struct { | |
512 | boolean regexp_init; | |
513 | regex_t posix_regexp; | |
514 | } pattern_value; | |
515 | }; | |
516 | ||
517 | void copy_template(const CHARSTRING_template& other_value); | |
518 | void copy_template(const UNIVERSAL_CHARSTRING_template& other_value); | |
519 | ||
520 | public: | |
521 | UNIVERSAL_CHARSTRING_template(); | |
522 | UNIVERSAL_CHARSTRING_template(template_sel other_value); | |
523 | UNIVERSAL_CHARSTRING_template(const CHARSTRING& other_value); | |
524 | UNIVERSAL_CHARSTRING_template(const UNIVERSAL_CHARSTRING& other_value); | |
525 | UNIVERSAL_CHARSTRING_template(const CHARSTRING_ELEMENT& other_value); | |
526 | UNIVERSAL_CHARSTRING_template | |
527 | (const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
528 | UNIVERSAL_CHARSTRING_template(const OPTIONAL<CHARSTRING>& other_value); | |
529 | UNIVERSAL_CHARSTRING_template | |
530 | (const OPTIONAL<UNIVERSAL_CHARSTRING>& other_value); | |
531 | UNIVERSAL_CHARSTRING_template | |
532 | (const CHARSTRING_template& other_value); | |
533 | UNIVERSAL_CHARSTRING_template | |
534 | (const UNIVERSAL_CHARSTRING_template& other_value); | |
535 | UNIVERSAL_CHARSTRING_template(template_sel p_sel, const CHARSTRING& p_str); | |
536 | ||
537 | ~UNIVERSAL_CHARSTRING_template(); | |
538 | void clean_up(); | |
539 | ||
540 | UNIVERSAL_CHARSTRING_template& operator=(template_sel other_value); | |
541 | UNIVERSAL_CHARSTRING_template& operator=(const CHARSTRING& other_value); | |
542 | UNIVERSAL_CHARSTRING_template& operator= | |
543 | (const UNIVERSAL_CHARSTRING& other_value); | |
544 | UNIVERSAL_CHARSTRING_template& operator= | |
545 | (const CHARSTRING_ELEMENT& other_value); | |
546 | UNIVERSAL_CHARSTRING_template& operator= | |
547 | (const UNIVERSAL_CHARSTRING_ELEMENT& other_value); | |
548 | UNIVERSAL_CHARSTRING_template& operator= | |
549 | (const OPTIONAL<CHARSTRING>& other_value); | |
550 | UNIVERSAL_CHARSTRING_template& operator= | |
551 | (const OPTIONAL<UNIVERSAL_CHARSTRING>& other_value); | |
552 | UNIVERSAL_CHARSTRING_template& operator= | |
553 | (const CHARSTRING_template& other_value); | |
554 | UNIVERSAL_CHARSTRING_template& operator= | |
555 | (const UNIVERSAL_CHARSTRING_template& other_value); | |
556 | ||
557 | UNIVERSAL_CHARSTRING_ELEMENT operator[](int index_value); | |
558 | UNIVERSAL_CHARSTRING_ELEMENT operator[](const INTEGER& index_value); | |
559 | const UNIVERSAL_CHARSTRING_ELEMENT operator[](int index_value) const; | |
560 | const UNIVERSAL_CHARSTRING_ELEMENT operator[] | |
561 | (const INTEGER& index_value) const; | |
562 | ||
3abe9331 | 563 | boolean match(const UNIVERSAL_CHARSTRING& other_value, boolean legacy = FALSE) const; |
970ed795 EL |
564 | const UNIVERSAL_CHARSTRING& valueof() const; |
565 | ||
566 | int lengthof() const; | |
567 | ||
568 | void set_type(template_sel template_type, unsigned int list_length = 0); | |
569 | UNIVERSAL_CHARSTRING_template& list_item(unsigned int list_index); | |
570 | ||
571 | void set_min(const UNIVERSAL_CHARSTRING& min_value); | |
572 | void set_max(const UNIVERSAL_CHARSTRING& max_value); | |
573 | ||
574 | void log() const; | |
3abe9331 | 575 | void log_match(const UNIVERSAL_CHARSTRING& match_value, boolean legacy = FALSE) const; |
970ed795 EL |
576 | |
577 | void set_param(Module_Param& param); | |
3abe9331 | 578 | Module_Param* get_param(Module_Param_Name& param_name) const; |
970ed795 EL |
579 | |
580 | void encode_text(Text_Buf& text_buf) const; | |
581 | void decode_text(Text_Buf& text_buf); | |
582 | ||
3abe9331 | 583 | boolean is_present(boolean legacy = FALSE) const; |
584 | boolean match_omit(boolean legacy = FALSE) const; | |
970ed795 EL |
585 | |
586 | #ifdef TITAN_RUNTIME_2 | |
587 | void valueofv(Base_Type* value) const { *(static_cast<UNIVERSAL_CHARSTRING*>(value)) = valueof(); } | |
588 | void set_value(template_sel other_value) { *this = other_value; } | |
589 | void copy_value(const Base_Type* other_value) { *this = *(static_cast<const UNIVERSAL_CHARSTRING*>(other_value)); } | |
590 | Base_Template* clone() const { return new UNIVERSAL_CHARSTRING_template(*this); } | |
591 | const TTCN_Typedescriptor_t* get_descriptor() const { return &UNIVERSAL_CHARSTRING_descr_; } | |
3abe9331 | 592 | boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const UNIVERSAL_CHARSTRING*>(other_value)), legacy); } |
593 | void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const UNIVERSAL_CHARSTRING*>(match_value)), legacy); } | |
970ed795 | 594 | #else |
3abe9331 | 595 | void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const; |
970ed795 EL |
596 | #endif |
597 | ||
598 | const CHARSTRING& get_single_value() const; | |
599 | }; | |
600 | ||
601 | typedef UNIVERSAL_CHARSTRING BMPString; | |
602 | typedef UNIVERSAL_CHARSTRING UniversalString; | |
603 | typedef UNIVERSAL_CHARSTRING UTF8String; | |
604 | typedef UNIVERSAL_CHARSTRING TeletexString; | |
605 | typedef TeletexString T61String; | |
606 | typedef UNIVERSAL_CHARSTRING VideotexString; | |
607 | typedef UNIVERSAL_CHARSTRING GraphicString; | |
608 | typedef UNIVERSAL_CHARSTRING GeneralString; | |
609 | ||
610 | typedef UNIVERSAL_CHARSTRING_template BMPString_template; | |
611 | typedef UNIVERSAL_CHARSTRING_template UniversalString_template; | |
612 | typedef UNIVERSAL_CHARSTRING_template UTF8String_template; | |
613 | typedef UNIVERSAL_CHARSTRING_template TeletexString_template; | |
614 | typedef TeletexString_template T61String_template; | |
615 | typedef UNIVERSAL_CHARSTRING_template VideotexString_template; | |
616 | typedef UNIVERSAL_CHARSTRING_template GraphicString_template; | |
617 | typedef UNIVERSAL_CHARSTRING_template GeneralString_template; | |
618 | ||
619 | typedef GraphicString ObjectDescriptor; | |
620 | typedef GraphicString_template ObjectDescriptor_template; | |
621 | ||
622 | OCTETSTRING TTCN_TeletexString_2_ISO2022(const TeletexString& p_s); | |
623 | TeletexString TTCN_ISO2022_2_TeletexString(const OCTETSTRING& p_os); | |
624 | OCTETSTRING TTCN_VideotexString_2_ISO2022(const VideotexString& p_s); | |
625 | VideotexString TTCN_ISO2022_2_VideotexString(const OCTETSTRING& p_os); | |
626 | OCTETSTRING TTCN_GraphicString_2_ISO2022(const GraphicString& p_s); | |
627 | GraphicString TTCN_ISO2022_2_GraphicString(const OCTETSTRING& p_os); | |
628 | OCTETSTRING TTCN_GeneralString_2_ISO2022(const GeneralString& p_s); | |
629 | GeneralString TTCN_ISO2022_2_GeneralString(const OCTETSTRING& p_os); | |
630 | ||
631 | #endif |