Пример #1
0
void command_remove(FILE * f) {
	char word[130];
	read_word(word, 130);

	int count = remove_words(f, word);
	if (count == 0)
		printf("[INFO] Нет такого слова.\n");
	else if (count == 1)
		printf("[INFO] Слово удалено.\n");
	else
		printf("[WARNING] Удалено %d вхождений.\n", count);

}
Пример #2
0
void command_add(FILE * f) {
	char word[130];
	read_word(word, 130);

	uint64 index = find_word(f, word);
	if (0 == index) {
		// Слова нет, можно добавлять
		char * content = read_content();
		add_word(f, word, content);
		free( content );
	} else {
		// найденное слово запомним
		struct entry_t entry;
		read_entry(f, &entry, index, READ_ENTRY_WORD | READ_ENTRY_DO_SEEK);
		remove_words(f, entry.word);
		char * content = read_content();
		add_word(f, entry.word, content);
		free( content );
		free_entry(&entry);

		//TODO( "Прочитать толкование, запомнить слово, вставить новую, удалить старую." );
	}
}
Пример #3
0
void process_vocab( vector<textwords, allocator>*pvec )
{
	if ( !pvec ) 
	     // issue warning message
		return;

	vector< string, allocator > texts; 

	vector<textwords, allocator>::iterator iter = pvec->begin();
	for ( ; iter != pvec->end(); ++iter )
      		copy( (*iter).begin(), (*iter).end(), back_inserter( texts ));

	// sort the elements of texts
	sort( texts.begin(), texts.end() );
	for_each( texts.begin(), texts.end(), PrintElem() );

	cout << endl << endl;

	// delete all duplicate elements 
	vector<string, allocator>::iterator it;
	it = unique( texts.begin(), texts.end() );
	texts.erase( it, texts.end() );
	for_each( texts.begin(), texts.end(), PrintElem() );

	cout << endl << endl;

	stable_sort( texts.begin(), texts.end(), LessThan() );
	for_each( texts.begin(), texts.end(), PrintElem() );

	cout << endl << endl;

	// count number of strings greater than length 6
	int cnt = 0;

	// obsolete form of count -- standard changes this
	count_if( texts.begin(), texts.end(), GreaterThan(), cnt );

	cout << "Number of words greater than length six are "
     		<< cnt << endl;
	// ...

	static string rw[] = { "and", "if", "or", "but", "the" };
	vector<string,allocator> remove_words( rw, rw+5 );

	vector<string, allocator>::iterator it2 = remove_words.begin();
	for ( ; it2 != remove_words.end(); ++it2 ) {
		int cnt = 0;
		// obsolete form of count -- standard changes this
        	count( texts.begin(), texts.end(), *it2, cnt );
	
		cout << cnt << " instances removed:  " 
	     		<< (*it2) << endl;
	
	    	texts.erase(
	    		remove(texts.begin(),texts.end(),*it2),
	    		texts.end()
	   	);
   	}

	cout << endl << endl;
	for_each( texts.begin(), texts.end(), PrintElem() );
}