Skip to content

Commit

Permalink
adjust indexOf and lastIndexOf on empty search strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Feb 8, 2024
1 parent 45ee673 commit 0f2e870
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ int String::indexOf(const String &inValue, Dynamic inStart) const
int l = inValue.length;

if (l==0) {
return s > length ? length : s;
return std::max(0, std::min(s, length));
}

#ifdef HX_SMART_STRINGS
Expand Down Expand Up @@ -1333,8 +1333,11 @@ int String::lastIndexOf(const String &inValue, Dynamic inStart) const
if (__s==0)
return -1;
int l = inValue.length;
if (l>length) return -1;
int s = inStart==null() ? length : inStart->__ToInt();
if (l==0) {
return std::max(0, std::min(s, length));
}
if (l>length) return -1;
if (s+l>length) s = length-l;

#ifdef HX_SMART_STRINGS
Expand Down

0 comments on commit 0f2e870

Please sign in to comment.