1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Tim Penhey <tim@penhey.net>
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.
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.
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
21
#include <drizzled/plugin/function.h>
22
#include <drizzled/item/func.h>
23
#include <drizzled/function/str/strfunc.h>
29
using namespace drizzled;
34
char const* name= "rot13";
39
std::string rot13(std::string const& s)
41
std::ostringstream sout;
42
for (std::size_t i= 0, max= s.length(); i < max; ++i)
45
if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M'))
47
else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z'))
57
class Function : public Item_str_func
60
Function() : Item_str_func() {}
61
const char *func_name() const { return rot13::name; }
63
String *val_str(String *s)
66
String *other= args[0]->val_str(&val);
67
std::string to_rot= String_to_std_string(*other);
68
return set_String_from_std_string(s, rot13(to_rot));
71
void fix_length_and_dec()
73
max_length= args[0]->max_length;
76
bool check_argument_count(int n)
82
using plugin::Create_function;
83
using module::Context;
84
typedef Create_function<Function> PluginFunction;
85
PluginFunction *rot13_func= NULL;
87
static int init(Context &context)
89
rot13_func= new PluginFunction(rot13::name);
90
context.add(rot13_func);
94
} /* namespace rot13 */
96
DRIZZLE_PLUGIN(rot13::init, NULL, NULL);