Skip to content

Conversation

@linuxdevel
Copy link

Hi

The _FLASH_STRING class is good, however I would also like to see some more string functionality. For example the strncmp and strcmp would be very good to have. For example to compare string commands received through serialport with constant strings stored in flash.

I have created my own strncmp for a project I am working on, outside the Flash library, see below.
This PULL request is just a in browser - not tested - edited versions of Flash.h/Flash.cpp to give you an Idea. Hope to see something like this in next release of the Flash library.

unsigned int fs_strncmp(_FLASH_STRING fs1, const char *s2, size_t n) {
size_t i;
size_t s2_len = strlen(s2);

if (s2_len < n) {
// s2 too short
return 1;
}

for (i = 0; i < n; i++) {
if (fs1[i] != s2[i]) {
return 1;
}
}
return 0;

}

It returns 0 if s2 is identical to _FLASH_STRING.. max n bytes are compared
The original strncmp returns -1, 0 or 1 ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant