• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "core/fxcrt/cfx_widetextbuf.h"
8 
GetLength() const9 size_t CFX_WideTextBuf::GetLength() const {
10   return m_DataSize / sizeof(wchar_t);
11 }
12 
AppendChar(wchar_t ch)13 void CFX_WideTextBuf::AppendChar(wchar_t ch) {
14   ExpandBuf(sizeof(wchar_t));
15   *reinterpret_cast<wchar_t*>(m_pBuffer.get() + m_DataSize) = ch;
16   m_DataSize += sizeof(wchar_t);
17 }
18 
operator <<(ByteStringView ascii)19 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(ByteStringView ascii) {
20   ExpandBuf(ascii.GetLength() * sizeof(wchar_t));
21   for (uint8_t ch : ascii) {
22     *reinterpret_cast<wchar_t*>(m_pBuffer.get() + m_DataSize) = ch;
23     m_DataSize += sizeof(wchar_t);
24   }
25   return *this;
26 }
27 
operator <<(WideStringView str)28 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(WideStringView str) {
29   AppendBlock(str.unterminated_c_str(), str.GetLength() * sizeof(wchar_t));
30   return *this;
31 }
32 
operator <<(const WideString & str)33 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const WideString& str) {
34   AppendBlock(str.c_str(), str.GetLength() * sizeof(wchar_t));
35   return *this;
36 }
37 
operator <<(int i)38 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(int i) {
39   char buf[32];
40   FXSYS_itoa(i, buf, 10);
41   size_t len = strlen(buf);
42   ExpandBuf(len * sizeof(wchar_t));
43   wchar_t* str = reinterpret_cast<wchar_t*>(m_pBuffer.get() + m_DataSize);
44   for (size_t j = 0; j < len; j++) {
45     *str++ = buf[j];
46   }
47   m_DataSize += len * sizeof(wchar_t);
48   return *this;
49 }
50 
operator <<(double f)51 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(double f) {
52   char buf[32];
53   size_t len = FloatToString((float)f, buf);
54   ExpandBuf(len * sizeof(wchar_t));
55   wchar_t* str = reinterpret_cast<wchar_t*>(m_pBuffer.get() + m_DataSize);
56   for (size_t i = 0; i < len; i++) {
57     *str++ = buf[i];
58   }
59   m_DataSize += len * sizeof(wchar_t);
60   return *this;
61 }
62 
operator <<(const wchar_t * lpsz)63 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const wchar_t* lpsz) {
64   AppendBlock(lpsz, wcslen(lpsz) * sizeof(wchar_t));
65   return *this;
66 }
67 
operator <<(const CFX_WideTextBuf & buf)68 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideTextBuf& buf) {
69   AppendBlock(buf.m_pBuffer.get(), buf.m_DataSize);
70   return *this;
71 }
72