CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
regex.h
1
2#ifndef _aspose_system_regex_h_
3#define _aspose_system_regex_h_
4
5#include <system/text/regularexpressions/match_collection.h>
6#include <system/text/regularexpressions/match.h>
7#include <system/exceptions.h>
8#include <system/multicast_delegate.h>
9
10namespace System { namespace Text { namespace RegularExpressions {
11
12namespace Detail
13{
14 class RegexHolder;
15}
16
18using MatchEvaluator = System::MulticastDelegate<System::String(MatchPtr)>;
19
20class Regex;
23class Match;
24
29class ASPOSECPP_SHARED_CLASS Regex: public Object
30{
31 friend class Match;
32public:
34 static TimeSpan ASPOSECPP_SHARED_API InfiniteMatchTimeout;
35
37 ASPOSECPP_SHARED_API Regex();
40 ASPOSECPP_SHARED_API Regex(const String& pattern);
44 ASPOSECPP_SHARED_API Regex(const String& pattern, RegexOptions options);
49 ASPOSECPP_SHARED_API Regex(const String& pattern, RegexOptions options, TimeSpan matchTimeout);
50
53 TimeSpan get_MatchTimeout() { return m_matchTimeout; }
56 RegexOptions get_Options() { return m_options; }
60
65 ASPOSECPP_SHARED_API bool IsMatch(const String& input, int startat = 0);
66
70 ASPOSECPP_SHARED_API MatchPtr Match(const String& input);
76 ASPOSECPP_SHARED_API MatchPtr Match(const String& input, int startat, int length = 0);
77
82 ASPOSECPP_SHARED_API MatchCollectionPtr Matches(const String& input, int startat = 0);
83
88 ASPOSECPP_SHARED_API String Replace(const String& input, const String& replacement);
93 ASPOSECPP_SHARED_API String Replace(const String& input, const char_t* replacement);
94
100 static ASPOSECPP_SHARED_API String Replace(const String& input, const char_t* pattern, const char_t* replacement);
106 static ASPOSECPP_SHARED_API String Replace(const String& input, const String& pattern, const char_t* replacement);
107
112 ASPOSECPP_SHARED_API String Replace(const String& input, const MatchEvaluator& evaluator);
118 ASPOSECPP_SHARED_API String Replace(const String& input, const MatchEvaluator& evaluator, int count);
125 ASPOSECPP_SHARED_API String Replace(const String& input, const MatchEvaluator& evaluator, int count, int startat);
126
133 ASPOSECPP_SHARED_API static String Replace(const String& input, const String& pattern, const MatchEvaluator& evaluator, RegexOptions options);
134
135
142 static ASPOSECPP_SHARED_API String Replace(const String& input, const String& pattern, const String& replacement, RegexOptions options);
144 ASPOSECPP_SHARED_API String Replace(const String& input, const String& replacement, int count);
146 ASPOSECPP_SHARED_API String Replace(const String& input, const String& replacement, int count, int startat);
147
151 ASPOSECPP_SHARED_API ArrayPtr<String> Split(const String& input);
156 ASPOSECPP_SHARED_API ArrayPtr<String> Split(const String& input, int count);
164 ASPOSECPP_SHARED_API ArrayPtr<String> Split(const String& input, int count, int startat);
165
168 String ToString() const override { return m_pattern; }
169
170 // static methods
178 static ASPOSECPP_SHARED_API bool IsMatch(const String& input, const String& pattern,
180 TimeSpan matchTimeout = InfiniteMatchTimeout,
181 int startat = 0);
190 static ASPOSECPP_SHARED_API MatchPtr Match(const String& input, const String& pattern,
192 TimeSpan matchTimeout = InfiniteMatchTimeout,
193 int startat = 0, int length = 0);
202 static ASPOSECPP_SHARED_API MatchCollectionPtr Matches(const String& input, const String& pattern,
204 TimeSpan matchTimeout = InfiniteMatchTimeout,
205 int startat = 0, int length = 0);
206
212 static ASPOSECPP_SHARED_API String Replace(const String& input, const String& pattern, const String& replacement);
218 static ASPOSECPP_SHARED_API String Replace(const String& input, const String& pattern, const MatchEvaluator& evaluator);
219
226 static ASPOSECPP_SHARED_API ArrayPtr<String> Split(const String& input, const String& pattern,
228 TimeSpan matchTimeout = InfiniteMatchTimeout);
236 static ASPOSECPP_SHARED_API ArrayPtr<String> Split(const String& input, const String& pattern, int count,
238 TimeSpan matchTimeout = InfiniteMatchTimeout);
239
243 static ASPOSECPP_SHARED_API String Escape(const String& str);
247 static ASPOSECPP_SHARED_API String Unescape(const String& str);
248
249protected:
251 ASPOSECPP_SHARED_API ~Regex() override;
252
253private:
258 MatchPtr Match(const UStringPtr& source, int index);
259
263 static bool IsMetachar(char_t ch);
264
266 String m_pattern;
268 RegexOptions m_options;
270 TimeSpan m_matchTimeout;
272 std::unique_ptr<Detail::RegexHolder> m_regex_holder;
273
275 static const unsigned char s_category[];
276
277#ifdef __DBG_FOR_EACH_MEMBER
278public:
281 void DBG_for_each_member(DBG::for_each_member_visitor &visitor) const override
282 {
283 Object::DBG_for_each_member(visitor);
284 visitor.add_self(this);
285 }
286
289 const char* DBG_class_name() const override { return "Regex"; }
290#endif
291};
292
293}}} // namespace System::Text::RegularExpressions
294
295#endif // _aspose_system_regex_h_
296
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
Single match of regexp over string. Objects of this class should only be allocated using System::Make...
Definition: match.h:56
Regular expression that follows C#-like syntax. Objects of this class should only be allocated using ...
Definition: regex.h:30
static String Escape(const String &str)
Escapes special characters to use string as part of the pattern.
static String Replace(const String &input, const String &pattern, const MatchEvaluator &evaluator, RegexOptions options)
Replaces all matches in string with delegate-generated replacement strings (static function).
String Replace(const String &input, const String &replacement)
Replaces all matches of regex in string with replacement string.
String Replace(const String &input, const String &replacement, int count)
Replaces substrings in string. Not implemented.
ArrayPtr< String > Split(const String &input, int count, int startat)
Splits an input string a specified maximum number of times into an array of substrings,...
MatchPtr Match(const String &input, int startat, int length=0)
Matches regex against string.
String Replace(const String &input, const char_t *replacement)
Replaces all matches of regex in string with replacement string.
TimeSpan get_MatchTimeout()
Gets matching timeout.
Definition: regex.h:53
bool IsMatch(const String &input, int startat=0)
Matches regex against string.
static String Unescape(const String &str)
Unescapes special characters in string used as part of the pattern.
RegexOptions get_Options()
Gets regex options.
Definition: regex.h:56
String ToString() const override
Converts regex to string.
Definition: regex.h:168
String Replace(const String &input, const MatchEvaluator &evaluator, int count, int startat)
Replaces all matches in string with delegate-generated replacement strings.
bool get_RightToLeft()
Checks if matching is done in right-to-left mode.
Definition: regex.h:59
MatchCollectionPtr Matches(const String &input, int startat=0)
Gets all matches of regex in given string by matching repeatedly.
static String Replace(const String &input, const String &pattern, const MatchEvaluator &evaluator)
Replaces regex matches.
static String Replace(const String &input, const String &pattern, const String &replacement)
Replaces regex matches.
static bool IsMatch(const String &input, const String &pattern, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout, int startat=0)
Checks if string matches pattern.
static ArrayPtr< String > Split(const String &input, const String &pattern, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout)
Splits string by regexp.
Regex(const String &pattern, RegexOptions options)
Constructor.
ArrayPtr< String > Split(const String &input)
Splits string by regex matches.
static MatchCollectionPtr Matches(const String &input, const String &pattern, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout, int startat=0, int length=0)
Gets all matches between string and pattern.
Regex()
Constructs empty regexp.
static MatchPtr Match(const String &input, const String &pattern, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout, int startat=0, int length=0)
Matches string and pattern.
String Replace(const String &input, const MatchEvaluator &evaluator, int count)
Replaces all matches in string with delegate-generated replacement strings.
Regex(const String &pattern)
Constructor.
static String Replace(const String &input, const char_t *pattern, const char_t *replacement)
Replaces all matches of regex in string with replacement string.
static ArrayPtr< String > Split(const String &input, const String &pattern, int count, RegexOptions options=RegexOptions::None, TimeSpan matchTimeout=InfiniteMatchTimeout)
Splits string by regexp.
String Replace(const String &input, const String &replacement, int count, int startat)
Replaces substrings in string. Not implemented.
ArrayPtr< String > Split(const String &input, int count)
Splits string by regex matches.
Regex(const String &pattern, RegexOptions options, TimeSpan matchTimeout)
Constructor.
static String Replace(const String &input, const String &pattern, const char_t *replacement)
Replaces all matches of regex in string with replacement string.
static TimeSpan InfiniteMatchTimeout
Special timeout value to disable match break by timeout.
Definition: regex.h:34
MatchPtr Match(const String &input)
Matches regex against string.
static String Replace(const String &input, const String &pattern, const String &replacement, RegexOptions options)
Replaces all matches of regex in string with replacement string.
String Replace(const String &input, const MatchEvaluator &evaluator)
Replaces all matches in string with delegate-generated replacement strings.
Represents a time interval. This type should be allocated on stack and passed to functions by value o...
Definition: timespan.h:59
@ Text
Defines color adjustment information for text.
System::SharedPtr< Regex > RegexPtr
Regex pointer.
Definition: match.h:44
std::shared_ptr< const UnicodeString > UStringPtr
Shared UnicodeString to avoid copying.
Definition: capture.h:15
System::MulticastDelegate< System::String(MatchPtr)> MatchEvaluator
Delegate type to evaluate match.
Definition: regex.h:18
RegexOptions
Regex options.
Definition: regex_options.h:10
@ RightToLeft
Right-to-left matching. Unsupported.
Definition: db_command.h:9