string

void CCOMString::TrimLeft()
{
LPTSTR lpsz = m_pszString;


while (_istspace(*lpsz))
lpsz = _tcsinc(lpsz);


if (lpsz != m_pszString)
{
memmove(m_pszString, lpsz, (GetLength()+1) * sizeof(TCHAR));
}

}


void CCOMString::TrimRight()
{
LPTSTR lpsz = m_pszString;
LPTSTR lpszLast = NULL;


while (*lpsz != '\0')
{
if (_istspace(*lpsz))
{
if (lpszLast == NULL)
lpszLast = lpsz;
}
else
lpszLast = NULL;
lpsz = _tcsinc(lpsz);
}


if (lpszLast != NULL)
*lpszLast = '\0';
}


void *memmove(void *dst, const void *src, size_t count)
{
void *ret = dst;
if (dst <= src || (char *)dst >= ((char *)src + count))
{
// Non-Overlapping Buffers
// copy from lower addresses to higher addresses
while (count--)
{
*(char*)dst = *(char*)src;
dst = (char*)dst + 1;
src = (char*)src + 1;
}
}
else
{
// Overlapping Buffers
// copy from higher addresses to lower addresses
dst = (char*)dst + count - 1;
src = (char*)src + count - 1;


while (count--)
{
*(char*)dst = *(char*)src;
dst = (char*)dst - 1;
src = (char*)src - 1;
}
}


return ret;
}

你可能感兴趣的:(string)