MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / str_strcasestr

Function str_strcasestr

ut.h:1221–1258  ·  view source on GitHub ↗

* search @strb in @stra ignoring case of both, return pointer to 1st occurrence */

Source from the content-addressed store, hash-verified

1219 * search @strb in @stra ignoring case of both, return pointer to 1st occurrence
1220 */
1221static inline char* str_strcasestr(const str *stra, const str *strb)
1222{
1223 int i;
1224 int len;
1225
1226 if (stra==NULL || strb==NULL || stra->s==NULL || strb->s==NULL
1227 || stra->len<=0 || strb->len<=0) {
1228#ifdef EXTRA_DEBUG
1229 LM_DBG("bad parameters\n");
1230#endif
1231 return NULL;
1232 }
1233
1234 if (strb->len > stra->len)
1235 return NULL;
1236
1237 len=0;
1238 while (stra->len-len >= strb->len){
1239 if (tolower(stra->s[len]) != tolower(strb->s[0])) {
1240 len++;
1241 continue;
1242 }
1243
1244 for (i=1; i<strb->len; i++)
1245 if (tolower(stra->s[len+i])!=tolower(strb->s[i])) {
1246 len++;
1247 break;
1248 }
1249
1250 if (i != strb->len)
1251 continue;
1252
1253 return stra->s+len;
1254 }
1255
1256
1257 return NULL;
1258}
1259
1260/*
1261 * case-insensitive compare n chars of two str's

Callers 2

db_copy_rest_of_countFunction · 0.85
test_utFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_utFunction · 0.68