OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "xfa/fxfa/parser/cxfa_widetextread.h" |
| 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "xfa/fgas/crt/fgas_codepage.h" |
| 11 |
| 12 CXFA_WideTextRead::CXFA_WideTextRead(const CFX_WideString& wsBuffer) |
| 13 : m_wsBuffer(wsBuffer), m_iPosition(0), m_iRefCount(1) {} |
| 14 |
| 15 void CXFA_WideTextRead::Release() { |
| 16 if (--m_iRefCount < 1) |
| 17 delete this; |
| 18 } |
| 19 |
| 20 IFX_Stream* CXFA_WideTextRead::Retain() { |
| 21 m_iRefCount++; |
| 22 return this; |
| 23 } |
| 24 |
| 25 uint32_t CXFA_WideTextRead::GetAccessModes() const { |
| 26 return FX_STREAMACCESS_Read | FX_STREAMACCESS_Text; |
| 27 } |
| 28 |
| 29 int32_t CXFA_WideTextRead::GetLength() const { |
| 30 return m_wsBuffer.GetLength() * sizeof(FX_WCHAR); |
| 31 } |
| 32 |
| 33 int32_t CXFA_WideTextRead::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
| 34 switch (eSeek) { |
| 35 case FX_STREAMSEEK_Begin: |
| 36 m_iPosition = iOffset; |
| 37 break; |
| 38 case FX_STREAMSEEK_Current: |
| 39 m_iPosition += iOffset; |
| 40 break; |
| 41 case FX_STREAMSEEK_End: |
| 42 m_iPosition = m_wsBuffer.GetLength() + iOffset; |
| 43 break; |
| 44 } |
| 45 m_iPosition = std::min(std::max(0, m_iPosition), m_wsBuffer.GetLength()); |
| 46 return GetPosition(); |
| 47 } |
| 48 |
| 49 int32_t CXFA_WideTextRead::GetPosition() { |
| 50 return m_iPosition * sizeof(FX_WCHAR); |
| 51 } |
| 52 |
| 53 FX_BOOL CXFA_WideTextRead::IsEOF() const { |
| 54 return m_iPosition >= m_wsBuffer.GetLength(); |
| 55 } |
| 56 |
| 57 int32_t CXFA_WideTextRead::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
| 58 return 0; |
| 59 } |
| 60 |
| 61 int32_t CXFA_WideTextRead::ReadString(FX_WCHAR* pStr, |
| 62 int32_t iMaxLength, |
| 63 FX_BOOL& bEOS) { |
| 64 iMaxLength = std::min(iMaxLength, m_wsBuffer.GetLength() - m_iPosition); |
| 65 if (iMaxLength == 0) |
| 66 return 0; |
| 67 |
| 68 FXSYS_wcsncpy(pStr, m_wsBuffer.c_str() + m_iPosition, iMaxLength); |
| 69 m_iPosition += iMaxLength; |
| 70 bEOS = IsEOF(); |
| 71 return iMaxLength; |
| 72 } |
| 73 |
| 74 int32_t CXFA_WideTextRead::WriteData(const uint8_t* pBuffer, |
| 75 int32_t iBufferSize) { |
| 76 return 0; |
| 77 } |
| 78 |
| 79 int32_t CXFA_WideTextRead::WriteString(const FX_WCHAR* pStr, int32_t iLength) { |
| 80 return 0; |
| 81 } |
| 82 |
| 83 FX_BOOL CXFA_WideTextRead::SetLength(int32_t iLength) { |
| 84 return FALSE; |
| 85 } |
| 86 |
| 87 int32_t CXFA_WideTextRead::GetBOM(uint8_t bom[4]) const { |
| 88 return 0; |
| 89 } |
| 90 |
| 91 uint16_t CXFA_WideTextRead::GetCodePage() const { |
| 92 return (sizeof(FX_WCHAR) == 2) ? FX_CODEPAGE_UTF16LE : FX_CODEPAGE_UTF32LE; |
| 93 } |
| 94 |
| 95 uint16_t CXFA_WideTextRead::SetCodePage(uint16_t wCodePage) { |
| 96 return GetCodePage(); |
| 97 } |
| 98 |
| 99 IFX_Stream* CXFA_WideTextRead::CreateSharedStream(uint32_t dwAccess, |
| 100 int32_t iOffset, |
| 101 int32_t iLength) { |
| 102 return nullptr; |
| 103 } |
| 104 |
| 105 CFX_WideString CXFA_WideTextRead::GetSrcText() const { |
| 106 return m_wsBuffer; |
| 107 } |
OLD | NEW |