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
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>
26
using namespace drizzled;
28
class ReverseFunction :public Item_str_func
32
ReverseFunction() :Item_str_func() {}
33
String *val_str(String *);
34
void fix_length_and_dec();
35
const char *func_name() const { return "reverse"; }
37
bool check_argument_count(int n)
43
String *ReverseFunction::val_str(String *str)
46
String *res = args[0]->val_str(str);
47
char *ptr, *end, *tmp;
49
if ((null_value=args[0]->null_value))
51
/* An empty string is a special case as the string pointer may be null */
53
return &my_empty_string;
54
if (tmp_value.alloced_length() < res->length() &&
55
tmp_value.realloc(res->length()))
60
tmp_value.length(res->length());
61
tmp_value.set_charset(res->charset());
62
ptr= (char *) res->ptr();
63
end= ptr + res->length();
64
tmp= (char *) tmp_value.ptr() + tmp_value.length();
65
if (use_mb(res->charset()))
70
if ((l= my_ismbchar(res->charset(),ptr,end)))
88
void ReverseFunction::fix_length_and_dec()
90
collation.set(args[0]->collation);
91
max_length = args[0]->max_length;
94
plugin::Create_function<ReverseFunction> *reverse_function= NULL;
96
static int initialize(drizzled::plugin::Registry ®istry)
98
reverse_function= new plugin::Create_function<ReverseFunction>("reverse");
99
registry.add(reverse_function);
103
static int finalize(drizzled::plugin::Registry ®istry)
105
registry.remove(reverse_function);
106
delete reverse_function;
110
DRIZZLE_DECLARE_PLUGIN
118
initialize, /* Plugin Init */
119
finalize, /* Plugin Deinit */
120
NULL, /* system variables */
121
NULL /* config options */
123
DRIZZLE_DECLARE_PLUGIN_END;