From a94566f3833b885019bbea76d3261a3050b5ed04 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 30 Aug 2017 16:36:53 -0400 Subject: Move CFX_WideTextBuf out of fx_basic This CL moves CFX_WideTextBuf to its own files and updates includes as needed. Change-Id: Ibe66ecf3e66f8f01dd8e9eaf6b467588be86ad4f Reviewed-on: https://pdfium-review.googlesource.com/12413 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- core/fxcrt/cfx_utf8decoder.h | 2 +- core/fxcrt/cfx_widetextbuf.cpp | 58 ++++++++++++++++++++++++++++++++++ core/fxcrt/cfx_widetextbuf.h | 44 ++++++++++++++++++++++++++ core/fxcrt/fx_basic.h | 30 ------------------ core/fxcrt/fx_basic_buffer.cpp | 65 --------------------------------------- core/fxcrt/xml/cfx_xmlelement.cpp | 1 + core/fxcrt/xml/cxml_parser.cpp | 1 + 7 files changed, 105 insertions(+), 96 deletions(-) create mode 100644 core/fxcrt/cfx_widetextbuf.cpp create mode 100644 core/fxcrt/cfx_widetextbuf.h delete mode 100644 core/fxcrt/fx_basic_buffer.cpp (limited to 'core/fxcrt') diff --git a/core/fxcrt/cfx_utf8decoder.h b/core/fxcrt/cfx_utf8decoder.h index 50c2a3966d..dcf5ef796a 100644 --- a/core/fxcrt/cfx_utf8decoder.h +++ b/core/fxcrt/cfx_utf8decoder.h @@ -7,7 +7,7 @@ #ifndef CORE_FXCRT_CFX_UTF8DECODER_H_ #define CORE_FXCRT_CFX_UTF8DECODER_H_ -#include "core/fxcrt/fx_basic.h" +#include "core/fxcrt/cfx_widetextbuf.h" class CFX_UTF8Decoder { public: diff --git a/core/fxcrt/cfx_widetextbuf.cpp b/core/fxcrt/cfx_widetextbuf.cpp new file mode 100644 index 0000000000..246124b95f --- /dev/null +++ b/core/fxcrt/cfx_widetextbuf.cpp @@ -0,0 +1,58 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fxcrt/cfx_widetextbuf.h" + +void CFX_WideTextBuf::AppendChar(wchar_t ch) { + ExpandBuf(sizeof(wchar_t)); + *(wchar_t*)(m_pBuffer.get() + m_DataSize) = ch; + m_DataSize += sizeof(wchar_t); +} + +CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideStringC& str) { + AppendBlock(str.unterminated_c_str(), str.GetLength() * sizeof(wchar_t)); + return *this; +} + +CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideString& str) { + AppendBlock(str.c_str(), str.GetLength() * sizeof(wchar_t)); + return *this; +} + +CFX_WideTextBuf& CFX_WideTextBuf::operator<<(int i) { + char buf[32]; + FXSYS_itoa(i, buf, 10); + FX_STRSIZE len = FXSYS_strlen(buf); + ExpandBuf(len * sizeof(wchar_t)); + wchar_t* str = (wchar_t*)(m_pBuffer.get() + m_DataSize); + for (FX_STRSIZE j = 0; j < len; j++) { + *str++ = buf[j]; + } + m_DataSize += len * sizeof(wchar_t); + return *this; +} + +CFX_WideTextBuf& CFX_WideTextBuf::operator<<(double f) { + char buf[32]; + FX_STRSIZE len = FX_ftoa((float)f, buf); + ExpandBuf(len * sizeof(wchar_t)); + wchar_t* str = (wchar_t*)(m_pBuffer.get() + m_DataSize); + for (FX_STRSIZE i = 0; i < len; i++) { + *str++ = buf[i]; + } + m_DataSize += len * sizeof(wchar_t); + return *this; +} + +CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const wchar_t* lpsz) { + AppendBlock(lpsz, FXSYS_wcslen(lpsz) * sizeof(wchar_t)); + return *this; +} + +CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideTextBuf& buf) { + AppendBlock(buf.m_pBuffer.get(), buf.m_DataSize); + return *this; +} diff --git a/core/fxcrt/cfx_widetextbuf.h b/core/fxcrt/cfx_widetextbuf.h new file mode 100644 index 0000000000..0c9b6ff99d --- /dev/null +++ b/core/fxcrt/cfx_widetextbuf.h @@ -0,0 +1,44 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXCRT_CFX_WIDETEXTBUF_H_ +#define CORE_FXCRT_CFX_WIDETEXTBUF_H_ + +#include "core/fxcrt/cfx_binarybuf.h" +#include "core/fxcrt/fx_string.h" +#include "core/fxcrt/fx_system.h" + +class CFX_WideTextBuf : public CFX_BinaryBuf { + public: + void AppendChar(wchar_t wch); + FX_STRSIZE GetLength() const { return m_DataSize / sizeof(wchar_t); } + wchar_t* GetBuffer() const { + return reinterpret_cast(m_pBuffer.get()); + } + + CFX_WideStringC AsStringC() const { + return CFX_WideStringC(reinterpret_cast(m_pBuffer.get()), + m_DataSize / sizeof(wchar_t)); + } + CFX_WideString MakeString() const { + return CFX_WideString(reinterpret_cast(m_pBuffer.get()), + m_DataSize / sizeof(wchar_t)); + } + + void Delete(int start_index, int count) { + CFX_BinaryBuf::Delete(start_index * sizeof(wchar_t), + count * sizeof(wchar_t)); + } + + CFX_WideTextBuf& operator<<(int i); + CFX_WideTextBuf& operator<<(double f); + CFX_WideTextBuf& operator<<(const wchar_t* lpsz); + CFX_WideTextBuf& operator<<(const CFX_WideStringC& str); + CFX_WideTextBuf& operator<<(const CFX_WideString& str); + CFX_WideTextBuf& operator<<(const CFX_WideTextBuf& buf); +}; + +#endif // CORE_FXCRT_CFX_WIDETEXTBUF_H_ diff --git a/core/fxcrt/fx_basic.h b/core/fxcrt/fx_basic.h index 6052cc84c8..f3eb03f925 100644 --- a/core/fxcrt/fx_basic.h +++ b/core/fxcrt/fx_basic.h @@ -22,36 +22,6 @@ #define FX_IsOdd(a) ((a)&1) #endif // PDF_ENABLE_XFA -class CFX_WideTextBuf : public CFX_BinaryBuf { - public: - void AppendChar(wchar_t wch); - FX_STRSIZE GetLength() const { return m_DataSize / sizeof(wchar_t); } - wchar_t* GetBuffer() const { - return reinterpret_cast(m_pBuffer.get()); - } - - CFX_WideStringC AsStringC() const { - return CFX_WideStringC(reinterpret_cast(m_pBuffer.get()), - m_DataSize / sizeof(wchar_t)); - } - CFX_WideString MakeString() const { - return CFX_WideString(reinterpret_cast(m_pBuffer.get()), - m_DataSize / sizeof(wchar_t)); - } - - void Delete(int start_index, int count) { - CFX_BinaryBuf::Delete(start_index * sizeof(wchar_t), - count * sizeof(wchar_t)); - } - - CFX_WideTextBuf& operator<<(int i); - CFX_WideTextBuf& operator<<(double f); - CFX_WideTextBuf& operator<<(const wchar_t* lpsz); - CFX_WideTextBuf& operator<<(const CFX_WideStringC& str); - CFX_WideTextBuf& operator<<(const CFX_WideString& str); - CFX_WideTextBuf& operator<<(const CFX_WideTextBuf& buf); -}; - template class CFX_FixedBufGrow { public: diff --git a/core/fxcrt/fx_basic_buffer.cpp b/core/fxcrt/fx_basic_buffer.cpp deleted file mode 100644 index e282aa4247..0000000000 --- a/core/fxcrt/fx_basic_buffer.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include -#include -#include -#include - -#include "core/fxcrt/fx_basic.h" -#include "core/fxcrt/fx_safe_types.h" -#include "third_party/base/numerics/safe_conversions.h" - -void CFX_WideTextBuf::AppendChar(wchar_t ch) { - ExpandBuf(sizeof(wchar_t)); - *(wchar_t*)(m_pBuffer.get() + m_DataSize) = ch; - m_DataSize += sizeof(wchar_t); -} - -CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideStringC& str) { - AppendBlock(str.unterminated_c_str(), str.GetLength() * sizeof(wchar_t)); - return *this; -} - -CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideString& str) { - AppendBlock(str.c_str(), str.GetLength() * sizeof(wchar_t)); - return *this; -} - -CFX_WideTextBuf& CFX_WideTextBuf::operator<<(int i) { - char buf[32]; - FXSYS_itoa(i, buf, 10); - FX_STRSIZE len = FXSYS_strlen(buf); - ExpandBuf(len * sizeof(wchar_t)); - wchar_t* str = (wchar_t*)(m_pBuffer.get() + m_DataSize); - for (FX_STRSIZE j = 0; j < len; j++) { - *str++ = buf[j]; - } - m_DataSize += len * sizeof(wchar_t); - return *this; -} - -CFX_WideTextBuf& CFX_WideTextBuf::operator<<(double f) { - char buf[32]; - FX_STRSIZE len = FX_ftoa((float)f, buf); - ExpandBuf(len * sizeof(wchar_t)); - wchar_t* str = (wchar_t*)(m_pBuffer.get() + m_DataSize); - for (FX_STRSIZE i = 0; i < len; i++) { - *str++ = buf[i]; - } - m_DataSize += len * sizeof(wchar_t); - return *this; -} - -CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const wchar_t* lpsz) { - AppendBlock(lpsz, FXSYS_wcslen(lpsz) * sizeof(wchar_t)); - return *this; -} - -CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideTextBuf& buf) { - AppendBlock(buf.m_pBuffer.get(), buf.m_DataSize); - return *this; -} diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp index eb60e68893..e72b77c4f6 100644 --- a/core/fxcrt/xml/cfx_xmlelement.cpp +++ b/core/fxcrt/xml/cfx_xmlelement.cpp @@ -6,6 +6,7 @@ #include "core/fxcrt/xml/cfx_xmlelement.h" +#include "core/fxcrt/cfx_widetextbuf.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/xml/cfx_xmlchardata.h" #include "core/fxcrt/xml/cfx_xmltext.h" diff --git a/core/fxcrt/xml/cxml_parser.cpp b/core/fxcrt/xml/cxml_parser.cpp index 5e3fca7e79..9679e2cd41 100644 --- a/core/fxcrt/xml/cxml_parser.cpp +++ b/core/fxcrt/xml/cxml_parser.cpp @@ -12,6 +12,7 @@ #include #include "core/fxcrt/cfx_utf8decoder.h" +#include "core/fxcrt/cfx_widetextbuf.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/xml/cxml_content.h" #include "core/fxcrt/xml/cxml_element.h" -- cgit v1.2.3