File: WordCompletionThread.cpp

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (69 lines) | stat: -rw-r--r-- 2,010 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
#include "WordCompletionThread.h"
#include "wordcompletion.h"
#include "macros.h"
#include "WordCompletionSettings.h"
#include "WordCompletionDictionary.h"
#include "WordTokenizerAPI.h"

WordCompletionThread::WordCompletionThread(WordCompletionDictionary* dict)
    : m_dict(dict)
{
}

WordCompletionThread::~WordCompletionThread() {}
void WordCompletionThread::ProcessRequest(ThreadRequest* request)
{
    WordCompletionThreadRequest* req = dynamic_cast<WordCompletionThreadRequest*>(request);
    CHECK_PTR_RET(req);

    wxStringSet_t suggestsions;
    ParseBuffer(req->buffer, suggestsions);

    // Parse and send back the reply
    WordCompletionThreadReply reply;
    reply.filename = req->filename;
    reply.filter = req->filter;
    reply.insertSingleMatch = req->insertSingleMatch;
    reply.suggest.swap(suggestsions);
    m_dict->CallAfter(&WordCompletionDictionary::OnSuggestThread, reply);
}

void WordCompletionThread::ParseBuffer(const wxString& buffer, wxStringSet_t& suggest)
{
#if 0
    wxArrayString filteredWords;
    wxArrayString words = ::wxStringTokenize(buffer, "\r\n \t->./\\'\"[]()<>*&^%#!@+=:,;{}|/", wxTOKEN_STRTOK);
    for(size_t i=0; i<words.size(); ++i) {
        if(!wxIsdigit(words.Item(i).at(0))) {
            filteredWords.Add(words.Item(i));
        }
    }
    suggest.insert(filteredWords.begin(), filteredWords.end());
#else
    WordScanner_t scanner = ::WordLexerNew(buffer);
    if(!scanner) return;
    WordLexerToken token;
    std::string curword;
    while(::WordLexerNext(scanner, token)) {
        switch(token.type) {
        case kWordDelim:
            if(!curword.empty()) {
                suggest.insert(curword);
            }
            curword.clear();
            break;

        case kWordNumber: {
            if(!curword.empty()) {
                curword += token.text;
            }
            break;
        }
        default:
            curword += token.text;
            break;
        }
    }
    ::WordLexerDestroy(&scanner);
#endif
}