1 /* Copyright(C) 2004 Brazil 2 3 This library is free software; you can redistribute it and/or 4 modify it under the terms of the GNU Lesser General Public 5 License as published by the Free Software Foundation; either 6 version 2.1 of the License, or (at your option) any later version. 7 8 This library is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 Lesser General Public License for more details. 12 13 You should have received a copy of the GNU Lesser General Public 14 License along with this library; if not, write to the Free Software 15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 */ 17 #ifndef SEN_STR_H 18 #define SEN_STR_H 19 20 #ifndef SENNA_H 21 #include "senna_in.h" 22 #endif /* SENNA_H */ 23 24 #ifndef SEN_NFKC_H 25 #include "nfkc.h" 26 #endif /* SEN_NFKC_H */ 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 typedef struct { 33 const char *orig; 34 size_t orig_blen; 35 char *norm; 36 size_t norm_blen; 37 uint_least8_t *ctypes; 38 int16_t *checks; 39 size_t length; 40 int flags; 41 sen_ctx *ctx; 42 sen_encoding encoding; 43 } sen_nstr; 44 45 typedef enum { 46 getopt_op_none = 0, 47 getopt_op_on, 48 getopt_op_off, 49 getopt_op_update 50 } sen_str_getopt_op; 51 52 typedef struct { 53 const char opt; /* ends opt == 0 && longopt == NULL */ 54 const char *longopt; 55 char **arg; /* if NULL, no arg are required */ 56 int flag; 57 sen_str_getopt_op op; 58 } sen_str_getopt_opt; 59 60 int sen_str_get_prefix_order(const char *str); 61 62 sen_nstr *sen_nstr_open(const char *str, size_t str_len, sen_encoding encoding, int flags); 63 sen_nstr *sen_fakenstr_open(const char *str, size_t str_len, sen_encoding encoding, int flags); 64 sen_rc sen_nstr_close(sen_nstr *nstr); 65 66 size_t sen_str_charlen_nonnull(const char *str, const char *end, sen_encoding encoding); 67 size_t sen_str_len(const char *str, sen_encoding encoding, const char **last); 68 sen_rc sen_str_fin(void); 69 70 #define SEN_NSTR_BLANK 0x80 71 #define SEN_NSTR_ISBLANK(c) (c & 0x80) 72 #define SEN_NSTR_CTYPE(c) (c & 0x7f) 73 74 int sen_isspace(const char *s, sen_encoding encoding); 75 int sen_atoi(const char *nptr, const char *end, const char **rest); 76 unsigned int sen_atoui(const char *nptr, const char *end, const char **rest); 77 unsigned int sen_htoui(const char *nptr, const char *end, const char **rest); 78 int64_t sen_atoll(const char *nptr, const char *end, const char **rest); 79 sen_rc sen_str_itoa(int i, char *p, char *end, char **rest); 80 sen_rc sen_str_lltoa(int64_t i, char *p, char *end, char **rest); 81 const char *sen_enctostr(sen_encoding enc); 82 sen_encoding sen_strtoenc(const char *str); 83 84 void sen_str_itoh(unsigned int i, char *p, unsigned int len); 85 int sen_str_tok(char *str, size_t str_len, char delim, char **tokbuf, int buf_size, char **rest); 86 int sen_str_getopt(int argc, char * const argv[], const sen_str_getopt_opt *opts, int *flags); 87 88 typedef struct _sen_rbuf sen_rbuf; 89 90 extern int sen_rbuf_margin_size; 91 92 struct _sen_rbuf { 93 char *head; 94 char *curr; 95 char *tail; 96 }; 97 98 typedef struct _sen_lbuf_node sen_lbuf_node; 99 100 typedef struct { 101 sen_lbuf_node *head; 102 sen_lbuf_node **tail; 103 } sen_lbuf; 104 105 sen_rc sen_rbuf_init(sen_rbuf *buf, size_t size); 106 sen_rc sen_rbuf_reinit(sen_rbuf *buf, size_t size); 107 sen_rc sen_rbuf_resize(sen_rbuf *buf, size_t newsize); 108 sen_rc sen_rbuf_write(sen_rbuf *buf, const char *str, size_t len); 109 sen_rc sen_rbuf_reserve(sen_rbuf *buf, size_t len); 110 sen_rc sen_rbuf_space(sen_rbuf *buf, size_t len); 111 sen_rc sen_rbuf_itoa(sen_rbuf *buf, int i); 112 sen_rc sen_rbuf_lltoa(sen_rbuf *buf, int64_t i); 113 sen_rc sen_rbuf_ftoa(sen_rbuf *buf, double d); 114 sen_rc sen_rbuf_itoh(sen_rbuf *buf, int i); 115 sen_rc sen_rbuf_itob(sen_rbuf *buf, sen_id id); 116 sen_rc sen_rbuf_lltob32h(sen_rbuf *buf, int64_t i); 117 sen_rc sen_rbuf_fin(sen_rbuf *buf); 118 void sen_rbuf_str_esc(sen_rbuf *buf, const char *s, int len, sen_encoding encoding); 119 120 #define SEN_RBUF_PUTS(buf,str) (sen_rbuf_write((buf), (str), strlen(str))) 121 #define SEN_RBUF_PUTC(buf,c) { char _c = (c); sen_rbuf_write((buf), &_c, 1); } 122 #define SEN_RBUF_REWIND(buf) ((buf)->curr = (buf)->head) 123 #define SEN_RBUF_WSIZE(buf) ((buf)->tail - (buf)->head) 124 #define SEN_RBUF_REST(buf) ((buf)->tail - (buf)->curr) 125 #define SEN_RBUF_VSIZE(buf) ((buf)->curr - (buf)->head) 126 #define SEN_RBUF_EMPTYP(buf) ((buf)->curr == (buf)->head) 127 128 sen_rc sen_lbuf_init(sen_lbuf *buf); 129 void *sen_lbuf_add(sen_lbuf *buf, size_t size); 130 sen_rc sen_lbuf_fin(sen_lbuf *buf); 131 132 char *sen_str_itob(sen_id id, char *p); 133 sen_id sen_str_btoi(char *b); 134 135 sen_rc sen_substring(char **str, char **str_end, int start, int end, sen_encoding encoding); 136 137 void sen_logger_fin(void); 138 139 #ifdef __cplusplus 140 } 141 #endif 142 143 #endif /* SEN_STR_H */ 144