Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-implement String.get_slice_count as count() + 1, which has the same logic. #101030

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,45 +1059,6 @@ String String::get_with_code_lines() const {
return ret;
}

int String::get_slice_count(const String &p_splitter) const {
if (is_empty()) {
return 0;
}
if (p_splitter.is_empty()) {
return 0;
}

int pos = 0;
int slices = 1;

while ((pos = find(p_splitter, pos)) >= 0) {
slices++;
pos += p_splitter.length();
}

return slices;
}

int String::get_slice_count(const char *p_splitter) const {
if (is_empty()) {
return 0;
}
if (p_splitter == nullptr || *p_splitter == '\0') {
return 0;
}

int pos = 0;
int slices = 1;
int splitter_length = strlen(p_splitter);

while ((pos = find(p_splitter, pos)) >= 0) {
slices++;
pos += splitter_length;
}

return slices;
}

String String::get_slice(const String &p_splitter, int p_slice) const {
if (is_empty() || p_splitter.is_empty()) {
return "";
Expand Down
4 changes: 2 additions & 2 deletions core/string/ustring.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ class String {
String to_snake_case() const;

String get_with_code_lines() const;
int get_slice_count(const String &p_splitter) const;
int get_slice_count(const char *p_splitter) const;
int get_slice_count(const String &p_splitter) const { return count(p_splitter) + 1; }
int get_slice_count(const char *p_splitter) const { return count(p_splitter) + 1; }
String get_slice(const String &p_splitter, int p_slice) const;
String get_slice(const char *p_splitter, int p_slice) const;
String get_slicec(char32_t p_splitter, int p_slice) const;
Expand Down