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

📄 getnumberparameter.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
字号:
/*----------------------------------------------------------------------
Copyright (c) 1998 Gipsysoft. All Rights Reserved.
Please see the file "licence.txt" for licencing details.

File:	GetNumberParameter.cpp
Owner:	russf@gipsysoft.com
Purpose:	Get a parameter as a number, can be positive to reflect pixels
					or negative to represent a percentage.
----------------------------------------------------------------------*/
#include "stdafx.h"
#include <stdlib.h>
#include "StaticString.h"


int GetNumberParameterPercent( const CStaticString &strParam, int nDefault )
{
  int nTotal = 0;
	if( strParam.GetLength() )
	{
		LPCTSTR p = strParam.GetData();
		LPCTSTR pEnd = strParam.GetEndPointer();
		while( p < pEnd && isspace( *p ))
		{
			p++;
		}
  
		while( p < pEnd && isdigit( *p) )
		{
			nTotal = 10 * nTotal + (*p - _T('0') );     /* accumulate digit */
			p++;
		}

		if( p < pEnd && *p == _T('%') )
			nTotal = -nTotal;
	}
	else
	{
		nTotal = nDefault;
	}
	
	return nTotal;
}


int GetNumberParameter( const CStaticString &strParam, int nDefault )
{
  int nTotal = 0;
	if( strParam.GetLength() )
	{
		LPCTSTR p = strParam.GetData();
		LPCTSTR pEnd = strParam.GetEndPointer();
		while( p < pEnd && isspace( *p ))
		{
			p++;
		}
  
		TCHAR cSign = *p;
		if( cSign == _T('-') || cSign == _T('+') )
			p++;

		while( p < pEnd && isdigit( *p) )
		{
			nTotal = 10 * nTotal + (*p - _T('0') );     /* accumulate digit */
			p++;
		}

		if( cSign == _T('-') )
			nTotal = -nTotal;
	}
	else
	{
		nTotal = nDefault;
	}
	
	return nTotal;
}

⌨️ 快捷键说明

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