Skip to content

AdafruitIO_Group: compare feed names case-insensitively #124

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

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 17 additions & 3 deletions src/AdafruitIO_Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,20 @@ bool AdafruitIO_Group::save() {
/**************************************************************************/
bool AdafruitIO_Group::get() { return _get_pub->publish("\0"); }

/**************************************************************************/
/*
@brief Helper function to compare strings case-insensitively
@return True if strings are equal (ignoring case)
*/
/**************************************************************************/
bool strsame_nocase(const char *str1, const char *str2) {
while ( *str1 && *str2 && tolower(*str1) == tolower(*str2) ) {
++str1;
++str2;
}
return tolower(*str1) == tolower(*str2);
}

/**************************************************************************/
/*!
@brief Obtains data from feed within group.
Expand All @@ -251,7 +265,7 @@ AdafruitIO_Data *AdafruitIO_Group::getFeed(const char *feed) {

while (cur_data != NULL) {

if (strcmp(cur_data->feedName(), feed) == 0) {
if (strsame_nocase(cur_data->feedName(), feed)) {
return cur_data;
}

Expand Down Expand Up @@ -314,7 +328,7 @@ void AdafruitIO_Group::onMessage(const char *feed,

while (cur_cb != NULL) {

if (strcmp(cur_cb->feed, feed) == 0) {
if (strsame_nocase(cur_cb->feed, feed)) {
return;
}

Expand Down Expand Up @@ -345,7 +359,7 @@ void AdafruitIO_Group::call(AdafruitIO_Data *d) {

while (cur_cb) {

if (cur_cb->feed == NULL || strcmp(cur_cb->feed, d->feedName()) == 0) {
if (cur_cb->feed == NULL || strsame_nocase(cur_cb->feed, d->feedName())) {
cur_cb->dataCallback(d);
}

Expand Down