@@ -198,18 +198,49 @@ schema_space_free(struct mh_schema_space_t *schema) {
198
198
}
199
199
}
200
200
201
- int parse_field_type (const char * sfield , size_t sfield_len ) {
202
- if (sfield_len == 3 ) {
203
- if (tolower (sfield [0 ]) == 's' &&
204
- tolower (sfield [1 ]) == 't' &&
205
- tolower (sfield [2 ]) == 'r' )
206
- return FT_STR ;
207
- if (tolower (sfield [0 ]) == 'n' &&
208
- tolower (sfield [1 ]) == 'u' &&
209
- tolower (sfield [2 ]) == 'm' )
210
- return FT_NUM ;
201
+ static const char * field_type_strs [] = {
202
+ /* [FIELD_TYPE_ANY] = */ "any" ,
203
+ /* [FIELD_TYPE_UNSIGNED] = */ "unsigned" ,
204
+ /* [FIELD_TYPE_STRING] = */ "string" ,
205
+ /* [FIELD_TYPE_NUMBER] = */ "number" ,
206
+ /* [FIELD_TYPE_INTEGER] = */ "integer" ,
207
+ /* [FIELD_TYPE_BOOLEAN] = */ "boolean" ,
208
+ /* [FIELD_TYPE_SCALAR] = */ "scalar" ,
209
+ /* [FIELD_TYPE_ARRAY] = */ "array" ,
210
+ /* [FIELD_TYPE_MAP] = */ "map" ,
211
+ };
212
+
213
+ /**
214
+ * Find a string in an array of strings.
215
+ */
216
+ static uint32_t
217
+ strnindex (const char * * haystack , const char * needle , uint32_t len , uint32_t hmax )
218
+ {
219
+ if (len == 0 )
220
+ return hmax ;
221
+ for (unsigned index = 0 ; index != hmax && haystack [index ]; ++ index ) {
222
+ if (strncasecmp (haystack [index ], needle , len ) == 0 &&
223
+ strlen (haystack [index ]) == len )
224
+ return index ;
211
225
}
212
- return FT_OTHER ;
226
+ return hmax ;
227
+ }
228
+
229
+ static enum field_type
230
+ field_type_by_name (const char * name , size_t len )
231
+ {
232
+ enum field_type field_type = strnindex (field_type_strs , name , len ,
233
+ field_type_MAX );
234
+ if (field_type != field_type_MAX )
235
+ return field_type ;
236
+ /* 'num' and 'str' in _index are deprecated since Tarantool 1.7 */
237
+ if (strncasecmp (name , "num" , len ) == 0 )
238
+ return FIELD_TYPE_UNSIGNED ;
239
+ else if (strncasecmp (name , "str" , len ) == 0 )
240
+ return FIELD_TYPE_STRING ;
241
+ else if (len == 1 && name [0 ] == '*' )
242
+ return FIELD_TYPE_ANY ;
243
+ return field_type_MAX ;
213
244
}
214
245
215
246
static int
@@ -231,7 +262,7 @@ parse_schema_space_value_value(struct schema_field_value *fld,
231
262
if (mp_typeof (* * tuple ) != MP_STR )
232
263
goto error ;
233
264
sfield = mp_decode_str (tuple , & sfield_len );
234
- fld -> field_type = parse_field_type (sfield , sfield_len );
265
+ fld -> field_type = field_type_by_name (sfield , sfield_len );
235
266
} else {
236
267
mp_next (tuple );
237
268
}
@@ -293,7 +324,7 @@ decode_index_parts_166(struct schema_field_value *parts, uint32_t part_count,
293
324
return -1 ;
294
325
uint32_t len ;
295
326
const char * str = mp_decode_str (data , & len );
296
- part -> field_type = parse_field_type (str , len );
327
+ part -> field_type = field_type_by_name (str , len );
297
328
298
329
for (uint32_t j = 2 ; j < item_count ; ++ j )
299
330
mp_next (data );
0 commit comments