#include <item_strfunc.h>
Inheritance diagram for Item_func_substr_index:


Public Member Functions | |
| Item_func_substr_index (Item *a, Item *b, Item *c) | |
| String * | val_str (String *) |
| void | fix_length_and_dec () |
| const char * | func_name () const |
| bool | check_partition_func_processor (byte *bool_arg) |
Private Attributes | |
| String | tmp_value |
Definition at line 220 of file item_strfunc.h.
| void Item_func_substr_index::fix_length_and_dec | ( | ) | [virtual] |
Implements Item_result_field.
Definition at line 1159 of file item_strfunc.cc.
References Item_func::agg_arg_charsets(), Item_func::args, Item::collation, Item::max_length, and MY_COLL_CMP_CONV.
01160 { 01161 max_length= args[0]->max_length; 01162 01163 if (agg_arg_charsets(collation, args, 2, MY_COLL_CMP_CONV, 1)) 01164 return; 01165 }
Here is the call graph for this function:

| const char* Item_func_substr_index::func_name | ( | ) | const [inline, virtual] |
Implements Item.
Definition at line 1168 of file item_strfunc.cc.
References Item_func::args, String::charset(), DTCollation::collation, Item::collation, count, DBUG_ASSERT, delimiter, delimiter_length, Item::fixed, String::length(), String::mark_as_const(), my_empty_string(), my_ismbchar, n, Item::null_value, offset, pass, String::ptr(), search_end(), String::set(), String::set_charset(), skip(), strend(), String::strrstr(), String::strstr(), tmp_value, use_mb, Item_str_func::val_int(), and Item::val_str().
01169 { 01170 DBUG_ASSERT(fixed == 1); 01171 String *res= args[0]->val_str(str); 01172 String *delimiter= args[1]->val_str(&tmp_value); 01173 int32 count= (int32) args[2]->val_int(); 01174 uint offset; 01175 01176 if (args[0]->null_value || args[1]->null_value || args[2]->null_value) 01177 { // string and/or delim are null 01178 null_value=1; 01179 return 0; 01180 } 01181 null_value=0; 01182 uint delimiter_length= delimiter->length(); 01183 if (!res->length() || !delimiter_length || !count) 01184 return &my_empty_string; // Wrong parameters 01185 01186 res->set_charset(collation.collation); 01187 01188 #ifdef USE_MB 01189 if (use_mb(res->charset())) 01190 { 01191 const char *ptr= res->ptr(); 01192 const char *strend= ptr+res->length(); 01193 const char *end= strend-delimiter_length+1; 01194 const char *search= delimiter->ptr(); 01195 const char *search_end= search+delimiter_length; 01196 int32 n=0,c=count,pass; 01197 register uint32 l; 01198 for (pass=(count>0);pass<2;++pass) 01199 { 01200 while (ptr < end) 01201 { 01202 if (*ptr == *search) 01203 { 01204 register char *i,*j; 01205 i=(char*) ptr+1; j=(char*) search+1; 01206 while (j != search_end) 01207 if (*i++ != *j++) goto skip; 01208 if (pass==0) ++n; 01209 else if (!--c) break; 01210 ptr+= delimiter_length; 01211 continue; 01212 } 01213 skip: 01214 if ((l=my_ismbchar(res->charset(), ptr,strend))) ptr+=l; 01215 else ++ptr; 01216 } /* either not found or got total number when count<0 */ 01217 if (pass == 0) /* count<0 */ 01218 { 01219 c+=n+1; 01220 if (c<=0) return res; /* not found, return original string */ 01221 ptr=res->ptr(); 01222 } 01223 else 01224 { 01225 if (c) return res; /* Not found, return original string */ 01226 if (count>0) /* return left part */ 01227 { 01228 tmp_value.set(*res,0,(ulong) (ptr-res->ptr())); 01229 } 01230 else /* return right part */ 01231 { 01232 ptr+= delimiter_length; 01233 tmp_value.set(*res,(ulong) (ptr-res->ptr()), (ulong) (strend-ptr)); 01234 } 01235 } 01236 } 01237 } 01238 else 01239 #endif /* USE_MB */ 01240 { 01241 if (count > 0) 01242 { // start counting from the beginning 01243 for (offset=0; ; offset+= delimiter_length) 01244 { 01245 if ((int) (offset= res->strstr(*delimiter, offset)) < 0) 01246 return res; // Didn't find, return org string 01247 if (!--count) 01248 { 01249 tmp_value.set(*res,0,offset); 01250 break; 01251 } 01252 } 01253 } 01254 else 01255 { 01256 /* 01257 Negative index, start counting at the end 01258 */ 01259 for (offset=res->length(); offset ;) 01260 { 01261 /* 01262 this call will result in finding the position pointing to one 01263 address space less than where the found substring is located 01264 in res 01265 */ 01266 if ((int) (offset= res->strrstr(*delimiter, offset)) < 0) 01267 return res; // Didn't find, return org string 01268 /* 01269 At this point, we've searched for the substring 01270 the number of times as supplied by the index value 01271 */ 01272 if (!++count) 01273 { 01274 offset+= delimiter_length; 01275 tmp_value.set(*res,offset,res->length()- offset); 01276 break; 01277 } 01278 } 01279 } 01280 } 01281 /* 01282 We always mark tmp_value as const so that if val_str() is called again 01283 on this object, we don't disrupt the contents of tmp_value when it was 01284 derived from another String. 01285 */ 01286 tmp_value.mark_as_const(); 01287 return (&tmp_value); 01288 }
Here is the call graph for this function:

String Item_func_substr_index::tmp_value [private] |
1.4.7

