File: completion.cpp

package info (click to toggle)
libopendbx 1.4.6-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,960 kB
  • ctags: 1,006
  • sloc: sh: 10,899; ansic: 7,283; xml: 1,837; cpp: 1,696; makefile: 362; sed: 16
file content (63 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download | duplicates (7)
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;
// }