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

📄 rltxthdr.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    timeValInMillisec=0;    if(!pTimeBuffer  ||  timeBufLen<1)    {	return FALSE;    }    savedEndChar = pTimeBuffer[timeBufferLen-1];    //Get rid of start & terminating quotation mark, if they exist:    if('\"' == pTimeBuffer[0])    {	pTimeBuffer++;	timeBufferLen--;	//Added this check to kill bug if (pTimeBuffer==")	// and got shortened to an empty string:	if(!timeBufferLen)	{	    return FALSE;	}    }    if('\"' == pTimeBuffer[timeBufferLen-1])    {	pTimeBuffer[timeBufferLen-1] = '\0'; //get rid of end '\"'.	timeBufferLen--;	endCharWasChanged = TRUE;    }        //Work from right to left, searching first for milliseconds and then for    //	seconds (or seconds only if no '.' found):    BOOL bColonWasFound = FALSE;    for(bufIndx=timeBufferLen-1; 0L<=bufIndx; bufIndx--)    {	_CHAR ch = toupper(pTimeBuffer[bufIndx]);	if('0' > ch  ||  '9' < ch)	{	    if(' '==ch  ||  '\t'==ch  ||  '\n'==ch  ||  '\r'==ch)	    {		//Added everything up to "break;" to		// handle (valid) strings with leading space(s) like " 39":		//previous found was seconds_, so translate into ULONG:		seconds_ = atol(&pTimeBuffer[bufIndx+1L]);		timeValInMillisec += seconds_*1000; //converts seconds to ms.		break; //we're done; we found seconds only.	    }	    else if('.' == ch)	    {		if(bDotEncounteredAlready)		{		    //Make sure pColorNm is in original state:		    if(endCharWasChanged)		    {			pTimeBuffer[timeBufferLen-1] = savedEndChar;		    }		    if(indexOfDot >= 0)		    {			pTimeBuffer[indexOfDot] = '.';		    }		    //this second '.' is unexpected, so return with		    //  timeValInMillisec set to whatever was read so far:		    return FALSE;		}		bDotEncounteredAlready = TRUE;		indexOfDot = bufIndx;		pTimeBuffer[bufIndx] = '\0'; //end the buffr at the '.' .		//previously-read #'s are milliseconds, so count them:		//added "-1" to fix bug if buf ends with ".":		if(1L > timeBufferLen-bufIndx)		{		    milliseconds_ = 0L;		}		else		{		    //Now, make sure that more than three digits (base 10)		    //	are not present, e.g., reduce "46371" to "463" since		    //	we only allow millisecond precision (3 digits past		    //	the decimal point:		    _CHAR chTmp = '\0';		    ULONG32 ulNumDecimalDigitsFound = timeBufferLen-1 - bufIndx;#if !defined(NUM_DECIMAL_DIGITS_OF_SECONDS)# define NUM_DECIMAL_DIGITS_OF_SECONDS 3L#endif		    if(NUM_DECIMAL_DIGITS_OF_SECONDS <			    ulNumDecimalDigitsFound)		    {			chTmp = pTimeBuffer[bufIndx+1L];			pTimeBuffer[bufIndx+NUM_DECIMAL_DIGITS_OF_SECONDS+1]=				'\0';		    }		    milliseconds_ = atol(&pTimeBuffer[bufIndx+1L]);		    //Added this to fix "y.x" being converted		    // to y00x instead of yx00 milliseconds:		    if(ulNumDecimalDigitsFound < NUM_DECIMAL_DIGITS_OF_SECONDS)		    {			for(ULONG32 ulDiff=NUM_DECIMAL_DIGITS_OF_SECONDS				-ulNumDecimalDigitsFound; ulDiff>0; ulDiff--)			{			    milliseconds_ *= 10;			}		    }		    if(NUM_DECIMAL_DIGITS_OF_SECONDS <			    ulNumDecimalDigitsFound)		    {			//restore the changed char in the pTimeBuffer:			pTimeBuffer[				bufIndx+NUM_DECIMAL_DIGITS_OF_SECONDS+1]=				chTmp;		    }		}				timeValInMillisec = milliseconds_;	    } //end "else if('.' == ch)".	    else if(':' == ch)	    {		bColonWasFound = TRUE;		//previous found was seconds_, so translate into ULONG:		seconds_ = atol(&pTimeBuffer[bufIndx+1L]);		timeValInMillisec += seconds_*1000; //converts seconds to ms.		break; //done with "seconds_[.milliseconds_]" part.	    }	    else	    {		//Make sure pColorNm is in original state:		if(endCharWasChanged)		{		    pTimeBuffer[timeBufferLen-1] = savedEndChar;		}		if(indexOfDot >= 0)		{		    pTimeBuffer[indexOfDot] = '.';		}		//this char is unexpected, so return FALSE with		//  timeValInMillisec set to whatever was read so far:		return FALSE;	    }	} //end of "ch is a non-number" condition.	else if(0L == bufIndx) //we're done with the buffer:	{	    //previous found was seconds_, so translate into ULONG:	    seconds_ = atol(pTimeBuffer);	    timeValInMillisec += seconds_*1000; //converts seconds to ms.	    break; //done with "seconds_[.milliseconds_]" part.	}    } //end "for(bufIndx=timeBufferLen-1; ...".    if(bColonWasFound) //then get the "minutes" part:    {	bColonWasFound = FALSE;	//We've got the ":seconds.msecs" part, so lets get the hours part:	for(bufIndx--; 0L<=bufIndx; bufIndx--)	{	    _CHAR ch = toupper(pTimeBuffer[bufIndx]);	    if('0' > ch  ||  '9' < ch)	    {		if(' ' == ch  ||  '.' == ch)		{		    break;		}		else if(':' == ch)		{		    bColonWasFound = TRUE;		    //previous found was seconds_, so translate into ULONG:		    // (Note: this will do atol("min:sec") which ignores		    // everything at & beyond the first non-num (":") char):		    minutes_ = atol(&pTimeBuffer[bufIndx+1L]);		    timeValInMillisec += minutes_*60000; //minutes to msec		    break; //done w/ "minutes_:seconds_[milliseconds_]" part.		}		else  //unexpected char found, so quit parsing:		{		    //Make sure pTimeBuffer is in original state:		    if(endCharWasChanged)		    {			pTimeBuffer[timeBufferLen-1] = savedEndChar;		    }		    if(indexOfDot >= 0)		    {			pTimeBuffer[indexOfDot] = '.';		    }		    //this char is unexpected, so return FALSE with		    //  timeValInMillisec set to whatever was read so far:		    return FALSE;		}	    } //end of "ch is a non-number" condition.	    else if(0L == bufIndx) //we're done with the buffer:	    {		//previous found was seconds_, so translate into ULONG:		minutes_ = atol(pTimeBuffer);		timeValInMillisec += minutes_*60000; //minutes to msec		break; //done w/ "minutes_:seconds_[milliseconds_]" part.	    }	} //end "for(; ...".    } //end "if(bColonWasFound) //then get the "minutes" part:".    if(bColonWasFound) //then get the "hours" part:    {	bColonWasFound = FALSE;	//We've got the ":minutes.seconds.msec" part, so lets get the hours:	for(bufIndx--; 0L<=bufIndx; bufIndx--)	{	    _CHAR ch = toupper(pTimeBuffer[bufIndx]);	    if('0' > ch  ||  '9' < ch)	    {		if(' ' == ch  ||  '.' == ch)		{		    break;		}		else if(':' == ch)		{		    bColonWasFound = TRUE;		    //previous found was minutes_, so translate into ULONG:		    // (Note: this will do atol("hrs:min:sec") which ignores		    // everything at & beyond the first non-num (":") char):		    hours_ = atol(&pTimeBuffer[bufIndx+1L]);		    timeValInMillisec += hours_*3600000; //hours to msec		    break;//done w/ "hours_:minutes_:seconds_[milliseconds_]"		}		else  //unexpected char found, so quit parsing:		{		    //Make sure pTimeBuffer is in original state:		    if(endCharWasChanged)		    {			pTimeBuffer[timeBufferLen-1] = savedEndChar;		    }		    if(indexOfDot >= 0)		    {			pTimeBuffer[indexOfDot] = '.';		    }		    //this char is unexpected, so return FALSE with		    //  timeValInMillisec set to whatever was read so far:		    return FALSE;		}	    } //end of "ch is a non-number" condition.	    else if(0L == bufIndx) //we're done with the buffer:	    {		//previous found was seconds_, so translate into ULONG:		hours_ = atol(pTimeBuffer);		timeValInMillisec += hours_*3600000; //hours to msec		break; //done w/ "hours_:minutes_:seconds_[milliseconds_]".	    }	} //end "for(; ...".    } //end "if(bColonWasFound) //then get the "hours" part:".    if(endCharWasChanged)    {	timeBufferLen++;	//Restore the orignial pColorNm, in case end quote char was removed:	pTimeBuffer[timeBufferLen-1] = savedEndChar;    }        if(indexOfDot >= 0)    {        pTimeBuffer[indexOfDot] = '.';    }    return TRUE;} //end convertTimeStringToULONG32() function body.*/

⌨️ 快捷键说明

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