annotate src/string_base.h @ 20677:9795e5780df4 draft

-Fix: Improve text caret movement for complex scripts.
author Michael Lutz <michi@icosahedron.de>
date Sun, 21 Jul 2013 15:41:44 +0200
parents
children 71216b5f4bc9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20677
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
1 /* $Id$ */
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
2
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
3 /*
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
4 * This file is part of OpenTTD.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
8 */
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
9
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
10 #ifndef STRING_BASE_H
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
11 #define STRING_BASE_H
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
12
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
13 #include "string_type.h"
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
14
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
15 /** Class for iterating over different kind of parts of a string. */
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
16 class StringIterator {
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
17 public:
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
18 /** Sentinel to indicate end-of-iteration. */
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
19 static const size_t END = SIZE_MAX;
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
20
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
21 /**
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
22 * Create a new iterator instance.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
23 * @return New iterator instance.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
24 */
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
25 static StringIterator *Create();
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
26
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
27 virtual ~StringIterator() {}
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
28
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
29 /**
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
30 * Set a new iteration string. Must also be called if the string contents
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
31 * changed. The cursor is reset to the start of the string.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
32 * @param s New string.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
33 */
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
34 virtual void SetString(const char *s) = 0;
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
35
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
36 /**
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
37 * Change the current string cursor.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
38 * @param p New cursor position.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
39 * @return Actual new cursor position at the next valid character boundary.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
40 * @pre p has to be inside the current string.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
41 */
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
42 virtual size_t SetCurPosition(size_t pos) = 0;
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
43
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
44 /**
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
45 * Advance the cursor by one iteration unit.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
46 * @return New cursor position (in bytes) or #END if the cursor is already at the end of the string.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
47 */
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
48 virtual size_t Next() = 0;
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
49
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
50 /**
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
51 * Move the cursor back by one iteration unit.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
52 * @return New cursor position (in bytes) or #END if the cursor is already at the start of the string.
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
53 */
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
54 virtual size_t Prev() = 0;
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
55
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
56 protected:
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
57 StringIterator() {}
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
58 };
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
59
9795e5780df4 -Fix: Improve text caret movement for complex scripts.
Michael Lutz <michi@icosahedron.de>
parents:
diff changeset
60 #endif /* STRING_BASE_H */