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