1 | Strings under I4 are perhaps one of the most complicated things to
|
---|
2 | understand.
|
---|
3 |
|
---|
4 | The main string classes are
|
---|
5 |
|
---|
6 | i4_const_str (strings which cannot be changed or freed)
|
---|
7 | i4_str : public i4_const_str (strings which can be changed and freed)
|
---|
8 |
|
---|
9 | i4_string_manager_class : public i4_init_class
|
---|
10 |
|
---|
11 |
|
---|
12 | The primary goal of the string classes is to assist translations of
|
---|
13 | products. To enforce translation of all user visible strings, all
|
---|
14 | strings must be created by a i4_string_manager_class which loads them
|
---|
15 | from a resource file (while can be easily translated). A resource
|
---|
16 | file is a simple text file formatted as follows :
|
---|
17 |
|
---|
18 | internal external
|
---|
19 |
|
---|
20 | where is internal is the internal name referred to by the program. The
|
---|
21 | external name is the one the user sees and is might be translated.
|
---|
22 | The string manager also supports arrays of strings as follows :
|
---|
23 |
|
---|
24 | internal { external1 external2 external3 external4 }
|
---|
25 |
|
---|
26 | optionally you can insert a = between the external and the external as
|
---|
27 | follows :
|
---|
28 |
|
---|
29 | internal = external
|
---|
30 |
|
---|
31 | this assist parsing match up should you miss a word by accident.
|
---|
32 |
|
---|
33 |
|
---|
34 | An i4_string_manager_class can load up strings from a file via
|
---|
35 | load(i4_open_file_function_type opener, char *filename);
|
---|
36 | (see files.txt for details about opener)
|
---|
37 |
|
---|
38 | Or it can load them up from a memory buffer (i.e. a resource file
|
---|
39 | loaded into some memory location) with
|
---|
40 |
|
---|
41 | i4_bool load_buffer(i4_open_file_function_type opener,
|
---|
42 | void *internal_buffer, char *error_prefix);
|
---|
43 |
|
---|
44 |
|
---|
45 | Substitutions are allowed in resource files.
|
---|
46 |
|
---|
47 | internal1 = external1
|
---|
48 | internal2 = ${external1}_external2
|
---|
49 |
|
---|
50 | Once strings have been loaded into a string_manager, then you can
|
---|
51 | fetch them with either get or get_array.
|
---|
52 |
|
---|
53 | i4_string_manager_class.get("internal2") returns
|
---|
54 | i4_const_str("external1_external2")
|
---|
55 |
|
---|
56 | There is a global string manager defined for convince.
|
---|
57 | i4_string_man. Also the global function i4gets(char *) will
|
---|
58 | fetch an external string from it using an internal name.
|
---|
59 |
|
---|
60 | font->put_string(screen, 10, 10, i4gets("name"), context);
|
---|
61 |
|
---|
62 | Internal symbol names are stored in a binary tree and a search
|
---|
63 | is performed every time you call i4gets().
|
---|
64 |
|
---|
65 | The difference between i4_const_str and i4_str is that i4_const_str's
|
---|
66 | are compacted into a small heap (head to toe) and cannot be freed or
|
---|
67 | modified. An i4_str resides in the main heap (allocated with
|
---|
68 | i4_malloc). i4_str's can be deleted or modified. An i4_str can be
|
---|
69 | passed to routines needing i4_const_str because it is derived from it.
|
---|
70 | i4_str's are usually constructed from i4_const_strs by insertion,
|
---|
71 | concatenation, etc. This ensures that all i4_str will built from
|
---|
72 | parts that are translated, thus being translated themselves.
|
---|
73 |
|
---|
74 | Strings use iterators to access individual characters. An iterator
|
---|
75 | can be thought of as a pointer. Incrementing moves to the next
|
---|
76 | character, decrementing goes back one character. i4_const_str.begin()
|
---|
77 | returns an iterator referencing the first character in the string,
|
---|
78 | while i4_const_str.end() returns an iterator referencing the last+1
|
---|
79 | character in a string. So you iterator through all the characters in
|
---|
80 | a string if you want to. This allows for addition of wide characters
|
---|
81 | or kanji-escaped code characters without changes to the rest of the
|
---|
82 | application. (Neither are currently supported though).
|
---|
83 |
|
---|
84 |
|
---|