summaryrefslogtreecommitdiff
path: root/core/src/fxcrt
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2016-01-11 11:59:17 -0800
committerLei Zhang <thestig@chromium.org>2016-01-11 11:59:17 -0800
commit375a86403b7fa8d17d7b142c270e2d8e33bb924f (patch)
tree1db1ffddb2bbbcd429cd1d7954b1949bfa54e1ab /core/src/fxcrt
parent492961df3011ccc25646eae12ac6e6dcfe7f26da (diff)
downloadpdfium-375a86403b7fa8d17d7b142c270e2d8e33bb924f.tar.xz
Merge to XFA: Switch most min/max macros to std::min/max.
Fix lint errors along the way. R=tsepez@chromium.org TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1567343002 . (cherry picked from commit 9adfbb0920a258e916003b1ee9515e97879db82a) Review URL: https://codereview.chromium.org/1577503002 .
Diffstat (limited to 'core/src/fxcrt')
-rw-r--r--core/src/fxcrt/extension.h61
-rw-r--r--core/src/fxcrt/fx_basic_buffer.cpp4
-rw-r--r--core/src/fxcrt/fx_basic_wstring.cpp8
-rw-r--r--core/src/fxcrt/fx_extension.cpp53
-rw-r--r--core/src/fxcrt/xml_int.h9
5 files changed, 89 insertions, 46 deletions
diff --git a/core/src/fxcrt/extension.h b/core/src/fxcrt/extension.h
index 638ffef58e..6e799eb3a4 100644
--- a/core/src/fxcrt/extension.h
+++ b/core/src/fxcrt/extension.h
@@ -7,6 +7,8 @@
#ifndef CORE_SRC_FXCRT_EXTENSION_H_
#define CORE_SRC_FXCRT_EXTENSION_H_
+#include <algorithm>
+
#include "core/include/fxcrt/fx_basic.h"
#include "core/include/fxcrt/fx_safe_types.h"
@@ -67,39 +69,21 @@ class CFX_CRTFileAccess : public IFX_FileAccess {
class CFX_CRTFileStream final : public IFX_FileStream {
public:
- CFX_CRTFileStream(IFXCRT_FileAccess* pFA) : m_pFile(pFA), m_dwCount(1) {}
- ~CFX_CRTFileStream() override {
- if (m_pFile) {
- m_pFile->Release();
- }
- }
- virtual IFX_FileStream* Retain() override {
- m_dwCount++;
- return this;
- }
- virtual void Release() override {
- FX_DWORD nCount = --m_dwCount;
- if (!nCount) {
- delete this;
- }
- }
- virtual FX_FILESIZE GetSize() override { return m_pFile->GetSize(); }
- virtual FX_BOOL IsEOF() override { return GetPosition() >= GetSize(); }
- virtual FX_FILESIZE GetPosition() override { return m_pFile->GetPosition(); }
- virtual FX_BOOL ReadBlock(void* buffer,
- FX_FILESIZE offset,
- size_t size) override {
- return (FX_BOOL)m_pFile->ReadPos(buffer, size, offset);
- }
- virtual size_t ReadBlock(void* buffer, size_t size) override {
- return m_pFile->Read(buffer, size);
- }
- virtual FX_BOOL WriteBlock(const void* buffer,
- FX_FILESIZE offset,
- size_t size) override {
- return (FX_BOOL)m_pFile->WritePos(buffer, size, offset);
- }
- virtual FX_BOOL Flush() override { return m_pFile->Flush(); }
+ explicit CFX_CRTFileStream(IFXCRT_FileAccess* pFA);
+ ~CFX_CRTFileStream() override;
+
+ // IFX_FileStream:
+ IFX_FileStream* Retain() override;
+ void Release() override;
+ FX_FILESIZE GetSize() override;
+ FX_BOOL IsEOF() override;
+ FX_FILESIZE GetPosition() override;
+ FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
+ size_t ReadBlock(void* buffer, size_t size) override;
+ FX_BOOL WriteBlock(const void* buffer,
+ FX_FILESIZE offset,
+ size_t size) override;
+ FX_BOOL Flush() override;
protected:
IFXCRT_FileAccess* m_pFile;
@@ -111,7 +95,7 @@ class CFX_CRTFileStream final : public IFX_FileStream {
#define FX_MEMSTREAM_TakeOver 0x02
class CFX_MemoryStream final : public IFX_MemoryStream {
public:
- CFX_MemoryStream(FX_BOOL bConsecutive)
+ explicit CFX_MemoryStream(FX_BOOL bConsecutive)
: m_dwCount(1),
m_nTotalSize(0),
m_nCurSize(0),
@@ -190,7 +174,7 @@ class CFX_MemoryStream final : public IFX_MemoryStream {
if (m_nCurPos >= m_nCurSize) {
return 0;
}
- size_t nRead = FX_MIN(size, m_nCurSize - m_nCurPos);
+ size_t nRead = std::min(size, m_nCurSize - m_nCurPos);
if (!ReadBlock(buffer, (int32_t)m_nCurPos, nRead)) {
return 0;
}
@@ -262,12 +246,13 @@ class CFX_MemoryStream final : public IFX_MemoryStream {
void EstimateSize(size_t nInitSize, size_t nGrowSize) override {
if (m_dwFlags & FX_MEMSTREAM_Consecutive) {
if (m_Blocks.GetSize() < 1) {
- uint8_t* pBlock = FX_Alloc(uint8_t, FX_MAX(nInitSize, 4096));
+ uint8_t* pBlock =
+ FX_Alloc(uint8_t, std::max(nInitSize, static_cast<size_t>(4096)));
m_Blocks.Add(pBlock);
}
- m_nGrowSize = FX_MAX(nGrowSize, 4096);
+ m_nGrowSize = std::max(nGrowSize, static_cast<size_t>(4096));
} else if (m_Blocks.GetSize() < 1) {
- m_nGrowSize = FX_MAX(nGrowSize, 4096);
+ m_nGrowSize = std::max(nGrowSize, static_cast<size_t>(4096));
}
}
uint8_t* GetBuffer() const override {
diff --git a/core/src/fxcrt/fx_basic_buffer.cpp b/core/src/fxcrt/fx_basic_buffer.cpp
index e5c6c6d4b9..4ef86bbf41 100644
--- a/core/src/fxcrt/fx_basic_buffer.cpp
+++ b/core/src/fxcrt/fx_basic_buffer.cpp
@@ -4,6 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include <algorithm>
+
#include "core/include/fxcrt/fx_basic.h"
FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf);
@@ -401,7 +403,7 @@ int32_t IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) {
uint8_t* buffer = (uint8_t*)pBuf;
FX_STRSIZE temp_size = (FX_STRSIZE)size;
while (temp_size > 0) {
- FX_STRSIZE buf_size = FX_MIN(m_BufSize - m_Length, (FX_STRSIZE)temp_size);
+ FX_STRSIZE buf_size = std::min(m_BufSize - m_Length, (FX_STRSIZE)temp_size);
FXSYS_memcpy(m_pBuffer + m_Length, buffer, buf_size);
m_Length += buf_size;
if (m_Length == m_BufSize) {
diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp
index dd26f595f2..2370c87cf1 100644
--- a/core/src/fxcrt/fx_basic_wstring.cpp
+++ b/core/src/fxcrt/fx_basic_wstring.cpp
@@ -5,6 +5,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include <stddef.h> // For offsetof().
+
+#include <algorithm>
#include <cctype>
#include "core/include/fxcrt/fx_basic.h"
@@ -639,7 +641,7 @@ FX_STRSIZE CFX_WideString::Replace(const FX_WCHAR* lpszOld,
pOldData->Release();
}
lpszStart = m_pData->m_String;
- lpszEnd = m_pData->m_String + FX_MAX(m_pData->m_nDataLength, nNewLength);
+ lpszEnd = m_pData->m_String + std::max(m_pData->m_nDataLength, nNewLength);
{
while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) !=
NULL &&
@@ -758,9 +760,7 @@ void CFX_WideString::FormatV(const FX_WCHAR* lpszFormat, va_list argList) {
nMaxLen += 2;
} else if (*lpsz == '*') {
nWidth = va_arg(argList, int);
- } else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' || *lpsz == ' ')
- ;
- else {
+ } else if (*lpsz != '-' && *lpsz != '+' && *lpsz != '0' && *lpsz != ' ') {
break;
}
}
diff --git a/core/src/fxcrt/fx_extension.cpp b/core/src/fxcrt/fx_extension.cpp
index 4669ac4be4..8a6987b066 100644
--- a/core/src/fxcrt/fx_extension.cpp
+++ b/core/src/fxcrt/fx_extension.cpp
@@ -14,6 +14,59 @@
#include <ctime>
#endif
+CFX_CRTFileStream::CFX_CRTFileStream(IFXCRT_FileAccess* pFA)
+ : m_pFile(pFA), m_dwCount(1) {}
+
+CFX_CRTFileStream::~CFX_CRTFileStream() {
+ if (m_pFile) {
+ m_pFile->Release();
+ }
+}
+
+IFX_FileStream* CFX_CRTFileStream::Retain() {
+ m_dwCount++;
+ return this;
+}
+
+void CFX_CRTFileStream::Release() {
+ FX_DWORD nCount = --m_dwCount;
+ if (!nCount) {
+ delete this;
+ }
+}
+
+FX_FILESIZE CFX_CRTFileStream::GetSize() {
+ return m_pFile->GetSize();
+}
+
+FX_BOOL CFX_CRTFileStream::IsEOF() {
+ return GetPosition() >= GetSize();
+}
+
+FX_FILESIZE CFX_CRTFileStream::GetPosition() {
+ return m_pFile->GetPosition();
+}
+
+FX_BOOL CFX_CRTFileStream::ReadBlock(void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
+ return (FX_BOOL)m_pFile->ReadPos(buffer, size, offset);
+}
+
+size_t CFX_CRTFileStream::ReadBlock(void* buffer, size_t size) {
+ return m_pFile->Read(buffer, size);
+}
+
+FX_BOOL CFX_CRTFileStream::WriteBlock(const void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
+ return (FX_BOOL)m_pFile->WritePos(buffer, size, offset);
+}
+
+FX_BOOL CFX_CRTFileStream::Flush() {
+ return m_pFile->Flush();
+}
+
#ifdef PDF_ENABLE_XFA
IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath) {
if (wsPath.GetLength() == 0)
diff --git a/core/src/fxcrt/xml_int.h b/core/src/fxcrt/xml_int.h
index b11a64b505..a837327445 100644
--- a/core/src/fxcrt/xml_int.h
+++ b/core/src/fxcrt/xml_int.h
@@ -7,6 +7,8 @@
#ifndef CORE_SRC_FXCRT_XML_INT_H_
#define CORE_SRC_FXCRT_XML_INT_H_
+#include <algorithm>
+
#include "core/include/fxcrt/fx_stream.h"
class CFX_UTF8Decoder;
@@ -43,10 +45,9 @@ class CXML_DataBufAcc : public IFX_BufferRead {
size_t m_dwCurPos;
};
-#define FX_XMLDATASTREAM_BufferSize (32 * 1024)
class CXML_DataStmAcc : public IFX_BufferRead {
public:
- CXML_DataStmAcc(IFX_FileRead* pFileRead)
+ explicit CXML_DataStmAcc(IFX_FileRead* pFileRead)
: m_pFileRead(pFileRead), m_pBuffer(NULL), m_nStart(0), m_dwSize(0) {
FXSYS_assert(m_pFileRead);
}
@@ -69,7 +70,9 @@ class CXML_DataStmAcc : public IFX_BufferRead {
if (m_nStart >= nLength) {
return FALSE;
}
- m_dwSize = (size_t)FX_MIN(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart);
+ static const FX_FILESIZE FX_XMLDATASTREAM_BufferSize = 32 * 1024;
+ m_dwSize = static_cast<size_t>(
+ std::min(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart));
if (!m_pBuffer) {
m_pBuffer = FX_Alloc(uint8_t, m_dwSize);
}