added str_str() to help parse http POST requests for rhizome direct. #9

This commit is contained in:
gardners 2012-08-30 19:18:16 +08:00
parent 389ae8e989
commit fb82043246
2 changed files with 14 additions and 1 deletions

10
str.c
View File

@ -17,6 +17,8 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "str.h"
@ -42,3 +44,11 @@ int strcase_startswith(char *str, const char *substring, char **afterp)
return 1;
}
/* Like strstr() but doesn't depend on null termination */
const char *str_str(const char *s1,const char *s2,int s1len)
{
int s2len=strlen(s2);
for(;*s1&&(s1len--);s1++)
if (!strncmp(s2,s1,s2len)) return s1;
return NULL;
}

5
str.h
View File

@ -37,5 +37,8 @@ int str_startswith(char *str, const char *substring, char **afterp);
*/
int strcase_startswith(char *str, const char *substring, char **afterp);
/* like strstr(), but doesn't depend on null termination.
@author Paul Gardner-Stephen <paul@servalproject.org> */
const char *str_str(const char *s1,const char *s2,int s1len);
#endif
#endif