コード例 #1
0
ファイル: CString.cpp プロジェクト: Seldom/miranda-ng
TString<T>& TString<T>::Replace(const T *szFind, const T *szReplaceBy)
{
    if (!pBuf)
    {
        return *this;
    }
    T *pCurPos = pBuf;
    int FindLen = My_lstrlen(szFind);
    T *p;
    TString<T> Result;
    Result.GetBuffer(1)[0] = '\0';
    Result.ReleaseBuffer(0); // set the string to ""; we can't do it in a usual way (using a constructor or an assignment) because we don't know whether "" needs to be unicode or ansi
    while (p = ( T* )My_strstr(pCurPos, szFind))
    {
        Result.DiffCat(pCurPos, p);
        Result += szReplaceBy;
        pCurPos = p + FindLen;
    }
    Result += pCurPos;
    *this = Result;
    return *this;
}
コード例 #2
0
ファイル: CString.cpp プロジェクト: Seldom/miranda-ng
TString<T>& TString<T>::Replace(int nIndex, int nCount, const T *szReplaceBy)
{
    if (!pBuf || !szReplaceBy || nIndex < 0 || nCount < 0)
    {
        return *this;
    }

    TString<T> Result;
    Result.GetBuffer(1)[0] = '\0';
    Result.ReleaseBuffer(0); // set the string to ""; we can't do it in a usual way (using a constructor or an assignment) because we don't know whether "" needs to be unicode or ansi
    if (nIndex > GetLen())
    {
        nIndex = GetLen();
    }
    if (nIndex + nCount > GetLen())
    {
        nCount = GetLen() - nIndex;
    }
    Result.DiffCat(pBuf, pBuf + nIndex);
    Result += szReplaceBy;
    Result += pBuf + nIndex + nCount;
    *this = Result;
    return *this;
}