@@ -198,18 +198,53 @@ 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_DOUBLE] = */ "double" ,
207
+ /* [FIELD_TYPE_INTEGER] = */ "integer" ,
208
+ /* [FIELD_TYPE_BOOLEAN] = */ "boolean" ,
209
+ /* [FIELD_TYPE_VARBINARY] = */ "varbinary" ,
210
+ /* [FIELD_TYPE_SCALAR] = */ "scalar" ,
211
+ /* [FIELD_TYPE_DECIMAL] = */ "decimal" ,
212
+ /* [FIELD_TYPE_UUID] = */ "uuid" ,
213
+ /* [FIELD_TYPE_ARRAY] = */ "array" ,
214
+ /* [FIELD_TYPE_MAP] = */ "map" ,
215
+ };
216
+
217
+ /**
218
+ * Find a string in an array of strings.
219
+ */
220
+ static uint32_t
221
+ strnindex (const char * * haystack , const char * needle , uint32_t len , uint32_t hmax )
222
+ {
223
+ if (len == 0 )
224
+ return hmax ;
225
+ for (unsigned index = 0 ; index != hmax && haystack [index ]; ++ index ) {
226
+ if (strncasecmp (haystack [index ], needle , len ) == 0 &&
227
+ strlen (haystack [index ]) == len )
228
+ return index ;
211
229
}
212
- return FT_OTHER ;
230
+ return hmax ;
231
+ }
232
+
233
+ static enum field_type
234
+ field_type_by_name (const char * name , size_t len )
235
+ {
236
+ enum field_type field_type = strnindex (field_type_strs , name , len ,
237
+ field_type_MAX );
238
+ if (field_type != field_type_MAX )
239
+ return field_type ;
240
+ /* 'num' and 'str' in _index are deprecated since Tarantool 1.7 */
241
+ if (strncasecmp (name , "num" , len ) == 0 )
242
+ return FIELD_TYPE_UNSIGNED ;
243
+ else if (strncasecmp (name , "str" , len ) == 0 )
244
+ return FIELD_TYPE_STRING ;
245
+ else if (len == 1 && name [0 ] == '*' )
246
+ return FIELD_TYPE_ANY ;
247
+ return field_type_MAX ;
213
248
}
214
249
215
250
static int
@@ -231,7 +266,7 @@ parse_schema_space_value_value(struct schema_field_value *fld,
231
266
if (mp_typeof (* * tuple ) != MP_STR )
232
267
goto error ;
233
268
sfield = mp_decode_str (tuple , & sfield_len );
234
- fld -> field_type = parse_field_type (sfield , sfield_len );
269
+ fld -> field_type = field_type_by_name (sfield , sfield_len );
235
270
} else {
236
271
mp_next (tuple );
237
272
}
@@ -293,7 +328,7 @@ decode_index_parts_166(struct schema_field_value *parts, uint32_t part_count,
293
328
return -1 ;
294
329
uint32_t len ;
295
330
const char * str = mp_decode_str (data , & len );
296
- part -> field_type = parse_field_type (str , len );
331
+ part -> field_type = field_type_by_name (str , len );
297
332
298
333
for (uint32_t j = 2 ; j < item_count ; ++ j )
299
334
mp_next (data );
0 commit comments