1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 ///////////////////////////////////////////////////////////////////////////////
13 #include <sys/types.h>
16 * \defgroup TEXT TEXT-related stuff.
22 struct TTCN_TEXTdescriptor_values {
31 struct TTCN_TEXTdescriptor_bool {
32 const CHARSTRING* true_encode_token;
33 const Token_Match* true_decode_token;
34 const CHARSTRING* false_encode_token;
35 const Token_Match* false_decode_token;
38 struct TTCN_TEXTdescriptor_enum {
39 const CHARSTRING* encode_token;
40 const Token_Match* decode_token;
44 struct TTCN_TEXTdescriptor_param_values {
45 TTCN_TEXTdescriptor_values coding_params;
46 TTCN_TEXTdescriptor_values decoding_params;
49 union TTCN_TEXTdescriptor_union {
50 const TTCN_TEXTdescriptor_param_values* parameters;
51 const TTCN_TEXTdescriptor_bool* bool_values;
52 const TTCN_TEXTdescriptor_enum* enum_values;
55 struct TTCN_TEXTdescriptor_t {
56 const CHARSTRING* begin_encode;
57 const Token_Match* begin_decode;
58 const CHARSTRING* end_encode;
59 const Token_Match* end_decode;
60 const CHARSTRING* separator_encode;
61 const Token_Match* separator_decode;
62 const Token_Match* select_token;
63 TTCN_TEXTdescriptor_union val;
67 regex_t posix_regexp_begin; ///< regexp for the anchored match
68 regex_t posix_regexp_first; ///< regexp for floating match
69 const char *token_str; // not owned or freed by Token_Match
70 size_t fixed_len; ///< length of fixed string, or zero
71 boolean null_match; ///< true if the token_str was NULL or empty
73 Token_Match(const char *posix_str, boolean case_sensitive = TRUE,
74 boolean fixed = FALSE);
77 inline operator const char*() const { return token_str; }
78 /** Match anchored at the beginning
80 * @param buf the buffer to search
81 * @return length of the match or -1 if not matched
83 * It may call TTCN_error() in case of error, causing a DTE
85 int match_begin(TTCN_Buffer& buf) const;
88 * @param buf the buffer to search
89 * @return the offset where the match begins, or -1 if not matched
91 * It may call TTCN_error() in case of error, causing a DTE
93 int match_first(TTCN_Buffer& buf) const;
96 class Limit_Token_List {
100 const Token_Match **list;
103 const char* last_pos;
104 /// Copy constructor disabled
105 Limit_Token_List(const Limit_Token_List&);
106 /// Assignment disabled
107 Limit_Token_List& operator=(const Limit_Token_List&);
112 void add_token(const Token_Match *);
113 void remove_tokens(size_t);
114 int match(TTCN_Buffer&,size_t lim=0);
115 inline boolean has_token(size_t ml=0) const { return num_of_tokens != ml; }
118 extern const TTCN_TEXTdescriptor_t INTEGER_text_;
119 extern const TTCN_TEXTdescriptor_t BOOLEAN_text_;
120 extern const TTCN_TEXTdescriptor_t CHARSTRING_text_;
121 extern const TTCN_TEXTdescriptor_t BITSTRING_text_;
122 extern const TTCN_TEXTdescriptor_t HEXSTRING_text_;
123 extern const TTCN_TEXTdescriptor_t OCTETSTRING_text_;
124 extern const TTCN_TEXTdescriptor_t UNIVERSAL_CHARSTRING_text_;
126 /** @} end of TEXT group */