r_strinstr.c
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:2k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  2.    
  3.    This library is free software; you can redistribute it and/or
  4.    modify it under the terms of the GNU Library General Public
  5.    License as published by the Free Software Foundation; either
  6.    version 2 of the License, or (at your option) any later version.
  7.    
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.    
  13.    You should have received a copy of the GNU Library General Public
  14.    License along with this library; if not, write to the Free
  15.    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  16.    MA 02111-1307, USA */
  17. /*
  18.   Author : David
  19.   strintstr(src, from, pat) looks for an instance of pat in src
  20.   backwards from pos from.  pat is not a regex(3) pattern, it is a literal
  21.   string which must be matched exactly.
  22.   The result 0 if the pattern was not found else it is the start char of
  23.   the pattern counted from the begining of the string.
  24. */
  25. #include <global.h>
  26. #include "m_string.h"
  27. uint r_strinstr(reg1 my_string str,int from, reg4 my_string search)
  28. {
  29.   reg2 my_string i, j;
  30.   uint len = (uint) strlen(search);
  31.   /* pointer to the last char of buff */
  32.   my_string start = str + from - 1;
  33.   /* pointer to the last char of search */
  34.   my_string search_end = search + len - 1;
  35.  skipp:
  36.   while (start >= str) /* Cant be != because the first char */
  37.   {
  38.     if (*start-- == *search_end)
  39.     {
  40.       i = start; j = search_end - 1;
  41.       while (j >= search && start > str)
  42. if (*i-- != *j--)
  43.   goto skipp;
  44.       return (uint) ((start - len) - str + 3);
  45.     }
  46.   }
  47.   return (0);
  48. }