static int getPath(const MyString& cmd, int pos, MyString* p) { int i = pos; while (i < cmd.size() && _istspace(cmd[i])) ++i; int j = i; // 处理以双引号包括的路径 if (cmd[j] == _T('"')) { ++j; while (j < cmd.size() && cmd[j] != _T('"')) ++j; if (j == cmd.size()) { return -1; } else { *p = cmd.substr(i + 1, j - i - 1); return j + 1; } } else { while (j < cmd.size() && !_istspace(cmd[j]) && cmd[j] != _T('/')) ++j; *p = cmd.substr(i, j - i); return j; } }
static bool XML_GetStrAttrTrimmed(cgMSXML::IXMLElement* pElem, BSTR pszAttr, FC_CStr* pStringToLoad) { VARIANT val; wchar_t* pszWchar; int nMCharsNeeded; VariantInit(&val); if(FAILED(pElem->getAttribute(pszAttr, &val)) || val.vt!=VT_BSTR) return false; pszWchar = val.bstrVal; while(_istspace(*pszWchar)) pszWchar++; nMCharsNeeded = wcslen(pszWchar); while(nMCharsNeeded>0 && _istspace(pszWchar[nMCharsNeeded-1])) { nMCharsNeeded--; pszWchar[nMCharsNeeded] = 0; } pStringToLoad->load(pszWchar); VariantClear(&val); return true; }
TCHAR* Misc::wordTrim(TCHAR* text) { size_t j, i; size_t len = _tcslen(text); for ( i=0;i<len;i++ ){ // find the first non-space character and store it as i if ( ! _istspace(text[i]) ) break; } for ( j=i; j < len; j++ ){ // find the last non-space character and store it as j if ( _istspace(text[j]) ) { break; } } if (i == 0 && j==len) return text; if (i==j) // empty string return NULL; if (i == 0) { text[j] = 0; return text; } else { _tcsncpy(text, text+i, j-i); text[j-i] = 0; } return text; }
TCHAR* Misc::stringTrim(TCHAR* text) { size_t j, i; size_t len = _tcslen(text); for ( i=0;i<len;i++ ){ // find the first non-space character and store it as i if ( ! _istspace(text[i]) ) break; } for ( j=len-1; j > i; --j ){ // find the last non-space character and store it as j if ( ! _istspace(text[j]) ) { break; } } if (i==0 && j==len-1) // prevent unnecessary copy return text; if (i==0) text[j+1]=0; else { j++; _tcsncpy(text, text+i, j-i); text[j-i] = 0; } return text; }
//======================================================== // Name : _SetString // Desc : put string of (psz~end) on ps string // Param : trim - will be trim? // Return : //-------------------------------------------------------- // Coder Date Desc // bro 2002-10-29 //======================================================== void _SetString( LPTSTR psz, LPTSTR end, HM::String* ps, bool trim = FALSE, int escape = 0 ) { //trim if( trim ) { while( psz && psz < end && _istspace(*psz) ) psz++; while( (end-1) && psz < (end-1) && _istspace(*(end-1)) ) end--; } int len = end - psz; if( len <= 0 ) return; if( escape ) { len = _tcselen( escape, psz, end ); LPTSTR pss = ps->GetBufferSetLength( len ); _tcsecpy( pss, escape, psz, end ); ps->ReleaseBuffer(); } else { //varför öka på strängens längd med ett här?! LPTSTR pss = ps->GetBufferSetLength( (len + 1) * sizeof(TCHAR)) ; memcpy( pss, psz, len * sizeof(TCHAR) ); ps->ReleaseBuffer(); } }
LPWSTR findFunction(LPWSTR src, LPWSTR funcText, LPWSTR params) { if(!src) return NULL; LPWSTR beginParams = StrStr(src, L"("); if(!beginParams) { return NULL; } LPWSTR endParams = StrStr(beginParams, L")"); if(!endParams) { return NULL; } lstrcpyn(params, beginParams + 1, (int) (endParams - beginParams)); params[endParams - beginParams] = 0; beginParams--; while(beginParams != src && _istspace(beginParams[0])) beginParams--; if(_istspace(beginParams[0])) { return NULL; } LPWSTR beginFunc = beginParams; while(beginFunc != src && !_istspace(beginFunc[0])) beginFunc--; if(_istspace(beginFunc[0])) { beginFunc++; } lstrcpyn(funcText, beginFunc, (int) (beginParams - beginFunc + 2)); funcText[beginParams - beginFunc + 2] = 0; return endParams + 1; }
BOOL OnOffCommand(LPTSTR param, LPBOOL flag, INT message) { TCHAR *p2; if (_tcsnicmp(param, D_OFF, sizeof(D_OFF)/sizeof(TCHAR) - 1) == 0) { p2 = param + sizeof(D_OFF)/sizeof(TCHAR) - 1; while (_istspace(*p2)) p2++; if (*p2 == _T('\0')) { *flag = FALSE; return TRUE; } } else if (_tcsnicmp(param, D_ON, sizeof(D_ON)/sizeof(TCHAR) - 1) == 0) { p2 = param + sizeof(D_ON)/sizeof(TCHAR) - 1; while (_istspace(*p2)) p2++; if (*p2 == _T('\0')) { *flag = TRUE; return TRUE; } } else if (*param == _T('\0')) { ConOutResPrintf(message, *flag ? D_ON : D_OFF); return TRUE; } return FALSE; }
static void _split_arg(const char_t *pbeg, const char_t *pend, std::vector<_ArgItem> &vArg, bool bAddHead) { const char_t *px=pbeg,*pbx=NULL; int nhead=0; //number of anonymous varibles, which must be placed at the start of command-line int ni=0; //number of named varibles, which can be placed anywhere after anonymous varibles int nq=0; //number of quotes while(px<pend) { if( (*px==_TX('-')&&px+1!=pend&&_istalpha((ushort)px[1])||*px==_TX('/'))&&(px==pbeg||_istspace((ushort)px[-1])) ) {//the beginning of a named varible, either the following two cases: // 1) '-' followed by alphabetic letters ('-' followed by number may be an negative number) // 2) '/' followed by any character if((nq&1)==0) //if not in double quotes { if(pbx) {//save the value of previous varible vArg.back().m_value.append(pbx,px); } pbx=_skip_non_space(px,pend); //the end of the varible name vArg.push_back(_ArgItem()); vArg.back().m_name=string_t(px+1,pbx); px=pbx; ++ni; } } else if(ni==0&&bAddHead&&!_istspace((ushort)*px)) {//the beginning of an anonymous varible const char_t *px0=px; px=_skip_non_str_non_space(px,pend); char_t buf[16]; _stprintf(buf,_TX("#%d"),nhead); //make an name for the varible vArg.push_back(_ArgItem()); vArg.back().m_name=buf; vArg.back().m_value=string_t(px0,px); ++nhead; } else { if(*px==_TX('\"')&&(px==pbeg||px[-1]!=_CH_CVT)) { ++nq; } } ++px; } if(pbx&&ni>0) {//save the value of the last varible vArg.back().m_value.append(pbx,pend); } }
void CFilePath::Trim(CString &sString) { if (_istspace(GetFirstChar(sString))) sString.TrimLeft(); if (_istspace(GetLastChar(sString))) sString.TrimRight(); }
BOOL COXCsvFile::WriteColumn(int nColumn, LPCTSTR lpszText, BOOL bQuote) { CString strSpecialChars; // the field and string delimiters, and line break characters strSpecialChars=m_tcFieldDelim; strSpecialChars+=m_tcStringDelim; strSpecialChars+=_T("\r\n"); SetError(errNone); if(nColumn<0 || nColumn>=m_nColumns) { SetError(errBadColumnIndex); return FALSE; } // // Important: The string needs to be quoted if one of the following conditions // is met: // 1. The string contains one of the following characters: // a. the field delimiter character // b. the string delimiter character // c. carraige return // d. line feed // 2. The string begins with a whitespace character // 3. The string ends with a whitespace character // if(!bQuote && _tcscspn(lpszText,strSpecialChars)>=_tcslen(lpszText) && !_istspace(lpszText[0]) && !_istspace(lpszText[_tcslen(lpszText)-1])) { m_arrColumns[nColumn].m_strData=lpszText; } else { CString strItem(m_tcStringDelim); for(int nIndex=0; lpszText[nIndex]!=tcNulc; ++nIndex) { if(lpszText[nIndex]==m_tcStringDelim) { strItem+=m_tcStringDelim; strItem+=m_tcStringDelim; } else { strItem+=lpszText[nIndex]; } } strItem+=m_tcStringDelim; m_arrColumns[nColumn].m_strData=strItem; m_arrColumns[nColumn].m_nType=tString; } return TRUE; }
KString KString::Trim() const { int i; for(i = 0 ; _istspace(m_Chars[i]) ; i++); int j; for(j = GetLength() - 1 ; j > i && _istspace(m_Chars[j]) ; j--); return Mid(i, j - i + 1); }
/* Note: empty/zero-length body part is translated as ALL */ IMAP4_BODYPART_CASE imap4XlateBodyPart (LPCTSTR lpszBodyPart, const UINT32 ulPartLen) { LPCTSTR lpszBP=lpszBodyPart; UINT32 ulIdx=0, ulPLen=ulPartLen, ulBPLen=ulPartLen; if (NULL == lpszBodyPart) return IMAP4_BAD_BODYPART; if ((_T('\0') == *lpszBodyPart) || (0 == ulPartLen)) return IMAP4_ALL_BODYPART; /* skip white space */ for (ulIdx=0, ulPLen=ulBPLen; _istspace(*lpszBP) && (ulIdx < ulPLen); ulIdx++, lpszBP++, ulBPLen--); /* find out if have any part numbers preceding the body part */ for (ulIdx=0, ulPLen=ulBPLen; _istdigit(*lpszBP) && (ulIdx < ulPLen); ulIdx++, lpszBP++, ulBPLen--) { if (IMAP4_BODYPART_DELIM == *(lpszBP+1)) { lpszBP++; ulIdx++; ulBPLen--; } } /* skip white space */ for (ulIdx=0, ulPLen=ulBPLen; _istspace(*lpszBP) && (ulIdx < ulPLen); ulIdx++, lpszBP++, ulBPLen--); /* find out if have headers list */ for (ulIdx=0, ulPLen=ulBPLen; ulIdx < ulPLen; ulIdx++) { TCHAR tch=lpszBP[ulIdx]; if (_istspace(tch) || (IMAP4_PARLIST_SDELIM == tch) || (IMAP4_BRCKT_EDELIM == tch)) { ulBPLen = ulIdx; break; } } for (ulIdx=0; ; ulIdx++) { const XLBDYPART *pxlPart=&xlBdyParts[ulIdx]; if (NULL == pxlPart->lpszBodyPart) break; ulPLen = _tcslen(pxlPart->lpszBodyPart); if ((ulPLen == ulBPLen) && (_tcsnicmp(pxlPart->lpszBodyPart, lpszBP, ulPLen) == 0)) return pxlPart->bCase; } return IMAP4_BAD_BODYPART; }
static void cleanup_space(CString& string) { for (int pos = 0; pos < string.GetLength(); ++pos) { if (_istspace(string[pos])) { string.SetAt(pos ,_T(' ')); int cnt; for (cnt = 0; _istspace(string[pos + cnt + 1]); ++cnt); string.Delete(pos + 1, cnt); } } }
BOOL COXString::IsNumber() { LPCTSTR pc = *this; BOOL bDigit = FALSE; // Skip white space characters while (_istspace(*pc)) pc++; // Skip sign if ((*pc == _T('-')) || (*pc == _T('+'))) pc++; // Skip digits while (_istdigit(*pc)) { pc++; bDigit = TRUE; } // Skip decimal sign if (*pc == cDecimalCharacter) pc++; if (!bDigit && !_istdigit(*pc)) return FALSE; // Skip digits while (_istdigit(*pc)) pc++; // Skip exponent sign and rest if ((*pc == _T('E')) || (*pc == _T('e')) || (*pc == _T('D')) || (*pc == _T('d'))) { pc++; // Skip sign if ((*pc == _T('-')) || (*pc == _T('+'))) pc++; // Skip digits if (!_istdigit(*pc)) // Exponent sign is not followed by digits return FALSE; while (_istdigit(*pc)) pc++; } // Skip white space characters while (_istspace(*pc)) pc++; // Pointer should not be behind the end of the string ASSERT(pc <= (((LPCTSTR)*this) + GetLength())); // Must be at the end of the string by now, otherwise the number is not valid return (*pc == _T('\0')); }
// remove whitespace from start and end of a string // void strip_whitespace(wxChar *str) { size_t n; while (1) { if (!str[0]) break; if (!_istascii(str[0])) break; if (!_istspace(str[0])) break; strcpy_overlap(str, str+1); } while (1) { n = _tcslen(str); if (n == 0) break; if (!_istascii(str[n-1])) break; if (!_istspace(str[n-1])) break; str[n-1] = 0; } }
/* * set the exitflag to true */ INT CommandExit (LPTSTR param) { if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_EXIT_HELP); /* Just make sure */ bExit = FALSE; /* Dont exit */ return 0; } if (bc != NULL && _tcsnicmp(param,_T("/b"),2) == 0) { param += 2; while (_istspace (*param)) param++; if (_istdigit(*param)) nErrorLevel = _ttoi(param); ExitBatch(); } else { bExit = TRUE; } return 0; }
/* move string pointer to next word (skip all spaces) on erro retunr nonzero value */ static INT chop_blank(LPTSTR *arg_str) { LPTSTR str; str = _tcschr(*arg_str,_T(' ')); if(!str) { str = _tcschr (*arg_str, _T('\0')); if(str != NULL) *arg_str=str; return CP_BLANK_NOT_FOUND; } while(_istspace(*str)) str++; if (*str == _T('\0')) { *arg_str=str; return CP_END_OF_STRING; } *arg_str = str; return CP_OK; }
static void propvalue(char *buffer, int size) { char *p = buffer; match('['); while (lookahead != ']' && lookahead != '\0') { if (lookahead == '\\') { lookahead = sgf_getch(); /* Follow the FF4 definition of backslash */ if (lookahead == '\r') { lookahead = sgf_getch(); if (lookahead == '\n') lookahead = sgf_getch(); } else if (lookahead == '\n') { lookahead = sgf_getch(); if (lookahead == '\r') lookahead = sgf_getch(); } } if (size > 1) { *p++ = lookahead; size--; } lookahead = sgf_getch(); } match(']'); /* Remove trailing whitespace */ --p; while (p > buffer && _istspace((int) *p)) --p; *++p = '\0'; }
static void nexttoken() { do lookahead = sgf_getch(); while (_istspace(lookahead)); }
static char_t *_skip_non_space(const char_t *pbeg,const char_t *pend) { while(pbeg<pend&&!_istspace((unsigned short)*pbeg)) ++pbeg; return (char_t*)pbeg; }
// Remove the headers from the input buffer, handing each to OnHeaderLine BOOL CConnection::ReadHeaders() { // Move the first line from the m_pInput buffer to strLine and do the contents of the while loop CString strLine; while ( Read( strLine ) ) // ReadLine will return false when there are no more lines { // If the line is more than 256 KB, change it to the long line error code if ( strLine.GetLength() > HTTP_HEADER_MAX_LINE ) strLine = _T("#LINE_TOO_LONG#"); // Find the first colon in the line int nPos = strLine.Find( _T(":") ); // The line is empty, it's just a \n character if ( strLine.IsEmpty() ) { // Empty the last header member variable (do) m_sLastHeader.Empty(); // Call the OnHeadersComplete method for the most advanced class that inherits from CConnection return OnHeadersComplete(); } else if ( _istspace( strLine.GetAt( 0 ) ) ) // Get the first character in the string, and see if its a space { // The line starts with a space // The last header has length if ( ! m_sLastHeader.IsEmpty() ) { // Trim whitespace from both ends of the line, and ensure it still has length strLine.Trim(); if ( strLine.IsEmpty() ) continue; // Give OnHeaderLine the last header and this line if ( ! OnHeaderLine( m_sLastHeader, strLine ) ) return FALSE; } } else if ( nPos > 1 && nPos < 64 ) // ":a" is 0 and "a:a" is 1, but "aa:a" is greater than 1 { // The colon is at a distance greater than 1 and less than 64 // The line is like "header:value", copy out both parts CString strHeader = strLine.Left( nPos ); CString strValue = strLine.Mid( nPos + 1 ); m_sLastHeader = strHeader; strValue.Trim(); if ( strValue.IsEmpty() ) continue; // Give OnHeaderLine this last header, and its value if ( ! OnHeaderLine( strHeader, strValue ) ) return FALSE; } } // Send the contents of the output buffer to the remote computer OnWrite(); return TRUE; }
BOOL COXQuickString::TrimLeft() { if (IsEmpty()) return TRUE; LPTSTR ptr = m_szText; while (ptr - m_szText < (int)m_nLength && _istspace(*ptr)) ptr++; if (ptr != m_szText) { int nLength = m_nLength-(ptr-m_szText); LPTSTR szNewString = AllocBuffer(nLength+1); if (!szNewString) return FALSE; UTBStr::tcscpy(szNewString, nLength+1, ptr); szNewString[nLength] = TEXT('\0'); m_nLength = nLength; m_nBufferSize = nLength+1; delete [] m_szText; m_szText = szNewString; } return TRUE; }
void CNoteItem::SetData(TCHAR *title, TCHAR *from, TCHAR *text, TCHAR *tags) { mir_free(m_szTitle); mir_free(m_szFrom); mir_free(m_szText); mir_free(m_szTags); mir_free(m_szTagsStr); m_szTitle = StrTrimCopy(title); m_szText = JabberStrFixLines(text); m_szFrom = StrTrimCopy(from); const TCHAR *szTags = tags; TCHAR *p = m_szTags = (TCHAR *)mir_alloc((lstrlen(szTags) + 2 /*for double zero*/) * sizeof(TCHAR)); TCHAR *q = m_szTagsStr = (TCHAR *)mir_alloc((lstrlen(szTags) + 1) * sizeof(TCHAR)); for ( ; szTags && *szTags; ++szTags) { if (_istspace(*szTags)) continue; if (*szTags == _T(',')) { *q++ = _T(','); *p++ = 0; continue; } *q++ = *p++ = *szTags; } q[0] = p[0] = p[1] = 0; }
static void _create_arg_index(char_t *pbeg,char_t *pend, std::vector<const char_t *> &idx) { assert(pbeg==pend||_istspace((ushort)pend[-1])); char_t *px=pbeg; while(px<pend) { char_t *pbx=_skip_space(px,pend); char_t *pex=_skip_non_str_non_space(pbx,pend); if(pbx!=pex) { _cvt_cmd_string(pbx,pex); idx.push_back(pbx); px=pex+1; } else { assert(pex==pend); px=pend; } } }
CString ExtractTag(CString tag, CMapStringToString& attribs, bool& fClosing) { tag.Trim(); attribs.RemoveAll(); fClosing = !tag.IsEmpty() ? tag[0] == '/' : false; tag.TrimLeft('/'); int i = tag.Find(' '); if (i < 0) { i = tag.GetLength(); } CString type = tag.Left(i).MakeLower(); tag = tag.Mid(i).Trim(); while ((i = tag.Find('=')) > 0) { CString attrib = tag.Left(i).Trim().MakeLower(); tag = tag.Mid(i + 1); for (i = 0; i < tag.GetLength() && _istspace(tag[i]); i++); tag = i < tag.GetLength() ? tag.Mid(i) : _T(""); if (!tag.IsEmpty() && tag[0] == '\"') {tag = tag.Mid(1); i = tag.Find('\"');} else { i = tag.Find(' '); } if (i < 0) { i = tag.GetLength(); } CString param = tag.Left(i).Trim(); if (!param.IsEmpty()) { attribs[attrib] = param; } tag = i + 1 < tag.GetLength() ? tag.Mid(i + 1) : _T(""); } return (type); }
INT CommandEcho (LPTSTR param) { LPTSTR p1; TRACE ("CommandEcho: '%s'\n", debugstr_aw(param)); /* skip all spaces for the check of '/?', 'ON' and 'OFF' */ p1 = param; while(_istspace(*p1)) p1++; if (!_tcsncmp (p1, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_ECHO_HELP4); return 0; } if (!OnOffCommand(p1, &bEcho, STRING_ECHO_HELP5)) { /* skip the first character */ ConOutPuts(param + 1); ConOutChar(_T('\n')); } return 0; }
void COXString::LTrim() { int nStringIndex = 0; int nLength = GetLength(); // find first non-space character LPCTSTR lpsz = *this; while (_istspace(*lpsz)) #ifdef WIN32 lpsz = _tcsinc(lpsz); #else lpsz++; #endif // fix up data and length #if _MFC_VER < 0x0700 nStringIndex = lpsz - m_pchData; #else nStringIndex = PtrToInt(lpsz - GetBuffer()); #endif if (nStringIndex == nLength) *this = COXString(_T("")); else *this = Mid(nStringIndex); }
int CIni::Parse(const CString& strIn, int nOffset, CString& strOut) { strOut.Empty(); int nLength = strIn.GetLength(); if(nOffset < nLength) { if(nOffset != 0 && strIn[nOffset] == _T(',')) nOffset++; while(nOffset < nLength) { if(!_istspace((_TUCHAR)strIn[nOffset])) break; nOffset++; } while(nOffset < nLength) { strOut += strIn[nOffset]; if(strIn[++nOffset] == _T(',')) break; } strOut.Trim(); } return nOffset; }
/* returns EIOUNCLASS if no match found */ EXC_TYPE imap4AnalyzeWelcomePattern (LPCTSTR lpszWelcome, LPCTSTR lpszWPattern, LPTSTR lpszType, const UINT32 ulMaxTypeLen, LPTSTR lpszVersion, const UINT32 ulMaxVerLen) { EXC_TYPE exc=EOK; TCHAR szTArg[MAX_IMAP4_OPCODE_LEN+2]; LPCTSTR lpszWPos=lpszWelcome; if (IsEmptyStr(lpszWelcome) || IsEmptyStr(lpszWPattern) || (NULL == lpszType) || (0 == ulMaxTypeLen) || (NULL == lpszVersion) || (0 == ulMaxVerLen)) return EPARAM; *lpszType = _T('\0'); *lpszVersion = _T('\0'); /* make sure this is an untagged response */ for ( ; _istspace(*lpszWPos) && (*lpszWPos != _T('\0')); lpszWPos++); if (*lpszWPos != IMAP4_UNTAGGED_RSP) return EUDFFORMAT; /* make sure this is an OK response */ if ((exc=imap4GetArg((lpszWPos+1), szTArg, MAX_IMAP4_OPCODE_LEN, &lpszWPos)) != EOK) return exc; if ((exc=imap4XlateRspCode(szTArg)) != EOK) return exc; if ((exc=inetAnalyzeWelcomePattern(lpszWPos, lpszWPattern, lpszType, ulMaxTypeLen, lpszVersion, ulMaxVerLen)) != EOK) return exc; return EOK; }
static void _read_strings(const char_t *pbeg, const char_t *pend, std::vector<string_t> &vstr) { if(pbeg&&pend>pbeg) { int nq=0; const char_t *px=pbeg,*pwb=NULL; while(px!=pend) { if(!_istspace((ushort)*px)) { if(!pwb) { pwb=px; nq=0; } if(*px==_TX('\"')&&px!=pbeg&&px[-1]!=_CH_CVT) ++nq; } else { if(pwb&&(nq&1)==0) { _pro_arg(pwb,px,nq,vstr); pwb=NULL; } } ++px; } if(pwb) _pro_arg(pwb,px,nq,vstr); } }