[GB.XML]
* BUG: Comments are now correctly supported. * BUG: Fix a 32-bits compilation warning. git-svn-id: svn://localhost/gambas/trunk@4824 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
bafcbb069a
commit
5248d86f82
4 changed files with 19 additions and 15 deletions
|
@ -120,7 +120,7 @@ int Reader::ReadChar(char car)
|
|||
return READ_END_CUR_ELEMENT;
|
||||
}
|
||||
|
||||
if(car == CHAR_STARTTAG)//Début de tag
|
||||
if(car == CHAR_STARTTAG && !inComment)//Début de tag
|
||||
{
|
||||
inNewTag = true;
|
||||
inTagName = true;
|
||||
|
@ -138,7 +138,7 @@ int Reader::ReadChar(char car)
|
|||
return NODE_TEXT;
|
||||
}
|
||||
}
|
||||
else if(car == CHAR_ENDTAG && inTag && !inEndTag)//Fin de tag (de nouvel élément)
|
||||
else if(car == CHAR_ENDTAG && inTag && !inEndTag && !inComment)//Fin de tag (de nouvel élément)
|
||||
{
|
||||
//DEBUG "Nouvel élément : " << (*(curNode->toElement()->tagName)) << endl;
|
||||
//UNREF(foundNode);
|
||||
|
@ -166,11 +166,11 @@ int Reader::ReadChar(char car)
|
|||
}
|
||||
return NODE_ELEMENT;
|
||||
}
|
||||
else if(isWhiteSpace(car) && inTag && inTagName)// Fin de tagName
|
||||
else if(isWhiteSpace(car) && inTag && inTagName && !inComment)// Fin de tagName
|
||||
{
|
||||
inTagName = false;
|
||||
}
|
||||
else if(isNameStartChar(car) && inTag && !inTagName && !inEndTag && !inAttrVal && !inAttrName)//Début de nom d'attribut
|
||||
else if(isNameStartChar(car) && inTag && !inTagName && !inEndTag && !inAttrVal && !inAttrName && !inComment)//Début de nom d'attribut
|
||||
{
|
||||
if(attrName && attrVal)
|
||||
{
|
||||
|
@ -190,16 +190,16 @@ int Reader::ReadChar(char car)
|
|||
*attrName = car;
|
||||
lenAttrName = 1;
|
||||
}
|
||||
else if(car == CHAR_EQUAL && inAttrName)//Fin du nom d'attribut
|
||||
else if(car == CHAR_EQUAL && inAttrName && !inComment)//Fin du nom d'attribut
|
||||
{
|
||||
inAttrName = false;
|
||||
}
|
||||
else if((car == CHAR_SINGLEQUOTE || car == CHAR_DOUBLEQUOTE) && inAttr && !inAttrVal)//Début de valeur d'attribut
|
||||
else if((car == CHAR_SINGLEQUOTE || car == CHAR_DOUBLEQUOTE) && inAttr && !inAttrVal && !inComment)//Début de valeur d'attribut
|
||||
{
|
||||
inAttrVal = true;
|
||||
attrVal = 0;
|
||||
}
|
||||
else if((car == CHAR_SINGLEQUOTE || car == CHAR_DOUBLEQUOTE) && inAttr && inAttrVal)//Fin de valeur d'attribut
|
||||
else if((car == CHAR_SINGLEQUOTE || car == CHAR_DOUBLEQUOTE) && inAttr && inAttrVal && !inComment)//Fin de valeur d'attribut
|
||||
{
|
||||
curNode->toElement()->addAttribute(attrName, lenAttrName,
|
||||
attrVal, lenAttrVal);
|
||||
|
@ -209,7 +209,7 @@ int Reader::ReadChar(char car)
|
|||
inAttrVal = false;
|
||||
return READ_ATTRIBUTE;
|
||||
}
|
||||
else if(car == CHAR_SLASH && inTag && !inAttrVal)//Self-closed element
|
||||
else if(car == CHAR_SLASH && inTag && !inAttrVal && !inComment)//Self-closed element
|
||||
{
|
||||
inTag = false;
|
||||
inTagName = false;
|
||||
|
@ -222,14 +222,14 @@ int Reader::ReadChar(char car)
|
|||
foundNode = curNode;
|
||||
return NODE_ELEMENT;
|
||||
}
|
||||
else if(car == CHAR_SLASH && inNewTag)//C'est un tag de fin
|
||||
else if(car == CHAR_SLASH && inNewTag && !inComment)//C'est un tag de fin
|
||||
{
|
||||
//DEBUG "Tag de fermeture" << endl;
|
||||
inEndTag = true;
|
||||
inNewTag = false;
|
||||
inTag = true;
|
||||
}
|
||||
else if(car == CHAR_ENDTAG && inEndTag)//La fin d'un tag de fin
|
||||
else if(car == CHAR_ENDTAG && inEndTag && !inComment)//La fin d'un tag de fin
|
||||
{
|
||||
inTag = false;
|
||||
inEndTag = false;
|
||||
|
@ -268,12 +268,13 @@ int Reader::ReadChar(char car)
|
|||
inTag = false;
|
||||
}
|
||||
//Caractère "-" de début de commentaire
|
||||
else if(inCommentTag && car == CHAR_DASH && specialTagLevel >= COMMENT_TAG_STARTCHAR_1 && specialTagLevel < COMMENT_TAG_STARTCHAR_3)
|
||||
else if(inCommentTag && car == CHAR_DASH && specialTagLevel >= COMMENT_TAG_STARTCHAR_1 && specialTagLevel < COMMENT_TAG_STARTCHAR_3 && !inComment)
|
||||
{
|
||||
specialTagLevel++;
|
||||
if (specialTagLevel == COMMENT_TAG_STARTCHAR_3)//Le tag <!-- est complet, on crée un nouveau node
|
||||
{
|
||||
inCommentTag = false;
|
||||
inComment = true;
|
||||
//UNREF(curNode);
|
||||
curNode = new CommentNode;
|
||||
//GB.Ref(curNode);
|
||||
|
@ -300,6 +301,7 @@ int Reader::ReadChar(char car)
|
|||
inTag = false;
|
||||
//UNREF(foundNode);
|
||||
foundNode = curNode;
|
||||
inComment = false;
|
||||
if(keepMemory)
|
||||
{
|
||||
APPEND(foundNode);
|
||||
|
@ -308,17 +310,17 @@ int Reader::ReadChar(char car)
|
|||
return NODE_COMMENT;
|
||||
}
|
||||
//Début de prologue XML
|
||||
else if(car == CHAR_PI && inNewTag)
|
||||
else if(car == CHAR_PI && inNewTag && !inComment)
|
||||
{
|
||||
inXMLProlog = true;
|
||||
inNewTag = false;
|
||||
inTag = false;
|
||||
}
|
||||
else if(car == CHAR_PI && inXMLProlog)
|
||||
else if(car == CHAR_PI && inXMLProlog && !inComment)
|
||||
{
|
||||
specialTagLevel = PROLOG_TAG_ENDCHAR;
|
||||
}
|
||||
else if(car == CHAR_ENDTAG && inXMLProlog && specialTagLevel == PROLOG_TAG_ENDCHAR)
|
||||
else if(car == CHAR_ENDTAG && inXMLProlog && specialTagLevel == PROLOG_TAG_ENDCHAR && !inComment)
|
||||
{
|
||||
specialTagLevel = 0;
|
||||
inXMLProlog = 0;
|
||||
|
|
|
@ -74,6 +74,7 @@ public :
|
|||
bool inCommentTag;//Si on est dans un tag commentaire
|
||||
bool inXMLProlog;//Si on est dans un prologue xml
|
||||
unsigned char specialTagLevel;//Niveau de lecture d'un tag spécial
|
||||
bool inComment;//Si on est dans un commentaire
|
||||
int depth;//Profondeur du nœud courant
|
||||
char *attrName;//Nom de l'attribut en cours de lecture
|
||||
size_t lenAttrName;
|
||||
|
|
|
@ -58,6 +58,7 @@ void TextNode::addStringLen(size_t *len, int indent)
|
|||
if(indent) *len += indent + 1;
|
||||
}
|
||||
|
||||
#undef ADD
|
||||
#define ADD(_car) **data = _car; ++(*data);
|
||||
|
||||
void TextNode::addString(char **data, int indent)
|
||||
|
|
|
@ -175,7 +175,7 @@ XMLParseException::XMLParseException(const char *nerror, const char *data, const
|
|||
//Parse error : (errorText) !\n Line 123456789 , Column 123456789 : \n (near)
|
||||
errorWhat = (char*)malloc(61 + lenError + lenNear);
|
||||
memset(errorWhat, 0, 61 + lenError + lenNear);
|
||||
sprintf(errorWhat, "Parse error : %s !\n Line %lu , Column %lu : \n %s", error, line, column, near);
|
||||
sprintf(errorWhat, "Parse error : %s !\n Line %zu , Column %zu : \n %s", error, line, column, near);
|
||||
errorWhat[60 + lenError + lenNear] = 0;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue