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
22
#include <drizzled/function/str/weight_string.h>
31
void Item_func_weight_string::fix_length_and_dec()
33
const CHARSET_INFO * const cs= args[0]->collation.collation;
34
collation.set(&my_charset_bin, args[0]->collation.derivation);
35
flags= my_strxfrm_flag_normalize(flags, cs->levels_for_order);
36
max_length= cs->mbmaxlen * max(args[0]->max_length, nweights);
40
/* Return a weight_string according to collation */
41
String *Item_func_weight_string::val_str(String *str)
44
const CHARSET_INFO * const cs= args[0]->collation.collation;
45
uint32_t tmp_length, frm_length;
48
if (args[0]->result_type() != STRING_RESULT ||
49
!(res= args[0]->val_str(str)))
52
tmp_length= cs->coll->strnxfrmlen(cs, cs->mbmaxlen *
53
max(res->length(), nweights));
55
if (tmp_value.alloc(tmp_length))
58
frm_length= cs->coll->strnxfrm(cs,
59
(unsigned char*) tmp_value.ptr(), tmp_length,
60
nweights ? nweights : tmp_length,
61
(const unsigned char*) res->ptr(), res->length(),
63
tmp_value.length(frm_length);
72
} /* namespace drizzled */