| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/object/ref_counted.h" |
| 34 |
#include "core/string/ustring.h" |
| 35 |
#include "core/templates/hash_map.h" |
| 36 |
#include "core/templates/vector.h" |
| 37 |
#include "core/variant/array.h" |
| 38 |
#include "core/variant/dictionary.h" |
| 39 |
#include "core/variant/typed_array.h" |
| 40 |
|
| 41 |
class RegExMatch : public RefCounted { |
| 42 |
GDCLASS(RegExMatch, RefCounted); |
| 43 |
|
| 44 |
struct Range { |
| 45 |
int start = 0; |
| 46 |
int end = 0; |
| 47 |
}; |
| 48 |
|
| 49 |
String subject; |
| 50 |
Vector<Range> data; |
| 51 |
HashMap<String, int> names; |
| 52 |
|
| 53 |
friend class RegEx; |
| 54 |
|
| 55 |
protected: |
| 56 |
static void _bind_methods(); |
| 57 |
|
| 58 |
int _find(const Variant &p_name) const; |
| 59 |
|
| 60 |
public: |
| 61 |
String get_subject() const; |
| 62 |
int get_group_count() const; |
| 63 |
Dictionary get_names() const; |
| 64 |
|
| 65 |
PackedStringArray get_strings() const; |
| 66 |
String get_string(const Variant &p_name) const; |
| 67 |
int get_start(const Variant &p_name) const; |
| 68 |
int get_end(const Variant &p_name) const; |
| 69 |
}; |
| 70 |
|
| 71 |
class RegEx : public RefCounted { |
| 72 |
GDCLASS(RegEx, RefCounted); |
| 73 |
|
| 74 |
void *general_ctx = nullptr; |
| 75 |
void *code = nullptr; |
| 76 |
String pattern; |
| 77 |
|
| 78 |
void _pattern_info(uint32_t what, void *where) const; |
| 79 |
|
| 80 |
int _sub(const String &p_subject, const String &p_replacement, int p_offset, int p_end, uint32_t p_flags, String &r_output) const; |
| 81 |
|
| 82 |
protected: |
| 83 |
static void _bind_methods(); |
| 84 |
|
| 85 |
#ifndef DISABLE_DEPRECATED |
| 86 |
static Ref<RegEx> _create_from_string_bind_compat_95212(const String &p_pattern); |
| 87 |
Error _compile_bind_compat_95212(const String &p_pattern); |
| 88 |
static void _bind_compatibility_methods(); |
| 89 |
#endif |
| 90 |
|
| 91 |
public: |
| 92 |
static Ref<RegEx> create_from_string(const String &p_pattern, bool p_show_error = true); |
| 93 |
|
| 94 |
void clear(); |
| 95 |
Error compile(const String &p_pattern, bool p_show_error = true); |
| 96 |
|
| 97 |
Ref<RegExMatch> search(const String &p_subject, int p_offset = 0, int p_end = -1) const; |
| 98 |
TypedArray<RegExMatch> search_all(const String &p_subject, int p_offset = 0, int p_end = -1) const; |
| 99 |
String sub(const String &p_subject, const String &p_replacement, bool p_all = false, int p_offset = 0, int p_end = -1) const; |
| 100 |
|
| 101 |
bool is_valid() const; |
| 102 |
String get_pattern() const; |
| 103 |
int get_group_count() const; |
| 104 |
PackedStringArray get_names() const; |
| 105 |
|
| 106 |
RegEx(); |
| 107 |
RegEx(const String &p_pattern); |
| 108 |
~RegEx(); |
| 109 |
}; |