On 9/10/2012 1:22 PM, kball...@kennethballard.com wrote:
Here's one that I wrote a while back:

void sqlite3_instr(sqlite3_context* pContext, int argc, sqlite3_value** argv)
{
     const char *str1 = (const char *) sqlite3_value_text(argv[0]);
     const char *str2 = (const char *) sqlite3_value_text(argv[1]);

     char *p = strstr(str1, str2);
     int nResult = 0;
     if(p != NULL)
     {
         nResult = p - str1 + 1;
     }

     sqlite3_result_int(pContext, nResult);
}

This returns an offset in bytes, not in characters. I would expect a reasonable instr() implementation to satisfy this identity:

substr(X, instr(X, Y), length(Y)) == Y

for all strings X and Y, or at least for those where Y does in fact appear in X. I don't think yours would satisfy this condition for strings containing non-ASCII characters.

One would probably want to study the implementation of substr and length before implementing instr, to make sure the three play well together.
--
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to