~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/str/conv.cc

  • Committer: Brian Aker
  • Date: 2008-11-13 02:56:15 UTC
  • mfrom: (575.4.10 devel)
  • Revision ID: brian@tangent.org-20081113025615-snhsi52yb2ivmx6f
Merging Monty's code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include CSTDINT_H
22
22
#include <drizzled/functions/str/conv.h>
23
23
 
24
 
String *Item_str_conv::val_str(String *str)
 
24
String *Item_func_conv::val_str(String *str)
25
25
{
26
26
  assert(fixed == 1);
27
 
  String *res;
28
 
  if (!(res=args[0]->val_str(str)))
29
 
  {
30
 
    null_value=1; /* purecov: inspected */
31
 
    return 0; /* purecov: inspected */
32
 
  }
33
 
  null_value=0;
34
 
  if (multiply == 1)
35
 
  {
36
 
    uint32_t len;
37
 
    res= copy_if_not_alloced(str,res,res->length());
38
 
    len= converter(collation.collation, (char*) res->ptr(), res->length(),
39
 
                                        (char*) res->ptr(), res->length());
40
 
    assert(len <= res->length());
41
 
    res->length(len);
42
 
  }
 
27
  String *res= args[0]->val_str(str);
 
28
  char *endptr,ans[65],*ptr;
 
29
  int64_t dec;
 
30
  int from_base= (int) args[1]->val_int();
 
31
  int to_base= (int) args[2]->val_int();
 
32
  int err;
 
33
 
 
34
  if (args[0]->null_value || args[1]->null_value || args[2]->null_value ||
 
35
      abs(to_base) > 36 || abs(to_base) < 2 ||
 
36
      abs(from_base) > 36 || abs(from_base) < 2 || !(res->length()))
 
37
  {
 
38
    null_value= 1;
 
39
    return NULL;
 
40
  }
 
41
  null_value= 0;
 
42
  unsigned_flag= !(from_base < 0);
 
43
 
 
44
  if (from_base < 0)
 
45
    dec= my_strntoll(res->charset(), res->ptr(), res->length(),
 
46
                     -from_base, &endptr, &err);
43
47
  else
44
 
  {
45
 
    uint32_t len= res->length() * multiply;
46
 
    tmp_value.alloc(len);
47
 
    tmp_value.set_charset(collation.collation);
48
 
    len= converter(collation.collation, (char*) res->ptr(), res->length(),
49
 
                                        (char*) tmp_value.ptr(), len);
50
 
    tmp_value.length(len);
51
 
    res= &tmp_value;
52
 
  }
53
 
  return res;
54
 
}
55
 
 
56
 
void Item_func_lcase::fix_length_and_dec()
57
 
{
58
 
  collation.set(args[0]->collation);
59
 
  multiply= collation.collation->casedn_multiply;
60
 
  converter= collation.collation->cset->casedn;
61
 
  max_length= args[0]->max_length * multiply;
62
 
}
63
 
 
64
 
void Item_func_ucase::fix_length_and_dec()
65
 
{
66
 
  collation.set(args[0]->collation);
67
 
  multiply= collation.collation->caseup_multiply;
68
 
  converter= collation.collation->cset->caseup;
69
 
  max_length= args[0]->max_length * multiply;
70
 
}
 
48
    dec= (int64_t) my_strntoull(res->charset(), res->ptr(), res->length(),
 
49
                                 from_base, &endptr, &err);
 
50
 
 
51
  ptr= int64_t2str(dec, ans, to_base);
 
52
  if (str->copy(ans, (uint32_t) (ptr-ans), default_charset()))
 
53
    return &my_empty_string;
 
54
  return str;
 
55
}
 
56
 
71
57