Groonga 3.0.9 Source Code Document
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
groonga
test
unit
fixtures
plugins
string.c
Go to the documentation of this file.
1
/* -*- c-basic-offset: 2 -*- */
2
/*
3
Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License version 2.1 as published by the Free Software Foundation.
8
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Lesser General Public License for more details.
13
14
You should have received a copy of the GNU Lesser General Public
15
License along with this library; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
*/
18
19
#include <
str.h
>
20
#include <
groonga/plugin.h
>
21
22
#include <
string.h
>
23
24
static
grn_obj
*
25
func_str_len(
grn_ctx
*ctx,
int
nargs,
grn_obj
**args,
grn_user_data
*user_data)
26
{
27
grn_obj
*obj, *caller;
28
uint32_t nvars;
29
grn_expr_var
*vars;
30
unsigned
int
length = 0;
31
grn_proc_get_info
(ctx, user_data, &vars, &nvars, &caller);
32
if
(nargs == 1) {
33
grn_obj
*text = args[0];
34
size_t
len =
GRN_TEXT_LEN
(text);
35
char
*null_terminated_text = malloc(len + 1);
36
memcpy(null_terminated_text,
GRN_TEXT_VALUE
(text), len);
37
null_terminated_text[len] =
'\0'
;
38
length =
grn_str_len
(ctx, null_terminated_text, ctx->
encoding
, NULL);
39
free(null_terminated_text);
40
}
41
if
((obj =
grn_expr_alloc
(ctx, caller,
GRN_DB_UINT32
, 0))) {
42
GRN_UINT32_SET
(ctx, obj, length);
43
}
44
return
obj;
45
}
46
47
grn_rc
48
GRN_PLUGIN_INIT
(
grn_ctx
*ctx)
49
{
50
return
GRN_SUCCESS
;
51
}
52
53
grn_rc
54
GRN_PLUGIN_REGISTER
(
grn_ctx
*ctx)
55
{
56
grn_proc_create
(ctx,
"str_len"
, strlen(
"str_len"
),
GRN_PROC_FUNCTION
,
57
func_str_len, NULL, NULL, 0, NULL);
58
59
return
ctx->
rc
;
60
}
61
62
grn_rc
63
GRN_PLUGIN_FIN
(
grn_ctx
*ctx)
64
{
65
return
GRN_SUCCESS
;
66
}
Generated on Sun Nov 10 2013 09:49:04 for Groonga 3.0.9 Source Code Document by
1.8.1.2