summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 781f943)
raw | patch | inline | side by side (parent: 781f943)
author | ishmal <ishmal@users.sourceforge.net> | |
Sat, 3 Mar 2007 22:59:22 +0000 (22:59 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Sat, 3 Mar 2007 22:59:22 +0000 (22:59 +0000) |
src/dom/minidom.cpp | patch | blob | history | |
src/dom/minidom.h | patch | blob | history |
diff --git a/src/dom/minidom.cpp b/src/dom/minidom.cpp
index 5afcfe5ee048596237f2068f96de5de3f62e2770..86ab36ce3ad0c6a5aeb5f4babc9486da68e20a2b 100644 (file)
--- a/src/dom/minidom.cpp
+++ b/src/dom/minidom.cpp
-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<pos ; i++)
+ int count = 0;
+ for (int i=begin ; i<end ; i++)
+ {
+ XMLCh ch = parsebuf[i];
+ if (ch == '\n' || ch == '\r')
+ count++;
+ }
+ return count;
+}
+
+
+void Parser::getLineAndColumn(int pos, int *lineNr, int *colNr)
+{
+ int line = 1;
+ int col = 1;
+ for (int i=0 ; i<pos ; i++)
{
XMLCh ch = parsebuf[i];
if (ch == '\n' || ch == '\r')
void Parser::error(char *fmt, ...)
{
- long lineNr;
- long colNr;
+ int lineNr;
+ int colNr;
getLineAndColumn(currentPosition, &lineNr, &colNr);
va_list args;
fprintf(stderr, "xml error at line %ld, column %ld:", lineNr, colNr);
-int Parser::peek(long pos)
+int Parser::peek(int pos)
{
if (pos >= parselen)
return -1;
-int Parser::match(long p0, const char *text)
+int Parser::match(int p0, const char *text)
{
int p = p0;
while (*text)
-int Parser::skipwhite(long p)
+int Parser::skipwhite(int p)
{
while (p<parselen)
return p;
}
-int Parser::parseElement(int p0, Element *par,int depth)
+int Parser::parseElement(int p0, Element *par,int lineNr)
{
int p = p0;
//Add element to tree
Element *n = new Element(openTagName);
n->parent = par;
+ n->line = lineNr + countLines(p0, p);
par->addChild(n);
// Get attributes
//# CHILD ELEMENT
if (ch == '<')
{
- p2 = parseElement(p, n, depth+1);
+ p2 = parseElement(p, n, lineNr + countLines(p0, p));
if (p2 == p)
{
/*
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 30b53dd181893807f14f8f4542b212213d653a11..b1ad82f0759fd420c2560e5455171910691a7404 100644 (file)
--- a/src/dom/minidom.h
+++ b/src/dom/minidom.h
friend class Parser;
public:
+
Element()
{
parent = NULL;
std::vector<Element *> getChildren()
{ return children; }
+
+ int getLine()
+ { return line; }
std::vector<Element *> findElements(const DOMString &name);
DOMString name;
DOMString value;
+
+ int line;
};
class Parser
{
public:
+
Parser()
{ init(); }
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);
bool keepGoing;
Element *currentNode;
- long parselen;
+ int parselen;
XMLCh *parsebuf;
DOMString cdatabuf;
- long currentPosition;
+ int currentPosition;
int colNr;