Few small changes.
[qshowdiff.git] / src / parser / tokens.cpp
blob10b6be4adab95252a9ecbbb6ac18a49cb8653527
1 #include "tokens.h"
2 using std::string;
4 Tokens *TokenFactory(string type)
6 Tokens *ret = NULL;
8 if (type == "git"){
9 ret = new TokensGit();
10 }else if (type == "svn"){
11 ret = new TokensSvn();
14 DBG("factory(" << type << ") - ret: " << (long)ret);
15 return ret;
19 Tokens::Tokens(const char *f_tok,
20 const char *h_tok,
21 const char *c_tok,
22 const char *a_tok,
23 const char *d_tok) :
24 file_tok(f_tok),
25 hunk_tok(h_tok),
26 context_tok(c_tok),
27 added_tok(a_tok),
28 deleted_tok(d_tok){}
30 Tokens::token Tokens::match(QString &line) const
32 if (file_tok.indexIn(line) != -1){
33 return FILE_TOK;
34 }else if (hunk_tok.indexIn(line) != -1){
35 return HUNK_TOK;
36 }else if (context_tok.indexIn(line) != -1){
37 return CONTEXT_TOK;
38 }else if (added_tok.indexIn(line) != -1){
39 return ADDED_TOK;
40 }else if (deleted_tok.indexIn(line) != -1){
41 return DELETED_TOK;
44 return NONE_TOK;
47 /* CONCRETE TOKENS: */
48 TokensGit::TokensGit() : Tokens::Tokens("^diff --git a/([^ ]+) b/.*$",
49 "^@@ -([0-9]+),.* \\+([0-9]+),.*$",
50 "^ .*$",
51 "^\\+.*$",
52 "^-.*$"){}
54 TokensSvn::TokensSvn() : Tokens::Tokens("^Index: ([^ ]+).*$",
55 "^@@ -([0-9]+),.* \\+([0-9]+),.*$",
56 "^ .*$",
57 "^\\+.*$",
58 "^-.*$"){}