1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
20
#include <drizzled/server_includes.h>
22
#include <drizzled/functions/str/weight_string.h>
24
void Item_func_weight_string::fix_length_and_dec()
26
const CHARSET_INFO * const cs= args[0]->collation.collation;
27
collation.set(&my_charset_bin, args[0]->collation.derivation);
28
flags= my_strxfrm_flag_normalize(flags, cs->levels_for_order);
29
max_length= cs->mbmaxlen * cmax(args[0]->max_length, nweights);
33
/* Return a weight_string according to collation */
34
String *Item_func_weight_string::val_str(String *str)
37
const CHARSET_INFO * const cs= args[0]->collation.collation;
38
uint32_t tmp_length, frm_length;
41
if (args[0]->result_type() != STRING_RESULT ||
42
!(res= args[0]->val_str(str)))
45
tmp_length= cs->coll->strnxfrmlen(cs, cs->mbmaxlen *
46
cmax(res->length(), nweights));
48
if (tmp_value.alloc(tmp_length))
51
frm_length= cs->coll->strnxfrm(cs,
52
(unsigned char*) tmp_value.ptr(), tmp_length,
53
nweights ? nweights : tmp_length,
54
(const unsigned char*) res->ptr(), res->length(),
56
tmp_value.length(frm_length);