#ifndef _MFC #include #include #endif #include "CStringAndstring.h" ///////////////////////////////////////////////////////////////////////////// // void stringTrimAll (string &str) { stringTrimLeft(str); stringTrimRight(str); } ///////////////////////////////////////////////////////////////////////////// // void stringTrimLeft (string& str) { // find first non-space character LPCTSTR lpsz = str.c_str(); while (_istspace(*lpsz)) lpsz = _tcsinc(lpsz); if (lpsz != str.c_str()) { // fix up data and length int nDataLength = str.length() - (lpsz - str.c_str()); memmove((LPTSTR)str.c_str(), lpsz, (nDataLength+1)*sizeof(TCHAR)); str.resize(nDataLength); } } ///////////////////////////////////////////////////////////////////////////// // void stringTrimRight (string& str) { // find beginning of trailing spaces by starting at beginning (DBCS aware) LPTSTR lpsz = (LPTSTR)str.c_str(); LPTSTR lpszLast = NULL; while (*lpsz != '\0') { if (_istspace(*lpsz)) { if (lpszLast == NULL) lpszLast = lpsz; } else lpszLast = NULL; lpsz = _tcsinc(lpsz); } if (lpszLast != NULL) { // truncate at trailing space start *lpszLast = '\0'; str.resize(lpszLast - str.c_str()); } } ///////////////////////////////////////////////////////////////////////////// // void stringMakeUpper (string& str) { LPTSTR lpsz = (LPTSTR)str.c_str(); _strupr_s(lpsz, str.length()+1); } ///////////////////////////////////////////////////////////////////////////// // void stringMakeLower (string& str) { LPTSTR lpsz = (LPTSTR)str.c_str(); _strlwr_s(lpsz, str.length() + 1); } ///////////////////////////////////////////////////////////////////////////// // void stringMakeLower2 (char* str, int isize) { _strlwr_s(str, isize +1); }