MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / _utstring_find

Function _utstring_find

libCacheSim/dataStructure/ut/utstring.h:251–280  ·  view source on GitHub ↗

Search data from left to right. ( Multiple search mode. ) */

Source from the content-addressed store, hash-verified

249
250/* Search data from left to right. ( Multiple search mode. ) */
251UTSTRING_UNUSED static long _utstring_find(
252 const char *P_Haystack,
253 size_t P_HaystackLen,
254 const char *P_Needle,
255 size_t P_NeedleLen,
256 long *P_KMP_Table)
257{
258 long i, j;
259 long V_FindPosition = -1;
260
261 /* Search from left to right. */
262 i = j = 0;
263 while ( (j < (int)P_HaystackLen) && (((P_HaystackLen - j) + i) >= P_NeedleLen) )
264 {
265 while ( (i > -1) && (P_Needle[i] != P_Haystack[j]) )
266 {
267 i = P_KMP_Table[i];
268 }
269 i++;
270 j++;
271 if (i >= (int)P_NeedleLen)
272 {
273 /* Found. */
274 V_FindPosition = j - i;
275 break;
276 }
277 }
278
279 return V_FindPosition;
280}
281
282
283/* Search data from right to left. ( Multiple search mode. ) */

Callers 1

utstring_findFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected