~drizzle-trunk/drizzle/development

574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
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
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
22
#include <drizzled/function/str/weight_string.h>
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
23
1067.4.6 by Nathan Williams
Converted all usages of cmax in drizzled/field/ and drizzled/function/ to std::max.
24
#include <algorithm>
25
26
using namespace std;
27
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
28
void Item_func_weight_string::fix_length_and_dec()
29
{
30
  const CHARSET_INFO * const cs= args[0]->collation.collation;
31
  collation.set(&my_charset_bin, args[0]->collation.derivation);
32
  flags= my_strxfrm_flag_normalize(flags, cs->levels_for_order);
1067.4.6 by Nathan Williams
Converted all usages of cmax in drizzled/field/ and drizzled/function/ to std::max.
33
  max_length= cs->mbmaxlen * max(args[0]->max_length, nweights);
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
34
  maybe_null= 1;
35
}
36
37
/* Return a weight_string according to collation */
38
String *Item_func_weight_string::val_str(String *str)
39
{
40
  String *res;
41
  const CHARSET_INFO * const cs= args[0]->collation.collation;
42
  uint32_t tmp_length, frm_length;
43
  assert(fixed == 1);
44
45
  if (args[0]->result_type() != STRING_RESULT ||
46
      !(res= args[0]->val_str(str)))
47
    goto nl;
48
49
  tmp_length= cs->coll->strnxfrmlen(cs, cs->mbmaxlen *
1067.4.6 by Nathan Williams
Converted all usages of cmax in drizzled/field/ and drizzled/function/ to std::max.
50
                                        max(res->length(), nweights));
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
51
52
  if (tmp_value.alloc(tmp_length))
53
    goto nl;
54
55
  frm_length= cs->coll->strnxfrm(cs,
56
                                 (unsigned char*) tmp_value.ptr(), tmp_length,
57
                                 nweights ? nweights : tmp_length,
58
                                 (const unsigned char*) res->ptr(), res->length(),
59
                                 flags);
60
  tmp_value.length(frm_length);
61
  null_value= 0;
62
  return &tmp_value;
63
64
nl:
65
  null_value= 1;
66
  return 0;
67
}
68