~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-01-07 09:27:07 UTC
  • Revision ID: brian@tangent.org-20090107092707-bn67qpdllfcyh3j9
Removing dead field translator code.

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/function/str/weight_string.h>
 
23
 
 
24
void Item_func_weight_string::fix_length_and_dec()
 
25
{
 
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);
 
30
  maybe_null= 1;
 
31
}
 
32
 
 
33
/* Return a weight_string according to collation */
 
34
String *Item_func_weight_string::val_str(String *str)
 
35
{
 
36
  String *res;
 
37
  const CHARSET_INFO * const cs= args[0]->collation.collation;
 
38
  uint32_t tmp_length, frm_length;
 
39
  assert(fixed == 1);
 
40
 
 
41
  if (args[0]->result_type() != STRING_RESULT ||
 
42
      !(res= args[0]->val_str(str)))
 
43
    goto nl;
 
44
 
 
45
  tmp_length= cs->coll->strnxfrmlen(cs, cs->mbmaxlen *
 
46
                                        cmax(res->length(), nweights));
 
47
 
 
48
  if (tmp_value.alloc(tmp_length))
 
49
    goto nl;
 
50
 
 
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(),
 
55
                                 flags);
 
56
  tmp_value.length(frm_length);
 
57
  null_value= 0;
 
58
  return &tmp_value;
 
59
 
 
60
nl:
 
61
  null_value= 1;
 
62
  return 0;
 
63
}
 
64