comparison engine/core/util/utf8/utf8stringeditor.h @ 228:756b895e1dab

Merged unicode-support back into trunk. Now all GUI/visible strings should be unicode. Internal strings unchanged. Remember to use a font that actually has the desired codepoints. Current default unicode policiy is 'ignore'.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 21 Mar 2009 10:38:11 +0000
parents
children
comparison
equal deleted inserted replaced
227:d642169490f7 228:756b895e1dab
1 /***************************************************************************
2 * Copyright (C) 2009 by the FIFE team *
3 * http://www.fifengine.de *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef GCN_UTF8STRINGEDITOR_HPP
23 #define GCN_UTF8STRINGEDITOR_HPP
24
25 // Standard C++ library includes
26
27 // 3rd party library includes
28 #include <guichan.hpp>
29
30 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line
32 // First block: files included from the FIFE root src directory
33 // Second block: files included from the same folder
34
35 namespace gcn {
36
37 /**
38 * UTF-8 string editor.
39 *
40 * This is a helper class which allows to use UTF-8 strings in
41 * your application.
42 *
43 * @author Przemyslaw Grzywacz
44 */
45 class UTF8StringEditor {
46 public:
47 /**
48 * Returns byte offset of the next character.
49 *
50 * @param text UTF-8 text to navigate.
51 * @param byteOffset Byte offset of current character.
52 * @return Byte offset of the next character.
53 */
54 static int nextChar(const std::string& text, int byteOffset);
55
56 /**
57 * Returns byte offset of the previous character.
58 *
59 * @param text UTF-8 text to navigate.
60 * @param byteOffset Byte offset of current character.
61 * @return Byte offset of the previous character.
62 */
63 static int prevChar(const std::string& text, int byteOffset);
64
65 /**
66 * Erase character at specified byte offset.
67 *
68 * @param text UTF-8 text to modify.
69 * @param byteOffset Byte offset of the character to erase.
70 * @return New byte offset (is equal to byteOffset).
71 */
72 static int eraseChar(std::string& text, int byteOffset);
73
74 /**
75 * Insert a character at specified byte offset.
76 *
77 * @param text UTF-8 text to modify.
78 * @param byteOffset Byte offset where character will be inserted.
79 * @param ch Unicode character to insert.
80 * @return New byte offset (after the new character).
81 */
82 static int insertChar(std::string& text, int byteOffset, int ch);
83
84 /**
85 * Counts characters up to byteOffset.
86 *
87 * @param text UTF-8 text to navigate.
88 * @param byteOffset Byte offset inside the text.
89 * @return Number of characters.
90 */
91 static int countChars(const std::string& text, int byteOffset);
92
93 /**
94 * Gets byte offset for character index.
95 *
96 * This method automaticly clips charIndex to be inside
97 * the string + EOF
98 *
99 * @param text UTF-8 text to navigate.
100 * @param charIndex Character index to move to.
101 * @return Byte offset of character at charIndex.
102 */
103 static int getOffset(const std::string& text, int charIndex);
104 };
105
106 };
107
108 #endif // !GCN_UTF8STRINGEDITOR_HPP