⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parsing.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	    equalsSignFoundAlready = TRUE;	}	curIndx++;	pCurChar++;	ch=*pCurChar;    }        return curIndx;}///////////////////////////////////////////////////////////////////////////////Converts all lower-case alphabet chars in buf to uppercase:// Added code so text inside quotes won't go to uppercase,// e.g., [blah "blah"] will be converted to [BLAH "blah"]:void convertToUpperCase(_CHAR* pBuf, ULONG32 bufLen){    if(!pBuf  ||  !bufLen)    {	return;    }    _CHAR* pCur;    _CHAR ch;    ULONG32 indx=0;    BOOL bIsInsideQuotes = FALSE;    pCur = pBuf;    ch = *pCur;    while(ch!='\0'  &&  indx<bufLen)    {/*XXXEH- we're always inside a markup tag when this function,  convertToUpperCase(), gets called so pBuf should never be  DBCS.  However, if we're inside quotes, we might allow DBCS  chars...not sure how to handle this in both DBCS/SBCS worlds;  disallow DBCS inside quotes for now:	//Added the following code to handle DBCS chars:	if(bIsInsideQuotes  &&  (UCHAR)ch >= DBCS_MIN_LEAD_BYTE_VAL)	{	    indx+=2;	 //skip the trail byte.	    if(indx >= bufLen)	    {		return; //we've gone past the end of the buffer.	    }	    pCur+=2;	    ch = *pCur;	    continue;	}*/	//added the following code to make sure	// text inside quotes is NOT converted to upper case:	if('\"' == ch)	{	    bIsInsideQuotes = !bIsInsideQuotes;	}	if(bIsInsideQuotes)	{	    indx++;	    pCur++;	    ch = *pCur;	    continue;	}	if(ch >= 'a'  &&  ch <= 'z')	{	    *pCur += ('A' - 'a');	}	indx++;	pCur++;	ch = *pCur;    }}/////////////////////////////////////////////////////////////////////////////// Finds the next instance of the specified character in pBuf starting its// search at ulStartIndex and returning the index of the next occurance of// charToFind (or ulBufLen if charToFind was not found):// Note that ulCurCharset is needed because we may want to skip trail// byte if a lead DBCS byte is found, but only if the charset is a DBCS one.//ULONG32 findNextChar(_CHAR charToFind, _CHAR* pBuf, ULONG32 ulBufLen,	ULONG32 ulStartIndex, ULONG32 ulCurCharset){    ULONG32 index;        if(!pBuf  ||  ulStartIndex > ulBufLen)    {	return ulBufLen;    }    _CHAR* pBufSearch = &pBuf[ulStartIndex];    for(index = ulStartIndex; index<ulBufLen; index++, pBufSearch++)    {	//Added the following code to handle DBCS chars;	// assumes charToFind is a SINGLE BYTE CHAR!:	if((ulCurCharset & HX_DBCS_CHARSET)  &&		(UCHAR)(*pBufSearch) >= DBCS_MIN_LEAD_BYTE_VAL)	{	    index++; //increment one extra to skip the trail byte.	    pBufSearch++;	}	if(charToFind == *pBufSearch)	{	   break;	}    }    return index;}/////////////////////////////////////////////////////////////////////////////// Finds the start and end indices of both elements of the next //  "lvalue=rvalue" token in pBuf.////  Example 2: if pBuf is the contents inside the following []'s: //	[ COLOR= red]//  then this function will set ulLvalueStartIndex to 1, //  ulLvalueEndIndex to 6, ulRvalueStartIndex to 8, and //  ulRvalueEndIndex to 11; "COLOR" and "red" are the values found.////  Example 2: if pBuf is the contents inside the following []'s: //	[COLOR  ="light blue" blah blah]//  then this function will set ulLvalueStartIndex to 0, //  ulLvalueEndIndex to 5, ulRvalueStartIndex to 10, and //  ulRvalueEndIndex to 20; "COLOR" and "light blue" are the values found.//BOOL GetNextTokenLvalueRvaluePair(_CHAR* pBuf, ULONG32 ulBufLen,	ULONG32& ulLvalueStartIndex, ULONG32& ulLvalueEndIndex,	ULONG32& ulRvalueStartIndex, ULONG32& ulRvalueEndIndex){    ulLvalueStartIndex = ulLvalueEndIndex = 	    ulRvalueStartIndex = ulRvalueEndIndex = 0L;        if(!pBuf  ||  ulBufLen<1)    {	return FALSE;    }    ULONG32 ulIndexOfEqualsSign;    //First, find the first non-space/tab/newline char; it's the start of the    // lvalue string (or is the end of the buffer):    ulLvalueStartIndex = skipSpacesTabsAndNewlineChars(pBuf, ulBufLen, 0L);    if(ulLvalueStartIndex >= ulBufLen)    {	return FALSE; //no non-space/tab/newline chars were found.    }    if('=' == pBuf[ulLvalueStartIndex])    {	return FALSE;//nothing but spaces/tabs/newlines were found before '='    }    ULONG32 ulTempEnd = findNextSpaceTabOrNewLineChar(pBuf, ulBufLen,	    ulLvalueStartIndex, ulIndexOfEqualsSign,	    CHARSET__us_ascii); //<- in-tag text is always us-ascii.        ulLvalueEndIndex = ulTempEnd;        if(ulIndexOfEqualsSign >= ulBufLen)    {	//no '=' sign was found	if(ulTempEnd >= ulBufLen)	{	    return FALSE; //no equals sign exists.	}		//Now, find the first non-space/tab/newline char; it's supposed to	// be the '=' (if not, return FALSE):	ulIndexOfEqualsSign =		skipSpacesTabsAndNewlineChars(pBuf, ulBufLen, ulTempEnd);	if(ulIndexOfEqualsSign >= ulBufLen)	{	    return FALSE; //no equals sign exists.	}	if('=' != pBuf[ulIndexOfEqualsSign])	{	    return FALSE; //equals sign not found next as expected.	}	//We found the equals sign, so go find the Rvalue part...    }    else    {	//'=' immediately follows lvalue part so end is at '='s index:	ulLvalueEndIndex = ulIndexOfEqualsSign;    }    //'=' was found; now find "value" part:    //First, find the first non-space/tab/newline char; it's the start    // of the rvalue string (or is the end of the buffer):    ulRvalueStartIndex =	    skipSpacesTabsAndNewlineChars(pBuf, ulBufLen, 	    ulIndexOfEqualsSign+1);    if(ulRvalueStartIndex >= ulBufLen)    {	return FALSE; //nothing but spaces/tabs/newlines found after the '='.    }    if('\"' != pBuf[ulRvalueStartIndex])    {	//now, find the end of the rvalue part, i.e., find the next	// space/tab/newline or end-of-pBuf:	ULONG32 ulDummy;	ulRvalueEndIndex = findNextSpaceTabOrNewLineChar(pBuf, ulBufLen,		ulRvalueStartIndex, ulDummy,		CHARSET__us_ascii);//<- in-tag text is always us-ascii.    }    else //ulRvalueEndIndex is where the next '\"' char is (or end-of-buf):    {	ulRvalueStartIndex++; //We want to return the foo part of "foo".	ulRvalueEndIndex = 		findNextChar('\"', pBuf, ulBufLen, ulRvalueStartIndex,		CHARSET__us_ascii);//<- in-tag text is always us-ascii.    }	     return TRUE;}//end of GetNextTokenLvalueRvaluePair().///////////////////////////////////////////////////////////////////////////////Returns TRUE if either a start or end quote was found.  Note: this// function does NOT mess with the pBuf in any way, so it is the// responsibility of the caller to do a pBuf++ if start quote is to// be removed and to put a '\0' in place of the end quote if it is// to be removed.  If the string is only one character long and that// char is a quote, then bStartQuoteWasFound is set to TRUE and// bEndQuoteWasFound is set to FALSE.BOOL lookForStartAndEndQuotesOfString(_CHAR* pBuf, ULONG32 ulBufLen,	BOOL& bStartQuoteWasFound, BOOL& bEndQuoteWasFound){    if(!pBuf  ||  !ulBufLen)    {	return FALSE;    }    bStartQuoteWasFound = bEndQuoteWasFound = FALSE;    if(pBuf[0]=='\"')    {	bStartQuoteWasFound = TRUE;	if(ulBufLen==1L)	{	    return TRUE;	}    }    if(pBuf[ulBufLen-1]=='\"')    {	bEndQuoteWasFound = TRUE;    }        return(bStartQuoteWasFound ||  bEndQuoteWasFound);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -