~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/str/conv.cc

  • Committer: Monty Taylor
  • Date: 2008-11-07 04:45:58 UTC
  • mfrom: (574.3.4 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 579.
  • Revision ID: monty@inaugust.com-20081107044558-2me2c70ksfr3qs9i
Merged from Lee (and from trunk by proxy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
 
22
#include <drizzled/functions/str/conv.h>
 
23
 
 
24
String *Item_str_conv::val_str(String *str)
 
25
{
 
26
  assert(fixed == 1);
 
27
  String *res;
 
28
  if (!(res=args[0]->val_str(str)))
 
29
  {
 
30
    null_value=1; /* purecov: inspected */
 
31
    return 0; /* purecov: inspected */
 
32
  }
 
33
  null_value=0;
 
34
  if (multiply == 1)
 
35
  {
 
36
    uint32_t len;
 
37
    res= copy_if_not_alloced(str,res,res->length());
 
38
    len= converter(collation.collation, (char*) res->ptr(), res->length(),
 
39
                                        (char*) res->ptr(), res->length());
 
40
    assert(len <= res->length());
 
41
    res->length(len);
 
42
  }
 
43
  else
 
44
  {
 
45
    uint32_t len= res->length() * multiply;
 
46
    tmp_value.alloc(len);
 
47
    tmp_value.set_charset(collation.collation);
 
48
    len= converter(collation.collation, (char*) res->ptr(), res->length(),
 
49
                                        (char*) tmp_value.ptr(), len);
 
50
    tmp_value.length(len);
 
51
    res= &tmp_value;
 
52
  }
 
53
  return res;
 
54
}
 
55
 
 
56
void Item_func_lcase::fix_length_and_dec()
 
57
{
 
58
  collation.set(args[0]->collation);
 
59
  multiply= collation.collation->casedn_multiply;
 
60
  converter= collation.collation->cset->casedn;
 
61
  max_length= args[0]->max_length * multiply;
 
62
}
 
63
 
 
64
void Item_func_ucase::fix_length_and_dec()
 
65
{
 
66
  collation.set(args[0]->collation);
 
67
  multiply= collation.collation->caseup_multiply;
 
68
  converter= collation.collation->cset->caseup;
 
69
  max_length= args[0]->max_length * multiply;
 
70
}
 
71