string.txt 3.3 KB

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