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