~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/str/weight_string.cc

  • Committer: Monty Taylor
  • Date: 2010-03-11 18:27:20 UTC
  • mfrom: (1333 staging)
  • mto: This revision was merged to the branch mainline in revision 1348.
  • Revision ID: mordred@inaugust.com-20100311182720-hd1h87y6cb1b1mp0
Merged trunk.

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 "config.h"
21
 
 
22
 
#include <drizzled/function/str/weight_string.h>
23
 
 
24
 
#include <algorithm>
25
 
 
26
 
using namespace std;
27
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
 
void Item_func_weight_string::fix_length_and_dec()
32
 
{
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);
37
 
  maybe_null= 1;
38
 
}
39
 
 
40
 
/* Return a weight_string according to collation */
41
 
String *Item_func_weight_string::val_str(String *str)
42
 
{
43
 
  String *res;
44
 
  const CHARSET_INFO * const cs= args[0]->collation.collation;
45
 
  uint32_t tmp_length, frm_length;
46
 
  assert(fixed == 1);
47
 
 
48
 
  if (args[0]->result_type() != STRING_RESULT ||
49
 
      !(res= args[0]->val_str(str)))
50
 
    goto nl;
51
 
 
52
 
  tmp_length= cs->coll->strnxfrmlen(cs, cs->mbmaxlen *
53
 
                                        max(res->length(), nweights));
54
 
 
55
 
  if (tmp_value.alloc(tmp_length))
56
 
    goto nl;
57
 
 
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(),
62
 
                                 flags);
63
 
  tmp_value.length(frm_length);
64
 
  null_value= 0;
65
 
  return &tmp_value;
66
 
 
67
 
nl:
68
 
  null_value= 1;
69
 
  return 0;
70
 
}
71
 
 
72
 
} /* namespace drizzled */