Drizzled Public API Documentation

str_conv.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <config.h>
00021 
00022 #include <drizzled/function/str/str_conv.h>
00023 
00024 namespace drizzled
00025 {
00026 
00027 String *Item_str_conv::val_str(String *str)
00028 {
00029   assert(fixed == 1);
00030   String *res;
00031   if (!(res=args[0]->val_str(str)))
00032   {
00033     null_value=1;
00034     return 0;
00035   }
00036   null_value=0;
00037   if (multiply == 1)
00038   {
00039     uint32_t len;
00040     res= copy_if_not_alloced(str,res,res->length());
00041     len= converter(collation.collation, (char*) res->ptr(), res->length(),
00042                                         (char*) res->ptr(), res->length());
00043     assert(len <= res->length());
00044     res->length(len);
00045   }
00046   else
00047   {
00048     uint32_t len= res->length() * multiply;
00049     tmp_value.alloc(len);
00050     tmp_value.set_charset(collation.collation);
00051     len= converter(collation.collation, (char*) res->ptr(), res->length(),
00052                                         (char*) tmp_value.ptr(), len);
00053     tmp_value.length(len);
00054     res= &tmp_value;
00055   }
00056   return res;
00057 }
00058 
00059 void Item_func_lcase::fix_length_and_dec()
00060 {
00061   collation.set(args[0]->collation);
00062   multiply= collation.collation->casedn_multiply;
00063   converter= collation.collation->cset->casedn;
00064   max_length= args[0]->max_length * multiply;
00065 }
00066 
00067 void Item_func_ucase::fix_length_and_dec()
00068 {
00069   collation.set(args[0]->collation);
00070   multiply= collation.collation->caseup_multiply;
00071   converter= collation.collation->cset->caseup;
00072   max_length= args[0]->max_length * multiply;
00073 }
00074 
00075 } /* namespace drizzled */