File indexing completed on 2024-03-24 17:26:38

0001 /*
0002     This file is part of the Okteta Core library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2005, 2008-2009 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef OKTETA_TEXTBYTEARRAYANALYZER_HPP
0010 #define OKTETA_TEXTBYTEARRAYANALYZER_HPP
0011 
0012 // lib
0013 #include "oktetacore_export.hpp"
0014 #include "addressrange.hpp"
0015 // Qt
0016 #include <QScopedPointer>
0017 
0018 class QString;
0019 
0020 namespace Okteta {
0021 
0022 class AbstractByteArrayModel;
0023 class CharCodec;
0024 
0025 /**
0026  *
0027  * @author Friedrich W. H. Kossebau
0028  */
0029 
0030 class OKTETACORE_EXPORT TextByteArrayAnalyzer
0031 {
0032 public:
0033     TextByteArrayAnalyzer(const AbstractByteArrayModel* byteArrayModel, const CharCodec* charCodec);
0034     TextByteArrayAnalyzer(const TextByteArrayAnalyzer&) = delete;
0035 
0036     ~TextByteArrayAnalyzer();
0037 
0038     TextByteArrayAnalyzer& operator=(const TextByteArrayAnalyzer&) = delete;
0039 
0040 public:
0041     /** searches for the start of the word including the given index.
0042      * if no other nonwordchar preceds this is 0;
0043      * If the byte at the given index is already a nonword char the given index is returned.
0044      * @param index index to start with
0045      * @return index of the first char of the current word or the given index if there is none
0046      */
0047     Address indexOfWordStart(Address index) const;
0048     Address indexOfLeftWordSelect(Address index) const;
0049     /** searches for the end of the word including the given index.
0050      * If the byte at the given index is already a nonword char the given index is returned.
0051      * if no other nonwordchar follows, that of the last byte;
0052      * @param index index to start with
0053      * @return index of the last char of the current word or the given index if there is none
0054      */
0055     Address indexOfWordEnd(Address index) const;
0056     /** searches for the first char after the end of the word including the given index.
0057      * If the byte at the given index is already a nonword char the given index is returned.
0058      * if no other nonwordchar follows that of behind the last byte;
0059      * @param index index to start with
0060      * @return index of the first char after the current word or the given index if there is none
0061      */
0062     Address indexOfRightWordSelect(Address index) const;
0063     /** searches for the first char after the end of the word including the given index.
0064      * If the byte at the given index is already a nonword char the given index is returned.
0065      * if no other nonwordchar follows that of behind the last byte;
0066      * @param index index to start with
0067      * @return index of the first char after the current word or the given index if there is none
0068      */
0069 //    Address indexOfBehindLeftWordEnd( Address index ) const;
0070     /** searches for the first char after the end of the word including the given index.
0071      * If the byte at the given index is already a nonword char the given index is returned.
0072      * if no other nonwordchar follows that of behind the last byte;
0073      * @param index index to start with
0074      * @return index of the first char after the current word or the given index if there is none
0075      */
0076 //    Address indexOfBehindRightWordEnd( Address index ) const;
0077     /** searches the start of the next previous word that does not include the given index,
0078      * if no further word is found 0 is returned.
0079      * if the index is out of range the behaviour is undefined.
0080      * @param index
0081      * @return index of the next previous word start or 0
0082      */
0083     Address indexOfPreviousWordStart(Address index) const;
0084     /** searches for the start of the next word not including the given index.
0085      * if there isn't a next word the index behind end is returned
0086      * @param index
0087      * @return index of the start of the next word or behind end
0088      */
0089     Address indexOfNextWordStart(Address index) const;
0090     /** searches for the start of the next word not including the given index.
0091      * if there isn't a next word the index of the end is returned
0092      * @param index index to start with
0093      * @return index of the last nonword char before the next word or the last index
0094      */
0095     Address indexOfBeforeNextWordStart(Address index) const;
0096 
0097     /** if index is out of range the behaviour is undefined
0098      * @param index
0099      * @return @c true if the byte at position i is a char of type CharType
0100      */
0101     bool isWordChar(Address index) const;
0102 
0103     /** returns the section with a word around index.
0104      * if there is no word the section is empty
0105      * @param index
0106      * @return the section with a word around index.
0107      */
0108     AddressRange wordSection(Address index) const;
0109 
0110     /** returns the text starting at the given index until the first non-text byte
0111      * if there is no text byte at the index the result is empty.
0112      * @param index
0113      * @param lastIndex if -1 lastIndex is set to the end of th byte array.
0114      * @return the text starting at the index
0115      */
0116     QString text(Address index, Address lastIndex = -1) const;
0117 
0118 private:
0119     const QScopedPointer<class TextByteArrayAnalyzerPrivate> d_ptr;
0120     Q_DECLARE_PRIVATE(TextByteArrayAnalyzer)
0121 };
0122 
0123 }
0124 
0125 #endif