1/* -*- c-basic-offset: 2 -*- */
2/*
3 Copyright(C) 2009-2016 Brazil
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#pragma once
20
21#include "grn.h"
22#include <groonga/nfkc.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28typedef enum {
29 GETOPT_OP_NONE = 0,
30 GETOPT_OP_ON,
31 GETOPT_OP_OFF,
32 GETOPT_OP_UPDATE
33} grn_str_getopt_op;
34
35typedef struct {
36 const char opt; /* ends opt == 0 && longopt == NULL */
37 const char *longopt;
38 const char **arg; /* if NULL, no arg are required */
39 int flag;
40 grn_str_getopt_op op;
41} grn_str_getopt_opt;
42
43GRN_API size_t grn_str_len(grn_ctx *ctx, const char *str, grn_encoding encoding, const char **last);
44
45#define GRN_STR_BLANK 0x80
46#define GRN_STR_ISBLANK(c) (c & 0x80)
47#define GRN_STR_CTYPE(c) (c & 0x7f)
48
49GRN_API int grn_isspace(const char *s, grn_encoding encoding);
50int8_t grn_atoi8(const char *nptr, const char *end, const char **rest);
51uint8_t grn_atoui8(const char *nptr, const char *end, const char **rest);
52int16_t grn_atoi16(const char *nptr, const char *end, const char **rest);
53uint16_t grn_atoui16(const char *nptr, const char *end, const char **rest);
54GRN_API int grn_atoi(const char *nptr, const char *end, const char **rest);
55GRN_API unsigned int grn_atoui(const char *nptr, const char *end, const char **rest);
56unsigned int grn_htoui(const char *nptr, const char *end, const char **rest);
57GRN_API int64_t grn_atoll(const char *nptr, const char *end, const char **rest);
58GRN_API uint64_t grn_atoull(const char *nptr, const char *end, const char **rest);
59grn_rc grn_itoa(int i, char *p, char *end, char **rest);
60grn_rc grn_lltoa(int64_t i, char *p, char *end, char **rest);
61grn_rc grn_ulltoa(uint64_t i, char *p, char *end, char **rest);
62GRN_API grn_rc grn_aton(grn_ctx *ctx, const char *p, const char *end, const char **rest, grn_obj *res);
63
64GRN_API void grn_itoh(unsigned int i, char *p, unsigned int len);
65int grn_str_tok(const char *str, size_t str_len, char delim, const char **tokbuf, int buf_size, const char **rest);
66GRN_API int grn_str_getopt(int argc, char * const argv[], const grn_str_getopt_opt *opts, int *flags);
67
68extern int grn_str_margin_size;
69
70char *grn_itob(grn_id id, char *p);
71grn_id grn_btoi(char *b);
72
73grn_rc grn_substring(grn_ctx *ctx, char **str, char **str_end, int start, int end, grn_encoding encoding);
74
75GRN_API int grn_charlen_(grn_ctx *ctx, const char *str, const char *end, grn_encoding encoding);
76GRN_API grn_str *grn_str_open_(grn_ctx *ctx, const char *str, unsigned int str_len, int flags, grn_encoding encoding);
77
78#define GRN_BULK_SET_CURR(buf,p) do {\
79 if (GRN_BULK_OUTP(buf)) {\
80 (buf)->u.b.curr = (char *)(p);\
81 } else {\
82 (buf)->header.flags = (char *)(p) - GRN_BULK_HEAD(buf);\
83 }\
84} while (0)
85
86grn_rc grn_text_ulltoa(grn_ctx *ctx, grn_obj *buf, unsigned long long int i);
87
88GRN_API const char *grn_text_cgidec(grn_ctx *ctx, grn_obj *buf,
89 const char *p, const char *e,
90 const char *delimiters);
91
92#define GRN_TOK_VOID (0x00)
93#define GRN_TOK_SYMBOL (0x01)
94#define GRN_TOK_STRING (0x02)
95#define GRN_TOK_QUOTE (0x03)
96
97GRN_API const char *grn_text_unesc_tok(grn_ctx *ctx, grn_obj *buf,
98 const char *p, const char *e,
99 char *tok_type);
100
101GRN_API void grn_str_url_path_normalize(grn_ctx *ctx,
102 const char *path, size_t path_len,
103 char *buf, size_t buf_len);
104
105#define GRN_OBJ_FORMAT_XML_ELEMENT_MASK (0x01<<1)
106#define GRN_OBJ_FORMAT_XML_ELEMENT_RESULTSET (0x00<<1)
107#define GRN_OBJ_FORMAT_XML_ELEMENT_NAVIGATIONENTRY (0x01<<1)
108
109#include <stdio.h>
110GRN_API grn_rc grn_text_fgets(grn_ctx *ctx, grn_obj *buf, FILE *fp);
111
112grn_bool grn_bulk_is_zero(grn_ctx *ctx, grn_obj *obj);
113
114#ifdef __cplusplus
115}
116#endif
117