Files parser.{h,cpp} splitted into parser.{h,cpp} and tokens.{h,cpp}.
[qshowdiff.git] / src / parser / tokens.cpp
blob5be2e53d9d4e57bdacc34ba688b4615485755b91
1 #include "tokens.h"
2 using std::string;
4 Tokens *factory(string type)
6 Tokens *ret;
8 ret = new TokensGit();
9 DBG("factory(" << type << ") - ret: " << (long)ret);
10 return ret;
14 Tokens::Tokens(const char *f_tok,
15 const char *h_tok,
16 const char *c_tok,
17 const char *a_tok,
18 const char *d_tok) :
19 file_tok(f_tok),
20 hunk_tok(h_tok),
21 context_tok(c_tok),
22 added_tok(a_tok),
23 deleted_tok(d_tok){}
25 Tokens::token Tokens::match(QString &line) const
27 if (file_tok.indexIn(line) != -1){
28 return FILE_TOK;
29 }else if (hunk_tok.indexIn(line) != -1){
30 return HUNK_TOK;
31 }else if (context_tok.indexIn(line) != -1){
32 return CONTEXT_TOK;
33 }else if (added_tok.indexIn(line) != -1){
34 return ADDED_TOK;
35 }else if (deleted_tok.indexIn(line) != -1){
36 return DELETED_TOK;
39 return NONE_TOK;
42 /* CONCRETE TOKENS: */
43 TokensGit::TokensGit() : Tokens::Tokens("^diff --git a/([^ ]+) b/.*$",
44 "^@@ -([0-9]+),.* \\+([0-9]+),.*$",
45 "^ .*$",
46 "^\\+.*$",
47 "^-.*$"){}