46 lines
1002 B
C++
46 lines
1002 B
C++
|
#include "Highlight.h"
|
||
|
|
||
|
const char *const test_string = "this (test) is my test string which im with testing in this test";
|
||
|
|
||
|
int fits(const char* const pattern, const char* const to){
|
||
|
if(pattern == NULL){ return true; }
|
||
|
for(int i = 0;; i++){
|
||
|
if(pattern[i] == '\00'){ return i; }
|
||
|
if(to[i] == '\00' or pattern[i] != to[i]){ return false; }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void render_string(const char* const string, char* mode){
|
||
|
for(const char* s = string; *s != '\00';){
|
||
|
for(auto &i : token_table){
|
||
|
int f;
|
||
|
f = fits(i->syntax, s);
|
||
|
if(f){
|
||
|
int pos = i->hl->o.find(mode)->second.attrs;
|
||
|
attr_callbacks[pos]();
|
||
|
for(int h = 0; h < f; h++){
|
||
|
putchar(*(s+h));
|
||
|
}
|
||
|
attr_callbacks[pos+1]();
|
||
|
s += f;
|
||
|
}else{
|
||
|
putchar(*s);
|
||
|
++s;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
signed main(){
|
||
|
hl_group mygroup = (hl_group){
|
||
|
.name = "test",
|
||
|
.link = NULL
|
||
|
};
|
||
|
mygroup.o["cterm"] = (hl_t){
|
||
|
.attrs = BOLD
|
||
|
};
|
||
|
token* mytoken = newtoken("test", KEYWORD, &mygroup);
|
||
|
render_string(test_string, "cterm");
|
||
|
putchar('\n');
|
||
|
}
|