-------------------------------------------------------------------------*/ @brief Get a value from a dictionary. @param d dictionary object to search. @param key Key to look for in the dictionary. @param def Default value to return if key not found. @return 1 pointer to internally allocated character string. This function locates a key in a dictionary and re
| 337 | */ |
| 338 | /*--------------------------------------------------------------------------*/ |
| 339 | static char * dictionary_get(dictionary * d, char * key, char * def) |
| 340 | { |
| 341 | unsigned hash ; |
| 342 | int i ; |
| 343 | |
| 344 | hash = dictionary_hash(key); |
| 345 | for (i=0 ; i<d->size ; i++) { |
| 346 | if (d->key==NULL) |
| 347 | continue ; |
| 348 | /* Compare hash */ |
| 349 | if (hash==d->hash[i]) { |
| 350 | /* Compare string, to avoid hash collisions */ |
| 351 | if (!strcmp(key, d->key[i])) { |
| 352 | return d->val[i] ; |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | return def ; |
| 357 | } |
| 358 | |
| 359 | |
| 360 | /*-------------------------------------------------------------------------*/ |
no test coverage detected