Move subStr Function to Support.ino

This commit is contained in:
Adrian Scillato 2018-07-23 01:32:54 -03:00 committed by GitHub
parent 96fb23737d
commit 754955cd48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -130,6 +130,24 @@ size_t strchrspn(const char *str1, int character)
return ret;
}
// Function to return a substring defined by a delimiter at an index
char* subStr(char* dest, char* str, const char *delim, int index)
{
char *act;
char *sub;
char *ptr;
int i;
// Since strtok consumes the first arg, make a copy
strncpy(dest, str, strlen(str));
for (i = 1, act = dest; i <= index; i++, act = NULL) {
sub = strtok_r(act, delim, &ptr);
if (sub == NULL) break;
}
sub = Trim(sub);
return sub;
}
double CharToDouble(char *str)
{
// simple ascii to double, because atof or strtod are too large