00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <config.h>
00018
00019 #include <drizzled/typelib.h>
00020 #include <drizzled/charset_info.h>
00021 #include <drizzled/global_charset_info.h>
00022
00023 namespace drizzled
00024 {
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 static const char field_separator=',';
00046
00047 uint64_t st_typelib::find_set(const char *str, uint32_t length,
00048 const CHARSET_INFO * const cs,
00049 char **err_pos, uint32_t *err_len, bool *set_warning) const
00050 {
00051 const CHARSET_INFO * const strip= cs ? cs : &my_charset_utf8_general_ci;
00052 const char *end= str + strip->cset->lengthsp(strip, str, length);
00053 uint64_t found= 0;
00054 *err_pos= 0;
00055 if (str != end)
00056 {
00057 const char *start= str;
00058 for (;;)
00059 {
00060 const char *pos= start;
00061 uint32_t var_len;
00062 int mblen= 1;
00063
00064 for (; pos != end && *pos != field_separator; pos++)
00065 {}
00066 var_len= (uint32_t) (pos - start);
00067 uint32_t find= cs ? find_type2(start, var_len, cs) : find_type(start, var_len, false);
00068 if (!find)
00069 {
00070 *err_pos= (char*) start;
00071 *err_len= var_len;
00072 *set_warning= 1;
00073 }
00074 else
00075 found|= ((int64_t) 1 << (find - 1));
00076 if (pos >= end)
00077 break;
00078 start= pos + mblen;
00079 }
00080 }
00081 return found;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 uint32_t st_typelib::find_type(const char *find, uint32_t length, bool part_match) const
00102 {
00103 uint32_t found_count=0, found_pos=0;
00104 const char *end= find+length;
00105 const char *i;
00106 const char *j;
00107 for (uint32_t pos= 0 ; (j= type_names[pos++]) ; )
00108 {
00109 for (i=find ; i != end &&
00110 my_toupper(system_charset_info,*i) ==
00111 my_toupper(system_charset_info,*j) ; i++, j++) ;
00112 if (i == end)
00113 {
00114 if (! *j)
00115 return(pos);
00116 found_count++;
00117 found_pos= pos;
00118 }
00119 }
00120 return(found_count == 1 && part_match ? found_pos : 0);
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 uint32_t st_typelib::find_type2(const char *x, uint32_t length, const CHARSET_INFO *cs) const
00142 {
00143 if (!count)
00144 return 0;
00145 const char *j;
00146 for (int pos=0 ; (j= type_names[pos]) ; pos++)
00147 {
00148 if (!my_strnncoll(cs, (const unsigned char*) x, length,
00149 (const unsigned char*) j, type_lengths[pos]))
00150 return pos + 1;
00151 }
00152 return 0;
00153 }
00154
00155 }