Adding ranges and cfstring_find

This commit is contained in:
Jos Kuijpers 2012-04-08 21:48:43 +02:00
parent d6bbd7ba65
commit 70e09522d3
4 changed files with 102 additions and 0 deletions

View file

@ -131,6 +131,37 @@ cfw_string_set(CFWString *str, const char *cstr)
return true;
}
cfw_unichar
cfw_string_char(CFWString *str, size_t index)
{
if(len > index)
return str->cstr[index];
return NULL;
}
size_t
cfw_string_find(CFWString *strA, CFWString *strB, cfw_range_t range)
{
char *cstrA = strA->cstr+range.location;
size_t i, max = MIN(range.length+range.location, strB->len);
if(strA->len == 0)
return 0;
if(strA->len-range.location < strB->len)
return SIZE_MAX;
for(i = range.location;
i <= strA->len-strB->len && i <= max;
i++)
{
if(!memcmp(strA->cstr+i, strB->cstr, max-i))
return i;
}
return SIZE_MAX;
}
static CFWClass class = {
.name = "CFWString",
.size = sizeof(CFWString),