本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}