Skip to content

Commit b4c6cc7

Browse files
[Core] Add case-insensitive String::containsn
1 parent 281fe39 commit b4c6cc7

23 files changed

+64
-32
lines changed

core/string/ustring.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ class String {
429429
_FORCE_INLINE_ bool is_empty() const { return length() == 0; }
430430
_FORCE_INLINE_ bool contains(const char *p_str) const { return find(p_str) != -1; }
431431
_FORCE_INLINE_ bool contains(const String &p_str) const { return find(p_str) != -1; }
432+
_FORCE_INLINE_ bool containsn(const char *p_str) const { return findn(p_str) != -1; }
433+
_FORCE_INLINE_ bool containsn(const String &p_str) const { return findn(p_str) != -1; }
432434

433435
// path functions
434436
bool is_absolute_path() const;

core/variant/variant_call.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,7 @@ static void _register_variant_builtin_methods() {
17071707
bind_string_method(sha256_buffer, sarray(), varray());
17081708
bind_string_method(is_empty, sarray(), varray());
17091709
bind_string_methodv(contains, static_cast<bool (String::*)(const String &) const>(&String::contains), sarray("what"), varray());
1710+
bind_string_methodv(containsn, static_cast<bool (String::*)(const String &) const>(&String::containsn), sarray("what"), varray());
17101711

17111712
bind_string_method(is_absolute_path, sarray(), varray());
17121713
bind_string_method(is_relative_path, sarray(), varray());

doc/classes/String.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
[/codeblock]
127127
</description>
128128
</method>
129-
<method name="contains" qualifiers="const" keywords="includes, has">
129+
<method name="contains" qualifiers="const">
130130
<return type="bool" />
131131
<param index="0" name="what" type="String" />
132132
<description>
@@ -142,7 +142,15 @@
142142
GD.Print("team".Contains("I")); // Prints false
143143
[/csharp]
144144
[/codeblocks]
145-
If you need to know where [param what] is within the string, use [method find].
145+
If you need to know where [param what] is within the string, use [method find]. See also [method containsn].
146+
</description>
147+
</method>
148+
<method name="containsn" qualifiers="const">
149+
<return type="bool" />
150+
<param index="0" name="what" type="String" />
151+
<description>
152+
Returns [code]true[/code] if the string contains [param what], [b]ignoring case[/b].
153+
If you need to know where [param what] is within the string, use [method findn]. See also [method contains].
146154
</description>
147155
</method>
148156
<method name="count" qualifiers="const">

doc/classes/StringName.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,15 @@
126126
GD.Print("team".Contains("I")); // Prints false
127127
[/csharp]
128128
[/codeblocks]
129-
If you need to know where [param what] is within the string, use [method find].
129+
If you need to know where [param what] is within the string, use [method find]. See also [method containsn].
130+
</description>
131+
</method>
132+
<method name="containsn" qualifiers="const">
133+
<return type="bool" />
134+
<param index="0" name="what" type="String" />
135+
<description>
136+
Returns [code]true[/code] if the string contains [param what], [b]ignoring case[/b].
137+
If you need to know where [param what] is within the string, use [method findn]. See also [method contains].
130138
</description>
131139
</method>
132140
<method name="count" qualifiers="const">

drivers/gles3/storage/config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Config::Config() {
157157
continue;
158158
}
159159

160-
if (renderer.findn(v) != -1) {
160+
if (renderer.containsn(v)) {
161161
use_depth_prepass = false;
162162
}
163163
}

editor/animation_track_editor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7122,7 +7122,7 @@ void AnimationTrackEditor::_pick_track_select_recursive(TreeItem *p_item, const
71227122
NodePath np = p_item->get_metadata(0);
71237123
Node *node = get_node_or_null(np);
71247124

7125-
if (node && !p_filter.is_empty() && ((String)node->get_name()).findn(p_filter) != -1) {
7125+
if (node && !p_filter.is_empty() && ((String)node->get_name()).containsn(p_filter)) {
71267126
p_select_candidates.push_back(node);
71277127
}
71287128

editor/connections_dialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ List<MethodInfo> ConnectDialog::_filter_method_list(const List<MethodInfo> &p_me
282282
List<MethodInfo> ret;
283283

284284
for (const MethodInfo &mi : p_methods) {
285-
if (!p_search_string.is_empty() && mi.name.findn(p_search_string) == -1) {
285+
if (!p_search_string.is_empty() && !mi.name.containsn(p_search_string)) {
286286
continue;
287287
}
288288

editor/debugger/debug_adapter/debug_adapter_parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class DebugAdapterParser : public Object {
5050
if (p_path.contains("\\")) {
5151
String project_path = ProjectSettings::get_singleton()->get_resource_path();
5252
String path = p_path.replace("\\", "/");
53-
return path.findn(project_path) != -1;
53+
return path.containsn(project_path);
5454
}
5555
return p_path.begins_with(ProjectSettings::get_singleton()->get_resource_path());
5656
}

editor/editor_help_search.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
bool EditorHelpSearch::_all_terms_in_name(const Vector<String> &p_terms, const String &p_name) const {
4242
for (int i = 0; i < p_terms.size(); i++) {
43-
if (p_name.findn(p_terms[i]) < 0) {
43+
if (!p_name.containsn(p_terms[i])) {
4444
return false;
4545
}
4646
}
@@ -109,7 +109,7 @@ Dictionary EditorHelpSearch::_native_search_cb(const String &p_search_string, in
109109
if (class_doc.name.is_empty()) {
110110
continue;
111111
}
112-
if (class_doc.name.findn(term) > -1) {
112+
if (class_doc.name.containsn(term)) {
113113
ret[vformat("class_name:%s", class_doc.name)] = class_doc.name;
114114
}
115115
if (term.length() > 1 || term == "@") {
@@ -746,7 +746,7 @@ bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String
746746
if (search_flags & SEARCH_CASE_SENSITIVE) {
747747
return p_string.find(p_term) > -1;
748748
} else {
749-
return p_string.findn(p_term) > -1;
749+
return p_string.containsn(p_term);
750750
}
751751
}
752752

editor/editor_inspector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#include "scene/resources/style_box_flat.h"
5353

5454
bool EditorInspector::_property_path_matches(const String &p_property_path, const String &p_filter, EditorPropertyNameProcessor::Style p_style) {
55-
if (p_property_path.findn(p_filter) != -1) {
55+
if (p_property_path.containsn(p_filter)) {
5656
return true;
5757
}
5858

0 commit comments

Comments
 (0)