recommendations_and_myths.txt 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 filetype=cpp.doxygen
  9. /*!
  10. \page recommendations_and_myths Recommendations and Myths
  11. \section recommendations Recommendations
  12. - The first and most important recommendation: prefer UTF-8 encoding for narrow strings --- it represents all
  13. supported Unicode characters and is more convenient for general use than encodings like Latin1.
  14. - Remember, there are many different cultures. You can assume very little about the user's language. His calendar
  15. may not have "January". It may be not possible to convert strings to integers using \c atoi because
  16. they may not use the "ordinary" digits 0..9 at all. You can't assume that "space" characters are frequent
  17. because in Chinese the space character does not separate words. The text may be written from Right-to-Left or
  18. from Up-to-Down, and so on.
  19. - Using message formatting, try to provide as much context information as you can. Prefer translating entire
  20. sentences over single words. When translating words, \b always add some context information.
  21. \section myths Myths
  22. \subsection myths_wide To use Unicode in my application I should use wide strings everywhere.
  23. Unicode is not limited to wide strings. Both \c std::string and \c std::wstring
  24. can hold and process Unicode text. More than that, the semantics of \c std::string
  25. are much cleaner in multi-platform applications, because all "Unicode" strings are
  26. UTF-8. "Wide" strings may be encoded in "UTF-16" or "UTF-32", depending
  27. on the platform, so they may be even less convenient when dealing with Unicode than
  28. \c char based strings.
  29. \subsection myths_utf16 UTF-16 is the best encoding to work with.
  30. There is common assumption that UTF-16 is the best encoding for storing information because it gives "shortest" representation
  31. of strings.
  32. In fact, it is probably the most error-prone encoding to work with. The biggest issue is code points that lay outside of the BMP,
  33. which must be represented with surrogate pairs. These characters are very rare and many applications are not tested with them.
  34. For example:
  35. - Qt3 could not deal with characters outside of the BMP.
  36. - Editing a character with a codepoint above 0xFFFF often shows an unpleasant bug: for example, to erase
  37. such a character in Windows Notepad you have to press backspace twice.
  38. So UTF-16 can be used for Unicode, in fact ICU and many other applications use UTF-16 as their internal Unicode representation, but
  39. you should be very careful and never assume one-code-point == one-utf16-character.
  40. */