MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
my_strchr.c
1 /* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #include <my_global.h>
17 #include "m_string.h"
18 #include "m_ctype.h"
19 
20 #define NEQ(A, B) ((A) != (B))
21 #define EQU(A, B) ((A) == (B))
22 
34 #define SCAN_STRING(CS, STR, END, ACC, LEN, CMP) \
35  do { \
36  uint mbl; \
37  const char *ptr_str, *ptr_acc; \
38  const char *acc_end= (ACC) + (LEN); \
39  for (ptr_str= (STR) ; ptr_str < (END) ; ptr_str+= mbl) \
40  { \
41  mbl= my_mbcharlen((CS), *(uchar*)ptr_str); \
42  if (mbl < 2) \
43  { \
44  DBUG_ASSERT(mbl == 1); \
45  for (ptr_acc= (ACC) ; ptr_acc < acc_end ; ++ptr_acc) \
46  if (CMP(*ptr_acc, *ptr_str)) \
47  goto end; \
48  } \
49  } \
50 end: \
51  return (size_t) (ptr_str - (STR)); \
52  } while (0)
53 
54 
55 /*
56  my_strchr(cs, str, end, c) returns a pointer to the first place in
57  str where c (1-byte character) occurs, or NULL if c does not occur
58  in str. This function is multi-byte safe.
59  TODO: should be moved to CHARSET_INFO if it's going to be called
60  frequently.
61 */
62 
63 char *my_strchr(const CHARSET_INFO *cs, const char *str, const char *end,
64  pchar c)
65 {
66  uint mbl;
67  while (str < end)
68  {
69  mbl= my_mbcharlen(cs, *(uchar *)str);
70  if (mbl < 2)
71  {
72  if (*str == c)
73  return((char *)str);
74  str++;
75  }
76  else
77  str+= mbl;
78  }
79  return(0);
80 }
81 
100 size_t my_strcspn(const CHARSET_INFO *cs, const char *str,
101  const char *str_end, const char *reject)
102 {
103  SCAN_STRING(cs, str, str_end, reject, strlen(reject), EQU);
104 }