strutil.cpp

来自「基于WINDOWS mobile 的用于创建一个窗体和自定义试图的工程」· C++ 代码 · 共 116 行

CPP
116
字号


#include "stdafx.h"
#include "StrUtil.h"


WCHAR *StrCopyN(WCHAR *pDest, const WCHAR *pSrc, size_t n)
{
	for( ; *pSrc && n; --n, ++pDest, ++pSrc)
		*pDest = *pSrc;
	*pDest = 0;

	return pDest;
}


WCHAR *StrCopyNR(WCHAR *pDest, const WCHAR *pSrc, size_t& n)
{
	for( ; *pSrc && n; --n, ++pDest, ++pSrc)
		*pDest = *pSrc;
	*pDest = 0;

	return pDest;
}


const WCHAR *StrGetInt(const WCHAR *pSrc, int *pInt)
{
	ASSERT(pInt);

	*pInt = 0;

	//
	// Find the first numeric character
	//
	while(*pSrc && !IsNumeric(*pSrc))
		++pSrc;

	while(*pSrc && IsNumeric(*pSrc))
	{
		*pInt = *pInt * 10 + (*pSrc - '0');
		++pSrc;
	}
	return pSrc;
}


const WCHAR *StrGetHex(const WCHAR *pSrc, int *pInt)
{
	ASSERT(pInt);

	*pInt = 0;

	//
	// Find the first numeric character
	//
	while(*pSrc && !IsHex(*pSrc))
		++pSrc;

	while(*pSrc && IsHex(*pSrc))
	{
		*pInt = (*pInt << 4) + CharHexValue(*pSrc);
		++pSrc;
	}
	return pSrc;
}


const WCHAR *StrGetHex(const WCHAR *pSrc, DWORD *pDword)
{
	ASSERT(pDword);

	*pDword = 0;

	//
	// Find the first numeric character
	//
	while(*pSrc && !IsHex(*pSrc))
		++pSrc;

	while(*pSrc && IsHex(*pSrc))
	{
		*pDword = (*pDword << 4) + CharHexValue(*pSrc);
		++pSrc;
	}
	return pSrc;
}


const WCHAR *StrGetQuoted(const WCHAR *pSrc, WCHAR *pDest, size_t n)
{
	*pDest = 0;							// Terminate the string

	while(*pSrc && *pSrc != '\"')		// Advance up to the "
		++pSrc;

	if(*pSrc == '\"')					// Advance past the "
		++pSrc;

	while(*pSrc && *pSrc != '\"' && n)	// Find the closing quote
	{
		*pDest = *pSrc;
		++pDest;
		++pSrc;
		--n;
	}

	if(*pSrc == '\"' || !n)				// String is terminated
	{
		*pDest = 0;
		++pSrc;							// Advance past last quote
	}

	return pSrc;
}

⌨️ 快捷键说明

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