Use switch insted of if with enums in ixml
Replace if statements with switch when using enums in ixml. Remove uneeded initialization in ixmlAttr_init, Parser_init and ixmlNode_init which was added by wrongly added in commit06660b6383
. (cherry picked from commitd48d73720b
)
This commit is contained in:
parent
f65b68a9bc
commit
a820f2ecce
@ -318,6 +318,15 @@ Version 1.8.0
|
||||
Version 1.6.16
|
||||
*******************************************************************************
|
||||
|
||||
2012-03-14 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
|
||||
|
||||
Use switch insted of if with enums in ixml
|
||||
|
||||
Replace if statements with switch when using enums in ixml.
|
||||
Remove uneeded initialization in ixmlAttr_init, Parser_init and
|
||||
ixmlNode_init which was added by wrongly added in commit
|
||||
06660b6383c438e4e2c9ca9854077cecc4da9e5d.
|
||||
|
||||
2012-03-14 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
|
||||
|
||||
Use switch insted of if with enums in threadutil
|
||||
|
@ -41,7 +41,6 @@ void ixmlAttr_init(IN IXML_Attr *attr)
|
||||
{
|
||||
if (attr != NULL) {
|
||||
memset(attr, 0, sizeof (IXML_Attr));
|
||||
attr->ownerElement = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1846,11 +1846,12 @@ static int Parser_getNextNode(
|
||||
goto ExitFunction;
|
||||
}
|
||||
|
||||
if (xmlParser->state == (PARSER_STATE)eCONTENT) {
|
||||
switch (xmlParser->state) {
|
||||
case eCONTENT:
|
||||
line = __LINE__;
|
||||
ret = Parser_processContent(xmlParser, node);
|
||||
goto ExitFunction;
|
||||
} else {
|
||||
default:
|
||||
Parser_skipWhiteSpaces(xmlParser);
|
||||
tokenLen = Parser_getNextToken(xmlParser);
|
||||
if (tokenLen == 0 &&
|
||||
@ -2209,9 +2210,15 @@ static int Parser_processElementName(
|
||||
/* the node may have default namespace definition */
|
||||
if (Parser_hasDefaultNamespace(xmlParser, newNode, &nsURI)) {
|
||||
Parser_setElementNamespace(newElement, nsURI);
|
||||
} else if (xmlParser->state == (PARSER_STATE)eATTRIBUTE) {
|
||||
/* the default namespace maybe defined later */
|
||||
xmlParser->pNeedPrefixNode = (IXML_Node *)newElement;
|
||||
} else {
|
||||
switch (xmlParser->state) {
|
||||
case eATTRIBUTE:
|
||||
/* the default namespace maybe defined later */
|
||||
xmlParser->pNeedPrefixNode = (IXML_Node *)newElement;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2292,13 +2299,17 @@ static int Parser_eTagVerification(
|
||||
assert( newNode->nodeName );
|
||||
assert( xmlParser->currentNodePtr );
|
||||
|
||||
if( newNode->nodeType == (IXML_NODE_TYPE)eELEMENT_NODE ) {
|
||||
switch( newNode->nodeType ) {
|
||||
case eELEMENT_NODE:
|
||||
if( Parser_isValidEndElement( xmlParser, newNode ) == TRUE ) {
|
||||
Parser_popElement( xmlParser );
|
||||
} else {
|
||||
/* syntax error */
|
||||
return IXML_SYNTAX_ERR;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if( strcmp( newNode->nodeName, xmlParser->currentNodePtr->nodeName ) ==
|
||||
@ -2496,12 +2507,6 @@ static Parser *Parser_init()
|
||||
}
|
||||
|
||||
memset(newParser, 0, sizeof (Parser));
|
||||
newParser->dataBuffer = NULL;
|
||||
newParser->curPtr = NULL;
|
||||
newParser->savePtr = NULL;
|
||||
newParser->pNeedPrefixNode = NULL;
|
||||
newParser->pCurElement = NULL;
|
||||
newParser->currentNodePtr = NULL;
|
||||
ixml_membuf_init(&(newParser->tokenBuf));
|
||||
ixml_membuf_init(&(newParser->lastElem));
|
||||
|
||||
|
@ -49,12 +49,6 @@ void ixmlNode_init(IXML_Node *nodeptr)
|
||||
assert(nodeptr != NULL);
|
||||
|
||||
memset(nodeptr, 0, sizeof (IXML_Node));
|
||||
nodeptr->parentNode = NULL;
|
||||
nodeptr->firstChild = NULL;
|
||||
nodeptr->prevSibling = NULL;
|
||||
nodeptr->nextSibling = NULL;
|
||||
nodeptr->firstAttr = NULL;
|
||||
nodeptr->ownerDocument = NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -97,9 +91,13 @@ static void ixmlNode_freeSingleNode(
|
||||
if (nodeptr->localName != NULL) {
|
||||
free(nodeptr->localName);
|
||||
}
|
||||
if (nodeptr->nodeType == (IXML_NODE_TYPE)eELEMENT_NODE) {
|
||||
switch (nodeptr->nodeType ) {
|
||||
case eELEMENT_NODE:
|
||||
element = (IXML_Element *)nodeptr;
|
||||
free(element->tagName);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
free(nodeptr);
|
||||
}
|
||||
@ -433,15 +431,21 @@ static BOOL ixmlNode_allowChildren(
|
||||
break;
|
||||
|
||||
case eELEMENT_NODE:
|
||||
if (newChild->nodeType == (IXML_NODE_TYPE)eATTRIBUTE_NODE ||
|
||||
newChild->nodeType == (IXML_NODE_TYPE)eDOCUMENT_NODE) {
|
||||
switch (newChild->nodeType) {
|
||||
case eATTRIBUTE_NODE:
|
||||
case eDOCUMENT_NODE:
|
||||
return FALSE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case eDOCUMENT_NODE:
|
||||
if (newChild->nodeType != (IXML_NODE_TYPE)eELEMENT_NODE) {
|
||||
switch (newChild->nodeType) {
|
||||
case eELEMENT_NODE:
|
||||
return FALSE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
@ -1128,7 +1132,8 @@ IXML_NamedNodeMap *ixmlNode_getAttributes(IXML_Node *nodeptr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(nodeptr->nodeType == (IXML_NODE_TYPE)eELEMENT_NODE) {
|
||||
switch(nodeptr->nodeType) {
|
||||
case eELEMENT_NODE:
|
||||
returnNamedNodeMap = (IXML_NamedNodeMap *)malloc(sizeof(IXML_NamedNodeMap));
|
||||
if(returnNamedNodeMap == NULL) {
|
||||
return NULL;
|
||||
@ -1146,7 +1151,7 @@ IXML_NamedNodeMap *ixmlNode_getAttributes(IXML_Node *nodeptr)
|
||||
tempNode = tempNode->nextSibling;
|
||||
}
|
||||
return returnNamedNodeMap;
|
||||
} else {
|
||||
default:
|
||||
/* if not an ELEMENT_NODE */
|
||||
return NULL;
|
||||
}
|
||||
@ -1166,9 +1171,13 @@ BOOL ixmlNode_hasChildNodes(IXML_Node *nodeptr)
|
||||
BOOL ixmlNode_hasAttributes(IXML_Node *nodeptr)
|
||||
{
|
||||
if (nodeptr != NULL) {
|
||||
if (nodeptr->nodeType == (IXML_NODE_TYPE)eELEMENT_NODE &&
|
||||
nodeptr->firstAttr != NULL) {
|
||||
return TRUE;
|
||||
switch (nodeptr->nodeType) {
|
||||
case eELEMENT_NODE:
|
||||
if (nodeptr->firstAttr != NULL)
|
||||
return TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user