Debian Codegraph @

modules/regex/regex.h

raw symbols SCIP
1 /**************************************************************************/
2 /* regex.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
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 };