Optimize speed of icu_iter_get_org_info
[yaz-moved-to-github.git] / src / cqlstring.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5 /**
6  * \file cqlstring.c
7  * \brief Implements query stream reader that reads from a C string.
8  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include <yaz/cql.h>
14
15 struct cql_buf_info {
16     const char *str;
17     int off;
18 };
19
20 static int getbuf(void *vp)
21 {
22     struct cql_buf_info *bi = (struct cql_buf_info *) vp;
23     if (bi->str[bi->off] == 0)
24         return 0;
25     return bi->str[bi->off++];
26 }
27
28 static void ungetbuf(int b, void *vp)
29 {
30     struct cql_buf_info *bi = (struct cql_buf_info *) vp;
31     if (b)
32         (bi->off--);
33 }
34
35 int cql_parser_string(CQL_parser cp, const char *str)
36 {
37     struct cql_buf_info b;
38
39     b.str = str;
40     b.off = 0;
41
42     return cql_parser_stream(cp, getbuf, ungetbuf, &b);
43 }
44
45 /*
46  * Local variables:
47  * c-basic-offset: 4
48  * c-file-style: "Stroustrup"
49  * indent-tabs-mode: nil
50  * End:
51  * vim: shiftwidth=4 tabstop=8 expandtab
52  */
53