| 1 | /* -*- c-basic-offset: 2 -*- */ |
| 2 | /* |
| 3 | Copyright(C) 2015-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 | |
| 23 | #include "ts_types.h" |
| 24 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
| 29 | /*------------------------------------------------------------- |
| 30 | * Byte. |
| 31 | */ |
| 32 | |
| 33 | /* grn_ts_byte_is_decimal() returns whether or not a byte is decimal. */ |
| 34 | grn_ts_bool grn_ts_byte_is_decimal(uint8_t byte); |
| 35 | |
| 36 | /* |
| 37 | * grn_ts_byte_is_name_char() returns whether or not a byte is allowed as a |
| 38 | * part of a name. |
| 39 | */ |
| 40 | grn_ts_bool grn_ts_byte_is_name_char(uint8_t byte); |
| 41 | |
| 42 | /*------------------------------------------------------------- |
| 43 | * String. |
| 44 | */ |
| 45 | |
| 46 | typedef struct { |
| 47 | const char *ptr; /* The starting address. */ |
| 48 | size_t size; /* The size in bytes. */ |
| 49 | } grn_ts_str; |
| 50 | |
| 51 | /* grn_ts_str_has_prefix() returns whether or not str starts with prefix. */ |
| 52 | grn_ts_bool grn_ts_str_starts_with(grn_ts_str str, grn_ts_str prefix); |
| 53 | |
| 54 | /* grn_ts_str_trim_left() returns a string without leading white-spaces. */ |
| 55 | grn_ts_str grn_ts_str_trim_left(grn_ts_str str); |
| 56 | |
| 57 | /* |
| 58 | * grn_ts_str_trim_score_assignment() returns a string without leading |
| 59 | * white-spaces and an assignment to _score. If `str` does not start with |
| 60 | * an assignment, this function returns `grn_ts_str_trim_left(str)`. |
| 61 | */ |
| 62 | grn_ts_str grn_ts_str_trim_score_assignment(grn_ts_str str); |
| 63 | |
| 64 | /* |
| 65 | * grn_ts_str_has_number_prefix() returns whether or not a string starts with a |
| 66 | * number or not. |
| 67 | */ |
| 68 | grn_ts_bool grn_ts_str_has_number_prefix(grn_ts_str str); |
| 69 | |
| 70 | /* |
| 71 | * grn_ts_str_is_name_prefix() returns whether or not a string is valid as a |
| 72 | * name prefix. Note that an empty string is a name prefix. |
| 73 | */ |
| 74 | grn_ts_bool grn_ts_str_is_name_prefix(grn_ts_str str); |
| 75 | |
| 76 | /* |
| 77 | * grn_ts_str_is_name() returns whether or not a string is valid as a name. |
| 78 | * Note that an empty string is invalid as a name. |
| 79 | */ |
| 80 | grn_ts_bool grn_ts_str_is_name(grn_ts_str str); |
| 81 | |
| 82 | /* grn_ts_str_is_true() returns str == "true". */ |
| 83 | grn_ts_bool grn_ts_str_is_true(grn_ts_str str); |
| 84 | |
| 85 | /* grn_ts_str_is_false() returns str == "false". */ |
| 86 | grn_ts_bool grn_ts_str_is_false(grn_ts_str str); |
| 87 | |
| 88 | /* grn_ts_str_is_bool() returns (str == "true") || (str == "false"). */ |
| 89 | grn_ts_bool grn_ts_str_is_bool(grn_ts_str str); |
| 90 | |
| 91 | /* grn_ts_str_is_id_name() returns str == "_id". */ |
| 92 | grn_ts_bool grn_ts_str_is_id_name(grn_ts_str str); |
| 93 | |
| 94 | /* grn_ts_str_is_score_name() returns str == "_score". */ |
| 95 | grn_ts_bool grn_ts_str_is_score_name(grn_ts_str str); |
| 96 | |
| 97 | /* grn_ts_str_is_key_name() returns str == "_key". */ |
| 98 | grn_ts_bool grn_ts_str_is_key_name(grn_ts_str str); |
| 99 | |
| 100 | /* grn_ts_str_is_value_name() returns str == "_value". */ |
| 101 | grn_ts_bool grn_ts_str_is_value_name(grn_ts_str str); |
| 102 | |
| 103 | #ifdef __cplusplus |
| 104 | } |
| 105 | #endif |
| 106 | |
| 107 | |