NXWidgets: cstringiterator.hxx Source File

NXWidgets 1.19

cstringiterator.hxx
Go to the documentation of this file.
1 /****************************************************************************
2 * NxWidgets/libnxwidgets/include/cstringiterator.hxx
3 *
4 * Copyright (C) 2012 Gregory Nutt. All rights reserved.
5 * Author: Gregory Nutt <gnutt@nuttx.org>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
18 * me be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************
35 *
36 * Portions of this package derive from Woopsi (http://woopsi.org/) and
37 * portions are original efforts. It is difficult to determine at this
38 * point what parts are original efforts and which parts derive from Woopsi.
39 * However, in any event, the work of Antony Dzeryn will be acknowledged
40 * in most NxWidget files. Thanks Antony!
41 *
42 * Copyright (c) 2007-2011, Antony Dzeryn
43 * All rights reserved.
44 *
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions are met:
47 *
48 * * Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * * Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * * Neither the names "Woopsi", "Simian Zombie" nor the
54 * names of its contributors may be used to endorse or promote products
55 * derived from this software without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
58 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
59 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
60 * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
61 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
62 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
63 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
64 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
66 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 *
68 ****************************************************************************/
69
70 #ifndef __INCLUDE_CSTRINGITERATOR_HXX
71 #define __INCLUDE_CSTRINGITERATOR_HXX
72
73 /****************************************************************************
74 * Included Files
75 ****************************************************************************/
76
77 #include <nuttx/config.h>
78
79 #include <stdint.h>
80 #include <stdbool.h>
81
82 /****************************************************************************
83 * Pre-Processor Definitions
84 ****************************************************************************/
85
86 /****************************************************************************
87 * Implementation Classes
88 ****************************************************************************/
89
90 #if defined(__cplusplus)
91
92 namespace NXWidgets
93 {
94 class CNxString;
95
96 /**
97 * Class used to efficiently iterate over the characters in a CNxString
98 * object. The CNxString is a Unicode string that uses the fixed-width
99 * 16-bit encoding to represent its characters.
100 */
101
102 class CStringIterator
103 {
104 private:
105 const CNxString *m_pString; /**< String being iterated over. */
106 const nxwidget_char_t *m_pCurrentChar; /**< Pointer to the current position of the iterator. */
107 int m_currentIndex; /**< Iterator's current index within the string. */
108
109 public:
110
111 /**
112 * Constructor. Moves the iterator to the first character in the string.
113 *
114 * @param string Pointer to the string that will be iterated over.
115 */
116
117 CStringIterator(FAR const CNxString* string);
118
119 /**
120 * Destructor.
121 */
122
123 inline ~CStringIterator(void) { }
124
125 /**
126 * Moves the iterator to the first character in the string.
127 *
128 * @param Returns false if the string is empty
129 */
130
131 bool moveToFirst(void);
132
133 /**
134 * Moves the iterator to the last character in the string.
135 *
136 * @param Returns false if the string is empty
137 */
138
139 bool moveToLast(void);
140
141 /**
142 * Move the iterator to the next character in the string.
143 *
144 * @return True if the iterator moved; false if not (indicates end of string).
145 */
146
147 bool moveToNext(void);
148
149 /**
150 * Move the iterator to the previous character in the string.
151 *
152 * @return True if the iterator moved; false if not (indicates start of string).
153 */
154
155 bool moveToPrevious(void);
156
157 /**
158 * Move the iterator to the specified index.
159 *
160 * @param index The index to move to.
161 * @return True if the iterator moved; false if not (indicates end of string).
162 */
163
164 bool moveTo(int index);
165
166 /**
167 * Get the current position of the iterator within the string.
168 *
169 * @return The current character index of the iterator.
170 */
171
172 inline int getIndex(void) const
173 {
174 return m_currentIndex;
175 }
176
177 /**
178 * Get the letter in the string at the iterator's current point.
179 *
180 * @return The current character in the string.
181 */
182
183 inline nxwidget_char_t getChar(void) const
184 {
185 return *m_pCurrentChar;
186 }
187 };
188 }
189
190 #endif // __cplusplus
191
192 #endif // __INCLUDE_CSTRINGITERATOR_HXX
NXWidgets::CStringIterator
Definition: cstringiterator.hxx:102
NXWidgets::CStringIterator::m_currentIndex
int m_currentIndex
Definition: cstringiterator.hxx:107
NXWidgets::CStringIterator::getIndex
int getIndex(void) const
Definition: cstringiterator.hxx:172
NXWidgets::CStringIterator::CStringIterator
CStringIterator(FAR const CNxString *string)
Definition: cstringiterator.cxx:98
NXWidgets::CStringIterator::moveToPrevious
bool moveToPrevious(void)
Definition: cstringiterator.cxx:167
NXWidgets::CStringIterator::m_pCurrentChar
const nxwidget_char_t * m_pCurrentChar
Definition: cstringiterator.hxx:106
NXWidgets
Definition: cbgwindow.hxx:65
NXWidgets::CStringIterator::moveToFirst
bool moveToFirst(void)
Definition: cstringiterator.cxx:111
NXWidgets::CStringIterator::moveToNext
bool moveToNext(void)
Definition: cstringiterator.cxx:149
NXWidgets::nxwidget_char_t
uint16_t nxwidget_char_t
Definition: nxconfig.hxx:454
NXWidgets::CStringIterator::getChar
nxwidget_char_t getChar(void) const
Definition: cstringiterator.hxx:183
NXWidgets::CStringIterator::moveToLast
bool moveToLast(void)
Definition: cstringiterator.cxx:130
NXWidgets::CNxString
Definition: cnxstring.hxx:121
NXWidgets::CStringIterator::moveTo
bool moveTo(int index)
Definition: cstringiterator.cxx:185
NXWidgets::CStringIterator::m_pString
const CNxString * m_pString
Definition: cstringiterator.hxx:105
NXWidgets::CStringIterator::~CStringIterator
~CStringIterator(void)
Definition: cstringiterator.hxx:123