• 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   *(wchar_t*)(m_pBuffer.get() + m_DataSize) = ch;
16   m_DataSize += sizeof(wchar_t);
17 }
18 
operator <<(const WideStringView & str)19 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const WideStringView& str) {
20   AppendBlock(str.unterminated_c_str(), str.GetLength() * sizeof(wchar_t));
21   return *this;
22 }
23 
operator <<(const WideString & str)24 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const WideString& str) {
25   AppendBlock(str.c_str(), str.GetLength() * sizeof(wchar_t));
26   return *this;
27 }
28 
operator <<(int i)29 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(int i) {
30   char buf[32];
31   FXSYS_itoa(i, buf, 10);
32   size_t len = strlen(buf);
33   ExpandBuf(len * sizeof(wchar_t));
34   wchar_t* str = (wchar_t*)(m_pBuffer.get() + m_DataSize);
35   for (size_t j = 0; j < len; j++) {
36     *str++ = buf[j];
37   }
38   m_DataSize += len * sizeof(wchar_t);
39   return *this;
40 }
41 
operator <<(double f)42 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(double f) {
43   char buf[32];
44   size_t len = FX_ftoa((float)f, buf);
45   ExpandBuf(len * sizeof(wchar_t));
46   wchar_t* str = (wchar_t*)(m_pBuffer.get() + m_DataSize);
47   for (size_t i = 0; i < len; i++) {
48     *str++ = buf[i];
49   }
50   m_DataSize += len * sizeof(wchar_t);
51   return *this;
52 }
53 
operator <<(const wchar_t * lpsz)54 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const wchar_t* lpsz) {
55   AppendBlock(lpsz, wcslen(lpsz) * sizeof(wchar_t));
56   return *this;
57 }
58 
operator <<(const CFX_WideTextBuf & buf)59 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideTextBuf& buf) {
60   AppendBlock(buf.m_pBuffer.get(), buf.m_DataSize);
61   return *this;
62 }
63