From: ishmal Date: Sat, 3 Mar 2007 22:59:22 +0000 (+0000) Subject: add line number to Element X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c651df0b7842de486409c0a6de7c6c1e1a90cbda;p=inkscape.git add line number to Element --- diff --git a/src/dom/minidom.cpp b/src/dom/minidom.cpp index 5afcfe5ee..86ab36ce3 100644 --- a/src/dom/minidom.cpp +++ b/src/dom/minidom.cpp @@ -136,11 +136,24 @@ static EntityEntry entities[] = -void Parser::getLineAndColumn(long pos, long *lineNr, long *colNr) +int Parser::countLines(int begin, int end) { - long line = 1; - long col = 1; - for (long i=0 ; i= parselen) return -1; @@ -184,7 +197,7 @@ int Parser::peek(long pos) -int Parser::match(long p0, const char *text) +int Parser::match(int p0, const char *text) { int p = p0; while (*text) @@ -198,7 +211,7 @@ int Parser::match(long p0, const char *text) -int Parser::skipwhite(long p) +int Parser::skipwhite(int p) { while (pparent = par; + n->line = lineNr + countLines(p0, p); par->addChild(n); // Get attributes @@ -468,7 +482,7 @@ int Parser::parseElement(int p0, Element *par,int depth) //# CHILD ELEMENT if (ch == '<') { - p2 = parseElement(p, n, depth+1); + p2 = parseElement(p, n, lineNr + countLines(p0, p)); if (p2 == p) { /* @@ -560,7 +574,7 @@ Element *Parser::parse(XMLCh *buf,int pos,int len) Element *rootNode = new Element("root"); pos = parseVersion(pos); pos = parseDoctype(pos); - pos = parseElement(pos, rootNode, 0); + pos = parseElement(pos, rootNode, 1); return rootNode; } diff --git a/src/dom/minidom.h b/src/dom/minidom.h index 30b53dd18..b1ad82f07 100644 --- a/src/dom/minidom.h +++ b/src/dom/minidom.h @@ -82,6 +82,7 @@ class Element friend class Parser; public: + Element() { parent = NULL; @@ -127,6 +128,9 @@ public: std::vector getChildren() { return children; } + + int getLine() + { return line; } std::vector findElements(const DOMString &name); @@ -170,6 +174,8 @@ protected: DOMString name; DOMString value; + + int line; }; @@ -180,6 +186,7 @@ protected: class Parser { public: + Parser() { init(); } @@ -226,15 +233,17 @@ private: currentPosition = 0; } - void getLineAndColumn(long pos, long *lineNr, long *colNr); + int countLines(int begin, int end); + + void getLineAndColumn(int pos, int *lineNr, int *colNr); void error(char *fmt, ...); - int peek(long pos); + int peek(int pos); - int match(long pos, const char *text); + int match(int pos, const char *text); - int skipwhite(long p); + int skipwhite(int p); int getWord(int p0, DOMString &buf); @@ -250,10 +259,10 @@ private: bool keepGoing; Element *currentNode; - long parselen; + int parselen; XMLCh *parsebuf; DOMString cdatabuf; - long currentPosition; + int currentPosition; int colNr;