picox  0.1
xtokenizer.h
[詳解]
1 
14 /*
15  * License: MIT license
16  * Copyright (c) <2015> <MaskedW [maskedw00@gmail.com]>
17  *
18  * Permission is hereby granted, free of charge, to any person
19  * obtaining a copy of this software and associated documentation
20  * files (the "Software"), to deal in the Software without
21  * restriction, including without limitation the rights to use, copy,
22  * modify, merge, publish, distribute, sublicense, and/or sell copies
23  * of the Software, and to permit persons to whom the Software is
24  * furnished to do so, subject to the following conditions:
25  *
26  * The above copyright notice and this permission notice shall be
27  * included in all copies or substantial portions of the Software.
28  *
29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36  * SOFTWARE.
37  */
38 
39 #ifndef picox_misc_xtokenizer_h_
40 #define picox_misc_xtokenizer_h_
41 
42 
43 #include <picox/core/xcore.h>
44 
45 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 
65 typedef struct XTokenizer
66 {
68  char* row;
69  char** tokens;
70  int ntokens;
71 } XTokenizer;
72 
73 
90 bool xtok_init(XTokenizer* self, const char* row, char separater, int max_tokens);
91 
92 
98 void xtok_release(XTokenizer* self);
99 
100 
106 static inline const char*
107 xtok_ref_token(const XTokenizer* self, int col)
108 {
109  X_ASSERT(self);
110  X_ASSERT(x_is_within(col, 0, self->ntokens));
111  return self->tokens[col];
112 }
113 
114 
117 static inline int
119 {
120  X_ASSERT(self);
121  return self->ntokens;
122 }
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 
128 
134 #endif // picox_misc_xtokenizer_h_
static bool x_is_within(int32_t x, int32_t begin, int32_t end)
(begin <= x) && (x < end)を判定します。
Definition: xutils.h:715
static int xtok_num_tokens(const XTokenizer *self)
列数を返します
Definition: xtokenizer.h:118
void xtok_release(XTokenizer *self)
オブジェクトが保持するリソースを解放します。
Definition: xtokenizer.c:98
bool xtok_init(XTokenizer *self, const char *row, char separater, int max_tokens)
文字列を指定文字で列に分解します。
Definition: xtokenizer.c:42
static const char * xtok_ref_token(const XTokenizer *self, int col)
列を参照します
Definition: xtokenizer.h:107
トークン化した文字列の管理構造体
Definition: xtokenizer.h:65