📄 parser.cpp.tmp
字号:
if (membuffer_append_str(&tokBuf,s)!=0) return -1; return 0;}int Parser::appendTokBuf(char c) { if (membuffer_append(&tokBuf,&c,1)!=0) return -1; return 0;}void Parser::IgnoreWhiteSpaces(){ while(char_match (*CurrPtr, WHITESPACE)) getNextToken();}//Rewinds Current Ptr by n bytesvoid Parser::rewindCurrentPtr(int n){ CurrPtr=CurrPtr - n;}//Finds the Next Match//Finds the next character in strSearch that contains strMatch.char * Parser::findNextMatch (char *strSearch, const char *strMatch){ char *strIndex; // Current character match position if ((strSearch == NULL) || (strMatch == NULL)) return NULL; strIndex = strSearch; while (!(char_match (*strIndex, strMatch)) && (*strIndex != '\0')) strIndex++; return strIndex;}int get_char(char *src, int*clen){ char *pnum; int count; int sum; char c; *clen=0; if (!src || !clen) return -1; if (*src!='&'){ if (*src>0 &&isxmlch(*src)){ *clen=1; return *src; } int i, len; i=toint(src,&len); if (!isxmlch(i)){ //modified by donghee printf("=================== is not xml char !!!!!!!! \n"); return -1; //end of modification } *clen=len; return i; } if (!strncasecmp(src,QUOT,strlen(QUOT))){ *clen=strlen(QUOT); return '"'; } if (!strncasecmp(src,LT,strlen(LT))){ *clen=strlen(LT); return '<'; } if (!strncasecmp(src,GT,strlen(GT))){ *clen=strlen(GT); return '>'; } if (!strncasecmp(src,APOS,strlen(APOS))){ *clen=strlen(APOS); return '\''; } if (!strncasecmp(src,AMP,strlen(AMP))){ *clen=strlen(AMP); return '&'; } // Read in escape characters of type &#xnn where nn is a hexadecimal value if (!strncasecmp(src,ESC_HEX,strlen(ESC_HEX))){ count=0; pnum=src+strlen(ESC_HEX); sum=0; while (char_match(pnum[count],HEX_NUMBERS)){ c=pnum[count]; if (c<='9') sum = sum * 16+(c-'0'); else if(c<='F') sum = sum*16+(c-'A'+10); else sum = sum*16+(c-'a'+10); count++; } if (count<=0||pnum[count]!=';'||!isxmlch(sum)) return -1; *clen=strlen(ESC_HEX)+count+1; return sum; } // Read in escape characters of type &#nn where nn is a decimal value if (!strncasecmp(src,ESC_DEC,strlen(ESC_DEC))){ count=0; pnum=src+strlen(ESC_DEC); sum=0; while (char_match(pnum[count],DEC_NUMBERS)) sum=sum*10+(pnum[count++]-'0'); if (count<=0||pnum[count]!=';'||!isxmlch(sum)) return -1; *clen=strlen(ESC_DEC)+count+1; return sum; } printf("=================== Do not thing return -1 !!!!!!!! \n"); return -1;}bool Parser::copy_token(char *src, int len){ int i,c, cl; char *psrc, *pend; utf8char uch; if (!src||len <= 0) return false; psrc=src; pend=src+len; while (psrc<pend){ if ((c=get_char(psrc, &cl))<=0) { //*dest=0; //clearTokBuf(); return false; } if (cl==1){ //*dest++=c; appendTokBuf(c); psrc++; } else { //i=toutf8(c, dest); i=toutf8(c, uch); //if (i<0) {*dest=0; return false;} if (i<0) { return false;} //dest+=i; appendTokBuf(uch); psrc+=cl; } } //*dest=0; if (psrc>pend) return false; return true; // success}// returns true on success; false on errorbool copy_token(char *dest, char *src, int len){ int i,c, cl; char *psrc, *pend; if (!dest||!src||len <= 0) return false; psrc=src; pend=src+len; while (psrc<pend){ if ((c=get_char(psrc, &cl))<=0) { *dest=0; return false;} if (cl==1){ *dest++=c; psrc++; } else { i=toutf8(c, dest); if (i<0) {*dest=0; return false;} dest+=i; psrc+=cl; } } *dest=0; if (psrc>pend) return false; return true; // success}//Skip String//Skips all characters in the fragment string that are contained within//strSkipChars until some other character is found. Useful for skipping//over whitespace.long Parser::skipString (char **pstrFragment, const char *strSkipChars){ if (!pstrFragment || !strSkipChars) return -1; while ((**pstrFragment != '\0') && (char_match (**pstrFragment, strSkipChars))) { (*pstrFragment)++; } return 0; //success}//Skip Until String//Skips all characters in the string until it finds the skip key.//Then it skips the skip key and returns.long Parser::skipUntilString (char **pstrSource, const char *strSkipKey){ if (!pstrSource || !strSkipKey) return -1; while (**pstrSource && strncmp (*pstrSource, strSkipKey, strlen(strSkipKey))) (*pstrSource)++; *pstrSource = *pstrSource + strlen (strSkipKey); return 0; //success}//This will return the string of the next token in the TokenBuffint Parser::getNextToken(){ int TokenLength=0; int temp, tlen; //############################################### //printf("%c", *CurrPtr); //############################################### clearTokBuf(); // Check for white space if(*CurrPtr=='\0') { //TokenBuff[0]='\0'; return 0; } // Attribute value logic must come first, since all text untokenized until end-quote if (inAttrib && (!char_match (*CurrPtr, QUOTE))) { char *strEndQuote = findNextMatch (CurrPtr, QUOTE); if (strEndQuote == NULL) { TokenLength = 1; //*TokenBuff = '\0'; // return a single space for whitespace //if (!copy_token (TokenBuff, CurrPtr, TokenLength)) //if (!copy_token (CurrPtr, TokenLength)) // return 1; if (!copy_token (CurrPtr, TokenLength)) { printf("=================== Check 999 - 1 \n"); return 1; } return 0; // serious problem - no matching end-quote found for attribute } TokenLength = strEndQuote - CurrPtr; // BUGBUG: conversion issue if using more than simple strings //if (!copy_token (TokenBuff, CurrPtr, TokenLength)) //if (!copy_token (CurrPtr, TokenLength)) // return 1; if (!copy_token (CurrPtr, TokenLength)) { printf("=================== Check 999 - 2 \n"); return 1; } CurrPtr = CurrPtr+TokenLength; return 0; // must return now, so it doesn't go into name processing } if (char_match (*CurrPtr, WHITESPACE)) { TokenLength = 1; //if (!copy_token (TokenBuff, " ", TokenLength)) // return a single space for whitespace //if (!copy_token (" ", TokenLength)) // return a single space for whitespace // return 1; if (!copy_token (" ", TokenLength)) // return a single space for whitespace { printf("=================== Check 999 - 3 \n"); return 1; } CurrPtr = CurrPtr+TokenLength; return 0; } // Skip <? .. ?> , <! .. >, <!-- .. --> while (!strncmp (CurrPtr, BEGIN_COMMENT, strlen(BEGIN_COMMENT)) // <!-- || !strncmp (CurrPtr, BEGIN_PROCESSING, strlen(BEGIN_PROCESSING)) // <? || !strncmp (CurrPtr, BEGIN_DOCTYPE, strlen(BEGIN_DOCTYPE))) // <! { if (!strncmp (CurrPtr, BEGIN_COMMENT, strlen(BEGIN_COMMENT))) skipUntilString (&CurrPtr, END_COMMENT); else if (!strncmp (CurrPtr, BEGIN_PROCESSING, strlen(BEGIN_PROCESSING))) skipUntilString (&CurrPtr, END_PROCESSING); else skipUntilString (&CurrPtr, GREATERTHAN); skipString (&CurrPtr, WHITESPACE); TagVal=false; } // Check for start tags if (char_match (*CurrPtr, LESSTHAN)) { temp = toint(CurrPtr+1, &tlen); if (temp == '/') TokenLength = 2; // token is '</' end tag else if(isnamech(temp,false)) TokenLength=1; // Begin tag found, so return '<' token else{ //strcpy(TokenBuff,"\0"); printf("=================== Check 999 - 4 \n"); return 1; //error } TagVal=false; } // Check for opening/closing attribute value quotation mark if (char_match (*CurrPtr, QUOTE) && !TagVal) { // Quote found, so return it as token TokenLength = strlen(QUOTE); } // Check for '=' token if (char_match (*CurrPtr, EQUALS) && !TagVal) { // Equals found, so return it as a token TokenLength = strlen(EQUALS); } // Check for '/>' token if (char_match (*CurrPtr, SLASH)) { if (char_match (*(CurrPtr + 1), GREATERTHAN)) { // token '/>' found TokenLength = 2; TagVal=true; } //Content may begin with a / else if (TagVal) { TagVal=false; CurrPtr=SavePtr+1;//SavePtr whould not have have already moved. char *pEndContent = CurrPtr; // Read content until a < is found that is not a comment <!--
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -