1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include "completion.hpp"
#include <iostream>
#include <fstream>
#include <string.h>
Completion::Completion( const string& filename )
{
string keyword;
std::ifstream ifs( filename.c_str() );
while( getline( ifs, keyword ) )
{
if( keyword.size() > 0 && keyword[0] != '#' ) { m_keywords[keyword] = ""; }
}
ifs.close();
}
void Completion::find( const char* keyword )
{
m_keyword = string( keyword );
for( m_next = m_keywords.begin(); m_next != m_keywords.end(); m_next++ )
{
if( !strncasecmp( m_keyword.c_str(), m_next->first.c_str(), m_keyword.size() ) ) { return; }
}
}
const char* Completion::get()
{
if( m_next != m_keywords.end() && !strncasecmp( m_keyword.c_str(), m_next->first.c_str(), m_keyword.size() ) )
{
map<string, string>::iterator cur = m_next;
m_next++;
return cur->first.c_str();
}
return NULL;
}
// int main( void )
// {
// char* keyword;
// Completion cmpl( "keywords" );
//
// cmpl.find( "DE" );
//
// while( ( keyword = cmpl.get() ) != NULL )
// {
// std::cout << keyword << std::endl;
// }
//
// return 0;
// }
|