/** * @file XTPSyntaxEditTextIterator.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPSYNTAXEDITTEXTITERATOR_H__) # define __XTPSYNTAXEDITTEXTITERATOR_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPSyntaxEditBufferManager; /** * @brief * This class provides functionality to navigate text in the data * buffer, seek forward/backward, retrieve text by lines, and * determine control symbols like CRLF. * When you create an instance of the CXTPSyntaxEditTextIterator class, * you should provide a pointer to data storage, represented by * the CXTPSyntaxEditBufferManager class. * @see * CXTPSyntaxEditBufferManager. */ class _XTP_EXT_CLASS CXTPSyntaxEditTextIterator : public CXTPCmdTarget { public: /** * @brief * Default object constructor. * @param pData [in] Pointer to a CXTPSyntaxEditBufferManager object. * @see * CXTPSyntaxEditBufferManager. */ CXTPSyntaxEditTextIterator(CXTPSyntaxEditBufferManager* pData); /** * @brief * Destroys a CXTPSyntaxEditTextIterator object, * handles cleanup and de-allocation. */ virtual ~CXTPSyntaxEditTextIterator(void); /** * @brief * Gets the current CRLF control symbol. * @return * The current CRLF control symbol. * @details * Strings such as "\\r\\n", "\\n\\r", and "\\r" are * recognized as CRLF control symbols. */ virtual CString GetEOL() const; /** * @brief * Repositions the "current position pointer" in the internal data * buffer to the begin. * @details * Call this member function to set the "current position pointer" * in the internal data buffer to the begin. Besides it resets * all others internal text counters. * @see * SeekPos() */ virtual void SeekBegin(); /** * @brief * Repositions the "current position pointer" in the internal data * buffer to the specified position. * @param posLC [in] Position in the text to set as current. * @param hBreakEvent [in] Handle to the break event to stop function execution. * @details * Call this member function to set the "current position pointer" * in the internal data buffer to the specified position. * For big texts this operation may take a lot of time. hBreakEvent * is used to to stop function execution without reaching the specified position. * @return * TRUE if successful, otherwise FALSE. * @see * SeekBegin() */ virtual BOOL SeekPos(const XTP_EDIT_LINECOL& posLC, HANDLE hBreakEvent = NULL); /** * @brief * Returns text of required length * @param nCharsBuf [in] length of the text in bytes to be returned. * @details * Call this member function to get text of required length. * CRLF symbols are taken in account and don't remove from the * returned string. * @return * Pointer to the character string. */ virtual LPCTSTR GetText(int nCharsBuf = 512); /** * @brief * Moves current position and return pointer to the text begin. * @param dwChars [in] counts to move. * @param nCharsBuf [in] length of the text in bytes to be returned. * @return * Pointer to the character string. */ virtual LPCTSTR SeekNext(DWORD dwChars = 1, int nCharsBuf = 512); /** * @brief * Moves current position back for 1 character, and return pointer * to the text begin. * @return * Pointer to the character string or NULL if text begin is reached. */ virtual LPCTSTR SeekPrev(); /** * @brief * Determines if the end of data has been reached. * @return * Nonzero if either the data buffer contains no records or if * the user has scrolled beyond the last position, otherwise 0. * @details * IsEOF can also be used to determine if the data buffer * contains any data or is empty. */ virtual BOOL IsEOF() const; /** * @brief * Gets the current position. * @return * An XTP_EDIT_LINECOL structure containing the current position. * @see * XTP_EDIT_LINECOL */ virtual XTP_EDIT_LINECOL GetPosLC() const; /** * @brief * Gets the last position. * @param bWithEOL TRUE to include EOL, FALSE otherwise. * @return * An XTP_EDIT_LINECOL structure containing the last position. * @see * XTP_EDIT_LINECOL */ virtual XTP_EDIT_LINECOL GetPosLC_last(BOOL bWithEOL) const; /** * @brief * Decrements position. * @param rLC [in] Reference to an XTP_EDIT_LINECOL structure. */ virtual void LCPosDec(XTP_EDIT_LINECOL& rLC) const; /** * @brief * Increments position. * @param rLC [in] Reference to an XTP_EDIT_LINECOL structure. * @param nCharsAdd [in] Number of characters to add. */ virtual void LCPosAdd(XTP_EDIT_LINECOL& rLC, int nCharsAdd) const; /** * @brief * Gets the length of a specified line. * @param nLine [in] Identifier of the line. * @param bWithEOL [in] TRUE to include end-of-line characters, * FALSE to ignore end-of-line characters. * @return * The length of the specified line. */ virtual int GetLineLen(int nLine, BOOL bWithEOL = FALSE) const; /** * @brief * Gets the length (in bytes) of a specified line. * @param nLine [in] Identifier of the line. * @param bWithEOL [in] TRUE to include end-of-line characters, * FALSE to ignore end-of-line characters. * @return * The length (in bytes) of the specified line. */ virtual int GetLineLenBytes(int nLine, BOOL bWithEOL) const; /** * @brief * Sets the offset value. * @param nOffsetChars [in] Offset value to be set. */ virtual void SetTxtOffset(int nOffsetChars); /** * @brief * Gets the file name. * @return * The file name. */ virtual CString GetFileExt() const; /** * @brief * Gets the maximum buffer size (in characters) for back text offset. * @return * The maximum buffer size (in characters) for back text offset. * @see * SetTxtOffset */ virtual int GetMaxBackOffset() const; protected: CXTPSyntaxEditBufferManager* m_pData; /**< Pointer to the used CXTPSyntaxEditBufferManager object. */ XTP_EDIT_LINECOL m_LCpos; /**< Current position in the text. */ BOOL m_bEOF; /**< End-Of-File flag. */ CMap m_mapLine2Len; /**< Map of line - length of line. */ /** * @brief * Gets the buffer. * @param nOffsetB [in] Offset (in bytes). * @return * A pointer to the TCHAR buffer. */ TCHAR* GetBuffer(int nOffsetB) const; CArray m_arBuffer; /**< Buffer of chars. */ int m_nBufSizeB; /**< Buffer length. */ int m_nNextLine; /**< Next line ID. */ int m_nBufOffsetB; /**< Offset. */ int m_nBufOffsetB_normal; /**< Offset. */ int m_nBufOffsetB_max; /**< Offset. */ int m_nTmpOffsetC; /**< Offset. */ int m_nTmpOffsetB; /**< Offset. */ }; //////////////////////////////////////////////////////////////////////////// AFX_INLINE TCHAR* CXTPSyntaxEditTextIterator::GetBuffer(int nOffsetB) const { return (TCHAR*)((CHAR*)m_arBuffer.GetData() + nOffsetB); } AFX_INLINE int CXTPSyntaxEditTextIterator::GetMaxBackOffset() const { return m_nBufOffsetB_normal; } //////////////////////////////////////////////////////////////////////////// # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTPSYNTAXEDITTEXTITERATOR_H__) /** @endcond */