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, Inc.
5
* Copyright (C) 2010 Stewart Smith
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; version 2 of the License.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include <drizzled/plugin/function.h>
24
#include <drizzled/function/str/strfunc.h>
25
#include <drizzled/charset_info.h>
27
using namespace drizzled;
29
class ReverseFunction :public Item_str_func
33
ReverseFunction() :Item_str_func() {}
34
String *val_str(String *);
35
void fix_length_and_dec();
36
const char *func_name() const { return "reverse"; }
38
bool check_argument_count(int n)
44
String *ReverseFunction::val_str(String *str)
47
String *res = args[0]->val_str(str);
48
char *ptr, *end, *tmp;
50
if ((null_value=args[0]->null_value))
52
/* An empty string is a special case as the string pointer may be null */
54
return &my_empty_string;
55
if (tmp_value.alloced_length() < res->length() &&
56
tmp_value.realloc(res->length()))
61
tmp_value.length(res->length());
62
tmp_value.set_charset(res->charset());
63
ptr= (char *) res->ptr();
64
end= ptr + res->length();
65
tmp= (char *) tmp_value.ptr() + tmp_value.length();
66
if (use_mb(res->charset()))
71
if ((l= my_ismbchar(res->charset(),ptr,end)))
89
void ReverseFunction::fix_length_and_dec()
91
collation.set(args[0]->collation);
92
max_length = args[0]->max_length;
95
plugin::Create_function<ReverseFunction> *reverse_function= NULL;
97
static int initialize(drizzled::module::Context &context)
99
reverse_function= new plugin::Create_function<ReverseFunction>("reverse");
100
context.add(reverse_function);
104
DRIZZLE_DECLARE_PLUGIN
112
initialize, /* Plugin Init */
114
NULL /* config options */
116
DRIZZLE_DECLARE_PLUGIN_END;