factory - reading from index file
| 326 | |
| 327 | /// factory - reading from index file |
| 328 | TinyDictWord * TinyDictWord::read( FILE * f, unsigned index ) |
| 329 | { |
| 330 | if ( !f || feof(f) ) |
| 331 | return NULL; |
| 332 | char buf[1024]; |
| 333 | unsigned indexpos = ftell( f ); |
| 334 | int sz = my_fgets( buf, 1023, f ); |
| 335 | if ( !sz ) |
| 336 | return NULL; |
| 337 | int tabc = 0; |
| 338 | int tabs[2]; |
| 339 | for ( int i=0; buf[i]; i++ ) { |
| 340 | if ( buf[i] == '\t' && tabc<2 ) |
| 341 | tabs[tabc++] = i; |
| 342 | } |
| 343 | if ( tabc!=2 ) |
| 344 | return NULL; |
| 345 | const char * word = buf; |
| 346 | const char * pos_str = buf + tabs[0] + 1; |
| 347 | const char * len_str = buf + tabs[1] + 1; |
| 348 | buf[tabs[0]] = 0; |
| 349 | buf[tabs[1]] = 0; |
| 350 | unsigned start = parseBase64( pos_str ); |
| 351 | unsigned len = parseBase64( len_str ); |
| 352 | if ( start==(unsigned)-1 || len==(unsigned)-1 ) |
| 353 | return NULL; |
| 354 | return new TinyDictWord( index, indexpos, start, len, word ); |
| 355 | } |
| 356 | |
| 357 | int TinyDictWordList::find( const char * prefix ) |
| 358 | { |
no test coverage detected