mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / strings / my_strchr.c
blobf68842d4f39f5bf376f974119e17afee51239ea5
1 /* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
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.
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.
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
17 #include <my_global.h>
18 #include "m_string.h"
19 #include "m_ctype.h"
21 #define NEQ(A, B) ((A) != (B))
22 #define EQU(A, B) ((A) == (B))
24 /**
25 Macro for the body of the string scanning.
27 @param CS The character set of the string
28 @param STR Pointer to beginning of string
29 @param END Pointer to one-after-end of string
30 @param ACC Pointer to beginning of accept (or reject) string
31 @param LEN Length of accept (or reject) string
32 @param CMP is a function-like for doing the comparison of two characters.
35 #define SCAN_STRING(CS, STR, END, ACC, LEN, CMP) \
36 do { \
37 uint mbl; \
38 const char *ptr_str, *ptr_acc; \
39 const char *acc_end= (ACC) + (LEN); \
40 for (ptr_str= (STR) ; ptr_str < (END) ; ptr_str+= mbl) \
41 { \
42 mbl= my_mbcharlen((CS), *(uchar*)ptr_str); \
43 if (mbl < 2) \
44 { \
45 DBUG_ASSERT(mbl == 1); \
46 for (ptr_acc= (ACC) ; ptr_acc < acc_end ; ++ptr_acc) \
47 if (CMP(*ptr_acc, *ptr_str)) \
48 goto end; \
49 } \
50 } \
51 end: \
52 return (size_t) (ptr_str - (STR)); \
53 } while (0)
57 my_strchr(cs, str, end, c) returns a pointer to the first place in
58 str where c (1-byte character) occurs, or NULL if c does not occur
59 in str. This function is multi-byte safe.
60 TODO: should be moved to CHARSET_INFO if it's going to be called
61 frequently.
64 char *my_strchr(CHARSET_INFO *cs, const char *str, const char *end,
65 pchar c)
67 uint mbl;
68 while (str < end)
70 mbl= my_mbcharlen(cs, *(uchar *)str);
71 if (mbl < 2)
73 if (*str == c)
74 return((char *)str);
75 str++;
77 else
78 str+= mbl;
80 return(0);
83 /**
84 Calculate the length of the initial segment of 'str' which consists
85 entirely of characters not in 'reject'.
87 @note The reject string points to single-byte characters so it is
88 only possible to find the first occurrence of a single-byte
89 character. Multi-byte characters in 'str' are treated as not
90 matching any character in the reject string.
92 @todo should be moved to CHARSET_INFO if it's going to be called
93 frequently.
95 @internal The implementation builds on the assumption that 'str' is long,
96 while 'reject' is short. So it compares each character in string
97 with the characters in 'reject' in a tight loop over the characters
98 in 'reject'.
101 size_t my_strcspn(CHARSET_INFO *cs, const char *str, const char *str_end,
102 const char *reject)
104 SCAN_STRING(cs, str, str_end, reject, strlen(reject), EQU);