📄 xtrim.cpp
字号:
// XTrim.cpp Version 1.0
//
// Author: Hans Dietrich
// hdietrich2@hotmail.com
//
// Description:
// XTrim.cpp implements _tcsltrim() and _tcsrtrim().
//
// History
// Version 1.0 - 2003 May 21
// - Initial public release
//
// This software is released into the public domain. You are free to use it
// in any way you like.
//
// This software is provided "as is" with no expressed or implied warranty.
// I accept no liability for any damage or loss of business that this software
// may cause.
//
///////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <tchar.h>
#include "XTrim.h"
///////////////////////////////////////////////////////////////////////////////
//
// _tcsltrim()
//
// Purpose: Removes (trims) leading whitespace characters from a string
//
// Parameters: pszSource - Pointer to the null-terminated string to be trimmed.
// On return, pszSource will hold the trimmed string
//
// Returns: TCHAR * - pointer to trimmed string
//
TCHAR * _tcsltrim(TCHAR * pszSource)
{
TCHAR * cp = pszSource;
if (cp && *cp)
{
// find first non-whitespace character
while (_istspace(*cp))
cp++;
if (cp != pszSource)
memcpy(pszSource, cp, (_tcslen(cp)+1)*sizeof(TCHAR));
}
return pszSource;
}
///////////////////////////////////////////////////////////////////////////////
//
// _tcsrtrim()
//
// Purpose: Removes (trims) trailing whitespace characters from a string
//
// Parameters: pszSource - Pointer to the null-terminated string to be trimmed.
// On return, pszSource will hold the trimmed string
//
// Returns: TCHAR * - pointer to trimmed string
//
TCHAR * _tcsrtrim(TCHAR * pszSource)
{
TCHAR * cp = pszSource;
if (cp && *cp)
{
BOOL bNonSpaceSeen = FALSE;
// check if string is blank
while (*cp)
{
if (!_istspace(*cp))
bNonSpaceSeen = TRUE;
cp++;
}
if (bNonSpaceSeen)
{
cp--;
// find last non-whitespace character
while ((cp >= pszSource) && (_istspace(*cp)))
*cp-- = _T('\0');
}
else
{
// string contains only whitespace characters
*pszSource = _T('\0');
}
}
return pszSource;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -