当前位置: 首页>>代码示例>>C++>>正文


C++ HeapString::AllocBuffer方法代码示例

本文整理汇总了C++中HeapString::AllocBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ HeapString::AllocBuffer方法的具体用法?C++ HeapString::AllocBuffer怎么用?C++ HeapString::AllocBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HeapString的用法示例。


在下文中一共展示了HeapString::AllocBuffer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FormatV

HeapString HeapString::FormatV(const char* format, va_list args)
{
	int len = 0;
	trio_vcprintf(CountAnsiHeapString, &len, format, args);

	HeapString dest;
	dest.AllocBuffer(len);
	trio_vsnprintf(dest.m_string, len + 1, format, args);
	return dest;
}
开发者ID:Abyss116,项目名称:luaplus51-all,代码行数:10,代码来源:HeapString.cpp

示例2: TrimLeft

HeapString HeapString::TrimLeft(const char* trimChars) const
{
	HeapString dest;

	// Count trim characters.
	size_t trimCharsLen = 0;
	const char empty[] = { 0 };
	for (const char* ptr = trimChars ? trimChars : empty; *ptr; ++ptr, ++trimCharsLen) { }

	const char* str = m_string;
	if (trimCharsLen == 0)
	{
		while (isspace(*str))
			str++;
	}
	else
	{
		if (trimCharsLen == 1)
		{
			while (*str == *trimChars)
				str++;
		}
		else
		{
			const char* stringEnd = m_string + GetStringData()->stringLen;
			const char* lastStr = str;
			while (str != stringEnd)
			{
				for (const char* ptr = trimChars; *ptr; ++ptr)
				{
					if (*ptr == *str)
					{
						str++;
						break;
					}
				}
				if (lastStr == str)
					break;
				lastStr = str;
			}
		}
	}

	size_t count = GetStringData()->stringLen - (str - m_string);
	if (count > 0)
	{
		dest.AllocBuffer(count);
		memcpy(dest.m_string, str, count);
	}

	return dest;
}
开发者ID:Abyss116,项目名称:luaplus51-all,代码行数:52,代码来源:HeapString.cpp

示例3: Sub

HeapString HeapString::Sub(size_t startPos, size_t count) const
{
	size_t stringLen = GetStringData()->stringLen;
	if (startPos > stringLen  ||  count == 0)
		return HeapString();
	if (startPos + count > stringLen)
		count = stringLen - startPos;

	HeapString dest;
	dest.AllocBuffer(count);
	memcpy(dest.m_string, m_string + startPos, count * sizeof(char));
	return dest;
}
开发者ID:Abyss116,项目名称:luaplus51-all,代码行数:13,代码来源:HeapString.cpp

示例4: Format

HeapString HeapString::Format(const char* format, ...)
{
	va_list args;
	va_start(args, format);

	int len = 0;
	trio_vcprintf(CountAnsiHeapString, &len, format, args);

	HeapString dest;
	dest.AllocBuffer(len);
	trio_vsnprintf(dest.m_string, len + 1, format, args);

	va_end(args);
	return dest;
}
开发者ID:Abyss116,项目名称:luaplus51-all,代码行数:15,代码来源:HeapString.cpp

示例5: TrimRight

HeapString HeapString::TrimRight(const char* trimChars) const
{
	HeapString dest;

	// Count trim characters.
	size_t trimCharsLen = 0;
	const char empty[] = { 0 };
	for (const char* ptr = trimChars ? trimChars : empty; *ptr; ++ptr, ++trimCharsLen) { }

	size_t stringLen = GetStringData()->stringLen;
	char* str = (char*)m_string + stringLen - 1;
	if (trimCharsLen == 0)
	{
		while (str != m_string  &&  isspace(*str))
			str--;
	}
	else
	{
		if (trimCharsLen == 1)
		{
			while (str != m_string  &&  *str == *trimChars)
				str--;
		}
		else
		{
			const char* lastStr = str;
			while (str != m_string)
			{
				for (const char* ptr = trimChars; *ptr; ++ptr)
				{
					if (*ptr == *str)
					{
						str--;
						break;
					}
				}
				if (lastStr == str)
					break;
				lastStr = str;
			}
		}
	}

	size_t count = str - m_string + 1;
	dest.AllocBuffer(count);
	memcpy(dest.m_string, m_string, count);
	return dest;
}
开发者ID:Abyss116,项目名称:luaplus51-all,代码行数:48,代码来源:HeapString.cpp

示例6: Replace

HeapString HeapString::Replace(char oldCh, char newCh) const
{
	HeapString dest;
	dest.AllocBuffer(GetStringData()->stringLen);

	char* destPtr = dest.m_string;
	for (char* srcPtr = m_string; *srcPtr; ++srcPtr, ++destPtr)
	{
		char ch = *srcPtr;
		if (ch == oldCh)
			*destPtr = newCh;
		else
			*destPtr = ch;
	}

	return dest;
}
开发者ID:Abyss116,项目名称:luaplus51-all,代码行数:17,代码来源:HeapString.cpp


注:本文中的HeapString::AllocBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。