Wednesday, 15 January 2014

c++ - I'm making a syntax highlighter and am having trouble coloring text between quotes -



c++ - I'm making a syntax highlighter and am having trouble coloring text between quotes -

i have programme iterate through line find ". if does, start loop goes end of string in find ". when does, check if @ same location first iterator. if is, insert "end-text-coloration" line, if not, insert "begin-text-coloration" line. not sure if problem lies within logic or code :/

#include <iostream> #include <fstream> #include <string> using namespace std; int getlength(string a) { homecoming a.length(); } int main () { string formstart = "\033[1;32m"; string formend = "\033[0m"; string line; size_t pos; ifstream myfile ("opentest.cpp"); if (myfile.is_open()) { while(getline(myfile,line)) { len = getlength(line); (int = 0; < len; i++) { if (line[i] == '"') len = getlength(line); (int n = len; n >= i; n--) { if (line[n] == '"' && n == i) { cout << "hit end" << endl; line.insert(i, formend); } else { cout << "hit start" << endl; line.insert(i, formstart); } } } } cout << line << endl; myfile.close(); } else { cout << "error" << endl; } homecoming 0; }

based on description, if should this:

if (line[n] == '"') { if (n == i) { cout << "hit end" << endl; line.insert(i, formend); } else { cout << "hit start" << endl; line.insert(i, formstart); } }

c++

No comments:

Post a Comment