Skip to content

Commit

Permalink
* Add autocomplete base.
Browse files Browse the repository at this point in the history
  • Loading branch information
iProgramMC committed Jun 4, 2024
1 parent 14f1bfc commit 235b0f8
Show file tree
Hide file tree
Showing 5 changed files with 442 additions and 9 deletions.
29 changes: 29 additions & 0 deletions src/discord/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,35 @@ int StringCompareCaseInsens(const char* s1, const char* s2)
return tolower(*s1) - tolower(*s2);
}

int StringCompareCaseInsensLimited(const char* s1, const char* s2, size_t n)
{
while (n > 0 && tolower(*s1) == tolower(*s2)) {
n--;
if (*s1 == '\0') break;
s1++, s2++;
}

if (n == 0)
return 0;
return tolower(*s1) - tolower(*s2);
}

bool BeginsWith(const std::string& what, const std::string& with)
{
if (what.size() < with.size())
return false;

return strncmp(what.c_str(), with.c_str(), with.size());
}

bool BeginsWithCaseInsens(const std::string& what, const std::string& with)
{
if (what.size() < with.size())
return false;

return StringCompareCaseInsensLimited(what.c_str(), with.c_str(), with.size()) == 0;
}

bool EndsWith(const std::string& what, const std::string& with)
{
if (what.size() < with.size())
Expand Down
3 changes: 3 additions & 0 deletions src/discord/Util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ std::string LoadEntireTextFile(const std::string& fileName);
std::string HttpEncodeString(std::string str);
std::string GetSizeString(size_t sz);
int StringCompareCaseInsens(const char* s1, const char* s2);
int StringCompareCaseInsensLimited(const char* s1, const char* s2, size_t n);
bool BeginsWith(const std::string& what, const std::string& with);
bool BeginsWithCaseInsens(const std::string& what, const std::string& with);
bool EndsWith(const std::string& what, const std::string& with);
bool EndsWithCaseInsens(const std::string& what, const std::string& with);
bool IsPotentiallyDangerousDownload(const std::string& filename);
Expand Down
Loading

0 comments on commit 235b0f8

Please sign in to comment.