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
11 * Szabo, Janos Zoltan – initial implementation
14 ******************************************************************************/
20 #include <sys/types.h>
23 * \defgroup TEXT TEXT-related stuff.
29 struct TTCN_TEXTdescriptor_values {
38 struct TTCN_TEXTdescriptor_bool {
39 const CHARSTRING* true_encode_token;
40 const Token_Match* true_decode_token;
41 const CHARSTRING* false_encode_token;
42 const Token_Match* false_decode_token;
45 struct TTCN_TEXTdescriptor_enum {
46 const CHARSTRING* encode_token;
47 const Token_Match* decode_token;
51 struct TTCN_TEXTdescriptor_param_values {
52 TTCN_TEXTdescriptor_values coding_params;
53 TTCN_TEXTdescriptor_values decoding_params;
56 union TTCN_TEXTdescriptor_union {
57 const TTCN_TEXTdescriptor_param_values* parameters;
58 const TTCN_TEXTdescriptor_bool* bool_values;
59 const TTCN_TEXTdescriptor_enum* enum_values;
62 struct TTCN_TEXTdescriptor_t {
63 const CHARSTRING* begin_encode;
64 const Token_Match* begin_decode;
65 const CHARSTRING* end_encode;
66 const Token_Match* end_decode;
67 const CHARSTRING* separator_encode;
68 const Token_Match* separator_decode;
69 const Token_Match* select_token;
70 TTCN_TEXTdescriptor_union val;
74 regex_t posix_regexp_begin; ///< regexp for the anchored match
75 regex_t posix_regexp_first; ///< regexp for floating match
76 const char *token_str; // not owned or freed by Token_Match
77 size_t fixed_len; ///< length of fixed string, or zero
78 boolean null_match; ///< true if the token_str was NULL or empty
80 Token_Match(const char *posix_str, boolean case_sensitive = TRUE,
81 boolean fixed = FALSE);
84 inline operator const char*() const { return token_str; }
85 /** Match anchored at the beginning
87 * @param buf the buffer to search
88 * @return length of the match or -1 if not matched
90 * It may call TTCN_error() in case of error, causing a DTE
92 int match_begin(TTCN_Buffer& buf) const;
95 * @param buf the buffer to search
96 * @return the offset where the match begins, or -1 if not matched
98 * It may call TTCN_error() in case of error, causing a DTE
100 int match_first(TTCN_Buffer& buf) const;
103 class Limit_Token_List {
105 size_t num_of_tokens;
107 const Token_Match **list;
110 const char* last_pos;
111 /// Copy constructor disabled
112 Limit_Token_List(const Limit_Token_List&);
113 /// Assignment disabled
114 Limit_Token_List& operator=(const Limit_Token_List&);
119 void add_token(const Token_Match *);
120 void remove_tokens(size_t);
121 int match(TTCN_Buffer&,size_t lim=0);
122 inline boolean has_token(size_t ml=0) const { return num_of_tokens != ml; }
125 extern const TTCN_TEXTdescriptor_t INTEGER_text_;
126 extern const TTCN_TEXTdescriptor_t BOOLEAN_text_;
127 extern const TTCN_TEXTdescriptor_t CHARSTRING_text_;
128 extern const TTCN_TEXTdescriptor_t BITSTRING_text_;
129 extern const TTCN_TEXTdescriptor_t HEXSTRING_text_;
130 extern const TTCN_TEXTdescriptor_t OCTETSTRING_text_;
131 extern const TTCN_TEXTdescriptor_t UNIVERSAL_CHARSTRING_text_;
133 /** @} end of TEXT group */