1
by brian
clean slate |
1 |
/* Copyright (C) 2003 MySQL AB
|
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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
16 |
/* Some useful string utility functions used by the MySQL server */
|
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
17 |
#include <config.h> |
1241.9.12
by Monty Taylor
Trims more out of server_includes.h. |
18 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
19 |
#include <drizzled/typelib.h> |
2281.5.1
by Muhammad Umair
Merged charset declarations of global_charset_info.h and charset_info.h into charset.h header file. |
20 |
#include <drizzled/charset.h> |
1
by brian
clean slate |
21 |
|
2275.2.1
by Olaf van der Spek
Refactor Typelib |
22 |
namespace drizzled { |
1
by brian
clean slate |
23 |
|
24 |
/*
|
|
25 |
Function to find a string in a TYPELIB
|
|
26 |
(Same format as mysys/typelib.c)
|
|
27 |
||
28 |
SYNOPSIS
|
|
29 |
find_type()
|
|
30 |
lib TYPELIB (struct of pointer to values + count)
|
|
31 |
find String to find
|
|
32 |
length Length of string to find
|
|
33 |
part_match Allow part matching of value
|
|
34 |
||
35 |
RETURN
|
|
36 |
0 error
|
|
37 |
> 0 position in TYPELIB->type_names +1
|
|
38 |
*/
|
|
39 |
||
2252.1.3
by Olaf van der Spek
Common fwd |
40 |
uint32_t TYPELIB::find_type(const char *find, uint32_t length, bool part_match) const |
1
by brian
clean slate |
41 |
{
|
482
by Brian Aker
Remove uint. |
42 |
uint32_t found_count=0, found_pos=0; |
2275.2.1
by Olaf van der Spek
Refactor Typelib |
43 |
const char* end= find + length; |
44 |
const char* i; |
|
45 |
const char* j; |
|
2445.1.4
by Olaf van der Spek
Refactor |
46 |
for (uint32_t pos= 0 ; (j= type_names[pos++]); ) |
1
by brian
clean slate |
47 |
{
|
2445.1.4
by Olaf van der Spek
Refactor |
48 |
for (i= find ; i != end && system_charset_info->toupper(*i) == system_charset_info->toupper(*j); i++, j++) |
2275.2.1
by Olaf van der Spek
Refactor Typelib |
49 |
{
|
50 |
}
|
|
1
by brian
clean slate |
51 |
if (i == end) |
52 |
{
|
|
2275.2.1
by Olaf van der Spek
Refactor Typelib |
53 |
if (not *j) |
54 |
return pos; |
|
1
by brian
clean slate |
55 |
found_count++; |
56 |
found_pos= pos; |
|
57 |
}
|
|
58 |
}
|
|
2275.2.1
by Olaf van der Spek
Refactor Typelib |
59 |
return found_count == 1 && part_match ? found_pos : 0; |
1
by brian
clean slate |
60 |
}
|
61 |
||
62 |
||
63 |
/*
|
|
64 |
Find a string in a list of strings according to collation
|
|
65 |
||
66 |
SYNOPSIS
|
|
67 |
find_type2()
|
|
68 |
lib TYPELIB (struct of pointer to values + count)
|
|
69 |
x String to find
|
|
70 |
length String length
|
|
71 |
cs Character set + collation to use for comparison
|
|
72 |
||
73 |
NOTES
|
|
74 |
||
75 |
RETURN
|
|
76 |
0 No matching value
|
|
77 |
>0 Offset+1 in typelib for matched string
|
|
78 |
*/
|
|
79 |
||
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
80 |
uint32_t TYPELIB::find_type2(const char *x, uint32_t length, const charset_info_st *cs) const |
1
by brian
clean slate |
81 |
{
|
2151.5.4
by Olaf van der Spek
Move strfunc functions into TYPELIB class |
82 |
if (!count) |
83 |
return 0; |
|
1
by brian
clean slate |
84 |
const char *j; |
2151.5.4
by Olaf van der Spek
Move strfunc functions into TYPELIB class |
85 |
for (int pos=0 ; (j= type_names[pos]) ; pos++) |
1
by brian
clean slate |
86 |
{
|
481
by Brian Aker
Remove all of uchar. |
87 |
if (!my_strnncoll(cs, (const unsigned char*) x, length, |
2151.5.4
by Olaf van der Spek
Move strfunc functions into TYPELIB class |
88 |
(const unsigned char*) j, type_lengths[pos])) |
89 |
return pos + 1; |
|
1
by brian
clean slate |
90 |
}
|
2151.5.4
by Olaf van der Spek
Move strfunc functions into TYPELIB class |
91 |
return 0; |
1
by brian
clean slate |
92 |
} /* find_type */ |
93 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
94 |
} /* namespace drizzled */ |