Skip to content

Commit

Permalink
Add mg_strstrip: trims whitespace at the ends of s
Browse files Browse the repository at this point in the history
CL: Add mg_strstrip: trims whitespace at the ends of s

PUBLISHED_FROM=a7e10054ac25fa2b3a878876da93a6b30d9507b3
  • Loading branch information
Deomid Ryabkov authored and cesantabot committed Jul 7, 2018
1 parent 93ac3e1 commit cdb8d7b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,18 @@ const char *mg_strstr(const struct mg_str haystack,
}
return NULL;
}

struct mg_str mg_strstrip(struct mg_str s) WEAK;
struct mg_str mg_strstrip(struct mg_str s) {
while (s.len > 0 && isspace((int) *s.p)) {
s.p++;
s.len--;
}
while (s.len > 0 && isspace((int) *(s.p + s.len - 1))) {
s.len--;
}
return s;
}
#ifdef MG_MODULE_LINES
#line 1 "common/str_util.c"
#endif
Expand Down
3 changes: 3 additions & 0 deletions mongoose.h
Original file line number Diff line number Diff line change
Expand Up @@ -2283,6 +2283,9 @@ int mg_strncmp(const struct mg_str str1, const struct mg_str str2, size_t n);
*/
const char *mg_strstr(const struct mg_str haystack, const struct mg_str needle);

/* Strip whitespace at the start and the end of s */
struct mg_str mg_strstrip(struct mg_str s);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit cdb8d7b

Please sign in to comment.