Skip to content

Commit

Permalink
Add method which should have been part of SmingHub#1461 and SmingHub#…
Browse files Browse the repository at this point in the history
…1463

* Comparison accomplished using stack, avoids allocating temporary String variable on heap
  • Loading branch information
mikee47 committed Oct 10, 2018
1 parent 05dbd17 commit ecacd8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sming/Wiring/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,13 @@ bool String::equalsIgnoreCase(const String &s2) const
return equalsIgnoreCase(s2.buffer);
}

bool String::equalsIgnoreCase(const FlashString& fstr) const
{
if (len != fstr.length()) return false;
LOAD_FSTR(buf, fstr);
return strcasecmp(buf, buffer) == 0;
}

bool String::startsWith(const String &prefix) const
{
if (len < prefix.len) return false;
Expand Down
1 change: 1 addition & 0 deletions Sming/Wiring/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class String
bool operator >= (const String &rhs) const;
bool equalsIgnoreCase(const char* cstr) const;
bool equalsIgnoreCase(const String &s2) const;
bool equalsIgnoreCase(const FlashString& fstr) const;
bool startsWith(const String &prefix) const;
bool startsWith(const String &prefix, unsigned int offset) const;
bool endsWith(const String &suffix) const;
Expand Down

0 comments on commit ecacd8b

Please sign in to comment.