コード例 #1
0
FX_STRSIZE CFX_WideString::Insert(FX_STRSIZE nIndex, FX_WCHAR ch)
{
    CopyBeforeWrite();
    if (nIndex < 0) {
        nIndex = 0;
    }
    FX_STRSIZE nNewLength = GetLength();
    if (nIndex > nNewLength) {
        nIndex = nNewLength;
    }
    nNewLength++;
    if (m_pData == NULL || m_pData->m_nAllocLength < nNewLength) {
        StringData* pOldData = m_pData;
        const FX_WCHAR* pstr = m_pData->m_String;
        m_pData = StringData::Create(nNewLength);
        if (!m_pData) {
            return 0;
        }
        if(pOldData != NULL) {
            FXSYS_memmove(m_pData->m_String, pstr, (pOldData->m_nDataLength + 1)*sizeof(FX_WCHAR));
            pOldData->Release();
        } else {
            m_pData->m_String[0] = 0;
        }
    }
    FXSYS_memmove(m_pData->m_String + nIndex + 1,
                    m_pData->m_String + nIndex, (nNewLength - nIndex)*sizeof(FX_WCHAR));
    m_pData->m_String[nIndex] = ch;
    m_pData->m_nDataLength = nNewLength;
    return nNewLength;
}
コード例 #2
0
void CFDE_TxtEdtBuf::Delete(int32_t nIndex, int32_t nLength) {
  ASSERT(nLength > 0 && nIndex >= 0 && nIndex + nLength <= m_nTotal);
  FDE_CHUNKPLACE cpEnd;
  Index2CP(nIndex + nLength - 1, cpEnd);
  m_nTotal -= nLength;
  FDE_CHUNKHEADER* lpChunk = m_Chunks[cpEnd.nChunkIndex];
  int32_t nFirstPart = cpEnd.nCharIndex + 1;
  int32_t nMovePart = lpChunk->nUsed - nFirstPart;
  if (nMovePart != 0) {
    int32_t nDelete = std::min(nFirstPart, nLength);
    FXSYS_memmove(lpChunk->wChars + nFirstPart - nDelete,
                  lpChunk->wChars + nFirstPart, nMovePart * sizeof(FX_WCHAR));
    lpChunk->nUsed -= nDelete;
    nLength -= nDelete;
    cpEnd.nChunkIndex--;
  }
  while (nLength > 0) {
    lpChunk = m_Chunks[cpEnd.nChunkIndex];
    int32_t nDeleted = std::min(lpChunk->nUsed, nLength);
    lpChunk->nUsed -= nDeleted;
    if (lpChunk->nUsed == 0) {
      m_pAllocator->Free(lpChunk);
      m_Chunks.RemoveAt(cpEnd.nChunkIndex);
      lpChunk = nullptr;
    }
    nLength -= nDeleted;
    cpEnd.nChunkIndex--;
  }
  m_bChanged = TRUE;
}
コード例 #3
0
void CFX_BinaryBuf::Delete(int start_index, int count) {
  if (!m_pBuffer || start_index < 0 || start_index + count > m_DataSize) {
    return;
  }
  FXSYS_memmove(m_pBuffer + start_index, m_pBuffer + start_index + count,
                m_DataSize - start_index - count);
  m_DataSize -= count;
}
コード例 #4
0
FX_STRSIZE CFX_WideString::Replace(const FX_WCHAR* lpszOld, const FX_WCHAR* lpszNew)
{
    if (GetLength() < 1) {
        return 0;
    }
    if (lpszOld == NULL) {
        return 0;
    }
    FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld);
    if (nSourceLen == 0) {
        return 0;
    }
    FX_STRSIZE nReplacementLen = lpszNew ? FXSYS_wcslen(lpszNew) : 0;
    FX_STRSIZE nCount = 0;
    FX_WCHAR* lpszStart = m_pData->m_String;
    FX_WCHAR* lpszEnd = m_pData->m_String + m_pData->m_nDataLength;
    FX_WCHAR* lpszTarget;
    {
        while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != NULL && lpszStart < lpszEnd) {
            nCount++;
            lpszStart = lpszTarget + nSourceLen;
        }
    }
    if (nCount > 0) {
        CopyBeforeWrite();
        FX_STRSIZE nOldLength = m_pData->m_nDataLength;
        FX_STRSIZE nNewLength =  nOldLength + (nReplacementLen - nSourceLen) * nCount;
        if (m_pData->m_nAllocLength < nNewLength || m_pData->m_nRefs > 1) {
            StringData* pOldData = m_pData;
            const FX_WCHAR* pstr = m_pData->m_String;
            m_pData = StringData::Create(nNewLength);
            if (!m_pData) {
                return 0;
            }
            FXSYS_memcpy(m_pData->m_String, pstr, pOldData->m_nDataLength * sizeof(FX_WCHAR));
            pOldData->Release();
        }
        lpszStart = m_pData->m_String;
        lpszEnd = m_pData->m_String + FX_MAX(m_pData->m_nDataLength, nNewLength);
        {
            while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != NULL && lpszStart < lpszEnd) {
                FX_STRSIZE nBalance = nOldLength - (FX_STRSIZE)(lpszTarget - m_pData->m_String + nSourceLen);
                FXSYS_memmove(lpszTarget + nReplacementLen, lpszTarget + nSourceLen, nBalance * sizeof(FX_WCHAR));
                FXSYS_memcpy(lpszTarget, lpszNew, nReplacementLen * sizeof(FX_WCHAR));
                lpszStart = lpszTarget + nReplacementLen;
                lpszStart[nBalance] = 0;
                nOldLength += (nReplacementLen - nSourceLen);
            }
        }
        ASSERT(m_pData->m_String[nNewLength] == 0);
        m_pData->m_nDataLength = nNewLength;
    }
    return nCount;
}
コード例 #5
0
ファイル: fx_basic_buffer.cpp プロジェクト: abbro-ca/pdfium
void CFX_BinaryBuf::InsertBlock(FX_STRSIZE pos, const void* pBuf, FX_STRSIZE size)
{
    ExpandBuf(size);
    if (!m_pBuffer) {
        return;
    }
    FXSYS_memmove(m_pBuffer + pos + size, m_pBuffer + pos, m_DataSize - pos);
    if (pBuf) {
        FXSYS_memcpy(m_pBuffer + pos, pBuf, size);
    }
    m_DataSize += size;
}
コード例 #6
0
void CFDE_CSSTextBuf::Subtract(int32_t iStart, int32_t iLength) {
  FXSYS_assert(iStart >= 0 && iLength > 0);
  if (iLength > m_iDatLen - iStart) {
    iLength = m_iDatLen - iStart;
  }
  if (iLength < 0) {
    iLength = 0;
  } else {
    FXSYS_memmove(m_pBuffer, m_pBuffer + iStart, iLength * sizeof(FX_WCHAR));
  }
  m_iDatLen = iLength;
}
コード例 #7
0
bool CFX_BasicArray::RemoveAt(int nIndex, int nCount) {
  if (nIndex < 0 || nCount <= 0 || m_nSize < nIndex + nCount) {
    return false;
  }
  int nMoveCount = m_nSize - (nIndex + nCount);
  if (nMoveCount) {
    FXSYS_memmove(m_pData + nIndex * m_nUnitSize,
                  m_pData + (nIndex + nCount) * m_nUnitSize,
                  nMoveCount * m_nUnitSize);
  }
  m_nSize -= nCount;
  return true;
}
コード例 #8
0
FX_STRSIZE CFX_WideString::Delete(FX_STRSIZE nIndex, FX_STRSIZE nCount)
{
    if (GetLength() < 1) {
        return 0;
    }
    if (nIndex < 0) {
        nIndex = 0;
    }
    FX_STRSIZE nOldLength = m_pData->m_nDataLength;
    if (nCount > 0 && nIndex < nOldLength) {
        CopyBeforeWrite();
        int nBytesToCopy = nOldLength - (nIndex + nCount) + 1;
        FXSYS_memmove(m_pData->m_String + nIndex,
                        m_pData->m_String + nIndex + nCount, nBytesToCopy * sizeof(FX_WCHAR));
        m_pData->m_nDataLength = nOldLength - nCount;
    }
    return m_pData->m_nDataLength;
}
コード例 #9
0
FX_BOOL CFDE_TxtEdtEngine::ReplaceParagEnd(FX_WCHAR*& lpText,
                                           int32_t& nLength,
                                           FX_BOOL bPreIsCR) {
  for (int32_t i = 0; i < nLength; i++) {
    FX_WCHAR wc = lpText[i];
    switch (wc) {
      case L'\r': {
        lpText[i] = m_wLineEnd;
        bPreIsCR = TRUE;
      } break;
      case L'\n': {
        if (bPreIsCR == TRUE) {
          int32_t nNext = i + 1;
          if (nNext < nLength) {
            FXSYS_memmove(lpText + i, lpText + nNext,
                          (nLength - nNext) * sizeof(FX_WCHAR));
          }
          i--;
          nLength--;
          bPreIsCR = FALSE;
          if (m_bAutoLineEnd) {
            m_nFirstLineEnd = FDE_TXTEDIT_LINEEND_CRLF;
            m_bAutoLineEnd = FALSE;
          }
        } else {
          lpText[i] = m_wLineEnd;
          if (m_bAutoLineEnd) {
            m_nFirstLineEnd = FDE_TXTEDIT_LINEEND_LF;
            m_bAutoLineEnd = FALSE;
          }
        }
      } break;
      default: {
        if (bPreIsCR && m_bAutoLineEnd) {
          m_nFirstLineEnd = FDE_TXTEDIT_LINEEND_CR;
          m_bAutoLineEnd = FALSE;
        }
        bPreIsCR = FALSE;
      } break;
    }
  }
  return bPreIsCR;
}
コード例 #10
0
uint8_t* CFX_BasicArray::InsertSpaceAt(int nIndex, int nCount) {
  if (nIndex < 0 || nCount <= 0) {
    return nullptr;
  }
  if (nIndex >= m_nSize) {
    if (!SetSize(nIndex + nCount)) {
      return nullptr;
    }
  } else {
    int nOldSize = m_nSize;
    if (!SetSize(m_nSize + nCount)) {
      return nullptr;
    }
    FXSYS_memmove(m_pData + (nIndex + nCount) * m_nUnitSize,
                  m_pData + nIndex * m_nUnitSize,
                  (nOldSize - nIndex) * m_nUnitSize);
    FXSYS_memset(m_pData + nIndex * m_nUnitSize, 0, nCount * m_nUnitSize);
  }
  return m_pData + nIndex * m_nUnitSize;
}
コード例 #11
0
FX_STRSIZE CFX_ByteString::Delete(FX_STRSIZE nIndex, FX_STRSIZE nCount) {
  if (!m_pData)
    return 0;

  if (nIndex < 0)
    nIndex = 0;

  FX_STRSIZE nOldLength = m_pData->m_nDataLength;
  if (nCount > 0 && nIndex < nOldLength) {
    FX_STRSIZE mLength = nIndex + nCount;
    if (mLength >= nOldLength) {
      m_pData->m_nDataLength = nIndex;
      return m_pData->m_nDataLength;
    }
    ReallocBeforeWrite(nOldLength);
    int nCharsToCopy = nOldLength - mLength + 1;
    FXSYS_memmove(m_pData->m_String + nIndex, m_pData->m_String + mLength,
                  nCharsToCopy);
    m_pData->m_nDataLength = nOldLength - nCount;
  }
  return m_pData->m_nDataLength;
}
コード例 #12
0
void CFX_WideString::TrimLeft(const FX_WCHAR* lpszTargets)
{
    FXSYS_assert(lpszTargets != NULL);
    if (m_pData == NULL || *lpszTargets == 0) {
        return;
    }
    CopyBeforeWrite();
    if (GetLength() < 1) {
        return;
    }
    const FX_WCHAR* lpsz = m_pData->m_String;
    while (*lpsz != 0) {
        if (FXSYS_wcschr(lpszTargets, *lpsz) == NULL) {
            break;
        }
        lpsz ++;
    }
    if (lpsz != m_pData->m_String) {
        int nDataLength = m_pData->m_nDataLength - (FX_STRSIZE)(lpsz - m_pData->m_String);
        FXSYS_memmove(m_pData->m_String, lpsz, (nDataLength + 1)*sizeof(FX_WCHAR));
        m_pData->m_nDataLength = nDataLength;
    }
}
コード例 #13
0
ファイル: fx_sax_imp.cpp プロジェクト: primiano/pdfium-merge
void CFX_SAXReader::SkipNode() {
  int32_t iLen = m_SkipStack.GetSize();
  if (m_SkipChar == '\'' || m_SkipChar == '\"') {
    if (m_CurByte != m_SkipChar) {
      return;
    }
    iLen--;
    FXSYS_assert(iLen > -1);
    m_SkipStack.RemoveAt(iLen, 1);
    m_SkipChar = iLen ? m_SkipStack[iLen - 1] : 0;
    return;
  }
  switch (m_CurByte) {
    case '<':
      m_SkipChar = '>';
      m_SkipStack.Add('>');
      break;
    case '[':
      m_SkipChar = ']';
      m_SkipStack.Add(']');
      break;
    case '(':
      m_SkipChar = ')';
      m_SkipStack.Add(')');
      break;
    case '\'':
      m_SkipChar = '\'';
      m_SkipStack.Add('\'');
      break;
    case '\"':
      m_SkipChar = '\"';
      m_SkipStack.Add('\"');
      break;
    default:
      if (m_CurByte == m_SkipChar) {
        iLen--;
        m_SkipStack.RemoveAt(iLen, 1);
        m_SkipChar = iLen ? m_SkipStack[iLen - 1] : 0;
        if (iLen == 0 && m_CurByte == '>') {
          m_iDataLength = m_iDataPos;
          m_iDataPos = 0;
          if (m_iDataLength >= 9 &&
              FXSYS_memcmp(m_pszData, "[CDATA[", 7 * sizeof(uint8_t)) == 0 &&
              FXSYS_memcmp(m_pszData + m_iDataLength - 2, "]]",
                           2 * sizeof(uint8_t)) == 0) {
            Pop();
            m_iDataLength -= 9;
            m_dwDataOffset += 7;
            FXSYS_memmove(m_pszData, m_pszData + 7,
                          m_iDataLength * sizeof(uint8_t));
            m_bCharData = TRUE;
            if (m_pHandler) {
              NotifyData();
            }
            m_bCharData = FALSE;
          } else {
            Pop();
          }
          m_eMode = FX_SAXMODE_Text;
        }
      }
      break;
  }
  if (iLen > 0) {
    ParseChar(m_CurByte);
  }
}
コード例 #14
0
ファイル: cmserr.c プロジェクト: gradescope/pdfium
// Generic block duplication
void* CMSEXPORT _cmsDupMem(cmsContext ContextID, const void* Org, cmsUInt32Number size)
{
	void* p = FXMEM_DefaultAlloc(size, 1);
	FXSYS_memmove(p, Org, size);
	return p;
}