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> |
20 |
#include <drizzled/charset_info.h> |
|
21 |
#include <drizzled/global_charset_info.h> |
|
1
by brian
clean slate |
22 |
|
2275.2.1
by Olaf van der Spek
Refactor Typelib |
23 |
namespace drizzled { |
1
by brian
clean slate |
24 |
|
25 |
/*
|
|
26 |
Function to find a string in a TYPELIB
|
|
27 |
(Same format as mysys/typelib.c)
|
|
28 |
||
29 |
SYNOPSIS
|
|
30 |
find_type()
|
|
31 |
lib TYPELIB (struct of pointer to values + count)
|
|
32 |
find String to find
|
|
33 |
length Length of string to find
|
|
34 |
part_match Allow part matching of value
|
|
35 |
||
36 |
RETURN
|
|
37 |
0 error
|
|
38 |
> 0 position in TYPELIB->type_names +1
|
|
39 |
*/
|
|
40 |
||
2252.1.3
by Olaf van der Spek
Common fwd |
41 |
uint32_t TYPELIB::find_type(const char *find, uint32_t length, bool part_match) const |
1
by brian
clean slate |
42 |
{
|
482
by Brian Aker
Remove uint. |
43 |
uint32_t found_count=0, found_pos=0; |
2275.2.1
by Olaf van der Spek
Refactor Typelib |
44 |
const char* end= find + length; |
45 |
const char* i; |
|
46 |
const char* j; |
|
2151.5.4
by Olaf van der Spek
Move strfunc functions into TYPELIB class |
47 |
for (uint32_t pos= 0 ; (j= type_names[pos++]) ; ) |
1
by brian
clean slate |
48 |
{
|
2275.2.1
by Olaf van der Spek
Refactor Typelib |
49 |
for (i= find ; i != end && my_toupper(system_charset_info, *i) == my_toupper(system_charset_info, *j); i++, j++) |
50 |
{
|
|
51 |
}
|
|
1
by brian
clean slate |
52 |
if (i == end) |
53 |
{
|
|
2275.2.1
by Olaf van der Spek
Refactor Typelib |
54 |
if (not *j) |
55 |
return pos; |
|
1
by brian
clean slate |
56 |
found_count++; |
57 |
found_pos= pos; |
|
58 |
}
|
|
59 |
}
|
|
2275.2.1
by Olaf van der Spek
Refactor Typelib |
60 |
return found_count == 1 && part_match ? found_pos : 0; |
1
by brian
clean slate |
61 |
}
|
62 |
||
63 |
||
64 |
/*
|
|
65 |
Find a string in a list of strings according to collation
|
|
66 |
||
67 |
SYNOPSIS
|
|
68 |
find_type2()
|
|
69 |
lib TYPELIB (struct of pointer to values + count)
|
|
70 |
x String to find
|
|
71 |
length String length
|
|
72 |
cs Character set + collation to use for comparison
|
|
73 |
||
74 |
NOTES
|
|
75 |
||
76 |
RETURN
|
|
77 |
0 No matching value
|
|
78 |
>0 Offset+1 in typelib for matched string
|
|
79 |
*/
|
|
80 |
||
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
81 |
uint32_t TYPELIB::find_type2(const char *x, uint32_t length, const charset_info_st *cs) const |
1
by brian
clean slate |
82 |
{
|
2151.5.4
by Olaf van der Spek
Move strfunc functions into TYPELIB class |
83 |
if (!count) |
84 |
return 0; |
|
1
by brian
clean slate |
85 |
const char *j; |
2151.5.4
by Olaf van der Spek
Move strfunc functions into TYPELIB class |
86 |
for (int pos=0 ; (j= type_names[pos]) ; pos++) |
1
by brian
clean slate |
87 |
{
|
481
by Brian Aker
Remove all of uchar. |
88 |
if (!my_strnncoll(cs, (const unsigned char*) x, length, |
2151.5.4
by Olaf van der Spek
Move strfunc functions into TYPELIB class |
89 |
(const unsigned char*) j, type_lengths[pos])) |
90 |
return pos + 1; |
|
1
by brian
clean slate |
91 |
}
|
2151.5.4
by Olaf van der Spek
Move strfunc functions into TYPELIB class |
92 |
return 0; |
1
by brian
clean slate |
93 |
} /* find_type */ |
94 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
95 |
} /* namespace drizzled */ |