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/fde/cfx_chariter.h" 8 CFX_CharIter(const CFX_WideString & wsText)9CFX_CharIter::CFX_CharIter(const CFX_WideString& wsText) 10 : m_wsText(wsText), m_nIndex(0) { 11 ASSERT(!wsText.IsEmpty()); 12 } 13 ~CFX_CharIter()14CFX_CharIter::~CFX_CharIter() {} 15 Next(bool bPrev)16bool CFX_CharIter::Next(bool bPrev) { 17 if (bPrev) { 18 if (m_nIndex <= 0) 19 return false; 20 m_nIndex--; 21 } else { 22 if (m_nIndex + 1 >= m_wsText.GetLength()) 23 return false; 24 m_nIndex++; 25 } 26 return true; 27 } 28 GetChar()29FX_WCHAR CFX_CharIter::GetChar() { 30 return m_wsText.GetAt(m_nIndex); 31 } 32 SetAt(int32_t nIndex)33void CFX_CharIter::SetAt(int32_t nIndex) { 34 if (nIndex < 0 || nIndex >= m_wsText.GetLength()) 35 return; 36 m_nIndex = nIndex; 37 } 38 GetAt() const39int32_t CFX_CharIter::GetAt() const { 40 return m_nIndex; 41 } 42 IsEOF(bool bTail) const43bool CFX_CharIter::IsEOF(bool bTail) const { 44 return bTail ? (m_nIndex + 1 == m_wsText.GetLength()) : (m_nIndex == 0); 45 } 46 Clone()47IFX_CharIter* CFX_CharIter::Clone() { 48 CFX_CharIter* pIter = new CFX_CharIter(m_wsText); 49 pIter->m_nIndex = m_nIndex; 50 return pIter; 51 } 52