~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/substr_functions/substr_functions.cc

  • Committer: Brian Aker
  • Date: 2010-03-19 01:45:39 UTC
  • mto: This revision was merged to the branch mainline in revision 1362.
  • Revision ID: brian@gaz-20100319014539-jv38vkd8h9a4axzr
Another pass through the interface...

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *  Copyright (C) 2010 Stewart Smith
6
6
 *
7
7
 *  This program is free software; you can redistribute it and/or modify
20
20
 
21
21
#include "config.h"
22
22
 
 
23
#include <drizzled/plugin/function.h>
23
24
#include <algorithm>
24
25
 
25
 
#include <drizzled/charset_info.h>
26
 
#include <drizzled/function/str/strfunc.h>
27
 
#include <drizzled/plugin/function.h>
28
 
 
29
26
using namespace std;
30
27
using namespace drizzled;
31
28
 
 
29
#include <drizzled/function/str/strfunc.h>
 
30
 
32
31
class SubstrFunction :public Item_str_func
33
32
{
34
33
  String tmp_value;
87
86
      (args[1]->unsigned_flag && ((uint64_t) start > INT32_MAX)))
88
87
    return &my_empty_string;
89
88
 
90
 
  start= ((start < 0) ?
91
 
          static_cast<int64_t>(res->numchars() + start)
92
 
          : start - 1);
 
89
  start= ((start < 0) ? res->numchars() + start : start - 1);
93
90
  start= res->charpos((int) start);
94
91
  if ((start < 0) || ((uint) start + 1 > res->length()))
95
92
    return &my_empty_string;
261
258
plugin::Create_function<SubstrFunction> *substr_function= NULL;
262
259
plugin::Create_function<SubstrIndexFunction> *substr_index_function= NULL;
263
260
 
264
 
static int initialize(drizzled::module::Context &context)
 
261
static int initialize(drizzled::plugin::Registry &registry)
265
262
{
266
263
  substr_function= new plugin::Create_function<SubstrFunction>("substr");
267
264
  substr_index_function= new plugin::Create_function<SubstrIndexFunction>("substring_index");
268
 
  context.add(substr_function);
269
 
  context.add(substr_index_function);
 
265
  registry.add(substr_function);
 
266
  registry.add(substr_index_function);
270
267
  return 0;
271
268
}
272
269
 
 
270
static int finalize(drizzled::plugin::Registry &registry)
 
271
{
 
272
   registry.remove(substr_function);
 
273
   registry.remove(substr_index_function);
 
274
   delete substr_function;
 
275
   delete substr_index_function;
 
276
   return 0;
 
277
}
 
278
 
273
279
DRIZZLE_DECLARE_PLUGIN
274
280
{
275
281
  DRIZZLE_VERSION_ID,
279
285
  "SUBSTR and SUBSTR",
280
286
  PLUGIN_LICENSE_GPL,
281
287
  initialize, /* Plugin Init */
282
 
  NULL,   /* depends */
 
288
  finalize,   /* Plugin Deinit */
 
289
  NULL,   /* system variables */
283
290
  NULL    /* config options */
284
291
}
285
292
DRIZZLE_DECLARE_PLUGIN_END;