locale.qbk 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. [/
  2. Copyright 2006-2007 John Maddock.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ]
  7. [section:locale Localization]
  8. Boost.Regex provides extensive support for run-time localization, the
  9. localization model used can be split into two parts: front-end and back-end.
  10. Front-end localization deals with everything which the user sees -
  11. error messages, and the regular expression syntax itself. For example a
  12. French application could change \[\[:word:\]\] to \[\[:mot:\]\] and \\w to \\m.
  13. Modifying the front end locale requires active support from the developer,
  14. by providing the library with a message catalogue to load, containing the
  15. localized strings. Front-end locale is affected by the LC_MESSAGES category only.
  16. Back-end localization deals with everything that occurs after the expression
  17. has been parsed - in other words everything that the user does not see or
  18. interact with directly. It deals with case conversion, collation, and character
  19. class membership. The back-end locale does not require any intervention from
  20. the developer - the library will acquire all the information it requires for
  21. the current locale from the underlying operating system / run time library.
  22. This means that if the program user does not interact with regular
  23. expressions directly - for example if the expressions are embedded in your
  24. C++ code - then no explicit localization is required, as the library will
  25. take care of everything for you. For example embedding the expression
  26. \[\[:word:\]\]+ in your code will always match a whole word, if the
  27. program is run on a machine with, for example, a Greek locale, then it
  28. will still match a whole word, but in Greek characters rather than Latin ones.
  29. The back-end locale is affected by the LC_TYPE and LC_COLLATE categories.
  30. There are three separate localization mechanisms supported by Boost.Regex:
  31. [h4 Win32 localization model.]
  32. This is the default model when the library is compiled under Win32, and is
  33. encapsulated by the traits class `w32_regex_traits`. When this model is in
  34. effect each [basic_regex] object gets it's own LCID, by default this is
  35. the users default setting as returned by GetUserDefaultLCID, but you can
  36. call imbue on the `basic_regex` object to set it's locale to some other
  37. LCID if you wish. All the settings used by Boost.Regex are acquired directly
  38. from the operating system bypassing the C run time library. Front-end
  39. localization requires a resource dll, containing a string table with the
  40. user-defined strings. The traits class exports the function:
  41. static std::string set_message_catalogue(const std::string& s);
  42. which needs to be called with a string identifying the name of the resource
  43. dll, before your code compiles any regular expressions (but not necessarily
  44. before you construct any `basic_regex` instances):
  45. boost::w32_regex_traits<char>::set_message_catalogue("mydll.dll");
  46. The library provides full Unicode support under NT, under Windows 9x
  47. the library degrades gracefully - characters 0 to 255 are supported, the
  48. remainder are treated as "unknown" graphic characters.
  49. [h4 C localization model.]
  50. This model has been deprecated in favor of the C++ locale for all non-Windows
  51. compilers that support it. This locale is encapsulated by the traits class
  52. `c_regex_traits`, Win32 users can force this model to take effect by
  53. defining the pre-processor symbol BOOST_REGEX_USE_C_LOCALE. When this model is
  54. in effect there is a single global locale, as set by `setlocale`. All settings
  55. are acquired from your run time library, consequently Unicode support is
  56. dependent upon your run time library implementation.
  57. Front end localization is not supported.
  58. Note that calling setlocale invalidates all compiled regular expressions,
  59. calling `setlocale(LC_ALL, "C")` will make this library behave equivalent to
  60. most traditional regular expression libraries including version 1 of this library.
  61. [h4 C++ localization model.]
  62. This model is the default for non-Windows compilers.
  63. When this model is in effect each instance of [basic_regex] has its own
  64. instance of `std::locale`, class [basic_regex] also has a member function
  65. `imbue` which allows the locale for the expression to be set on a
  66. per-instance basis. Front end localization requires a POSIX message catalogue,
  67. which will be loaded via the `std::messages` facet of the expression's locale,
  68. the traits class exports the symbol:
  69. static std::string set_message_catalogue(const std::string& s);
  70. which needs to be called with a string identifying the name of the
  71. message catalogue, before your code compiles any regular expressions
  72. (but not necessarily before you construct any basic_regex instances):
  73. boost::cpp_regex_traits<char>::set_message_catalogue("mycatalogue");
  74. Note that calling `basic_regex<>::imbue` will invalidate any expression
  75. currently compiled in that instance of [basic_regex].
  76. Finally note that if you build the library with a non-default localization model,
  77. then the appropriate pre-processor symbol (BOOST_REGEX_USE_C_LOCALE or
  78. BOOST_REGEX_USE_CPP_LOCALE) must be defined both when you build the support
  79. library, and when you include `<boost/regex.hpp>` or `<boost/cregex.hpp>`
  80. in your code. The best way to ensure this is to add the #define to
  81. `<boost/regex/user.hpp>`.
  82. [h4 Providing a message catalogue]
  83. In order to localize the front end of the library, you need to provide the
  84. library with the appropriate message strings contained either in a resource
  85. dll's string table (Win32 model), or a POSIX message catalogue (C++ models).
  86. In the latter case the messages must appear in message set zero of the
  87. catalogue. The messages and their id's are as follows:
  88. [table
  89. [[Message][id][Meaning][Default value]]
  90. [[101][The character used to start a sub-expression.]["(" ]]
  91. [[102][The character used to end a sub-expression declaration.][")" ]]
  92. [[103][The character used to denote an end of line assertion.]["$" ]]
  93. [[104][The character used to denote the start of line assertion.]["^" ]]
  94. [[105][The character used to denote the "match any character expression".]["." ]]
  95. [[106][The match zero or more times repetition operator.]["*" ]]
  96. [[107][The match one or more repetition operator.]["+" ]]
  97. [[108][The match zero or one repetition operator.]["?" ]]
  98. [[109][The character set opening character.]["\[" ]]
  99. [[110][The character set closing character.]["\]" ]]
  100. [[111][The alternation operator.]["|" ]]
  101. [[112][The escape character.]["\\" ]]
  102. [[113][The hash character (not currently used).]["#" ]]
  103. [[114][The range operator.]["-" ]]
  104. [[115][The repetition operator opening character.]["{" ]]
  105. [[116][The repetition operator closing character.]["}" ]]
  106. [[117][The digit characters.]["0123456789" ]]
  107. [[118][The character which when preceded by an escape character represents the word boundary assertion.]["b" ]]
  108. [[119][The character which when preceded by an escape character represents the non-word boundary assertion.]["B" ]]
  109. [[120][The character which when preceded by an escape character represents the word-start boundary assertion.]["<" ]]
  110. [[121][The character which when preceded by an escape character represents the word-end boundary assertion.][">" ]]
  111. [[122][The character which when preceded by an escape character represents any word character.]["w" ]]
  112. [[123][The character which when preceded by an escape character represents a non-word character.]["W" ]]
  113. [[124][The character which when preceded by an escape character represents a start of buffer assertion.]["`A" ]]
  114. [[125][The character which when preceded by an escape character represents an end of buffer assertion.]["'z" ]]
  115. [[126][The newline character. ]["\\n" ]]
  116. [[127][The comma separator.]["," ]]
  117. [[128][The character which when preceded by an escape character represents the bell character.]["a" ]]
  118. [[129][The character which when preceded by an escape character represents the form feed character.]["f" ]]
  119. [[130][The character which when preceded by an escape character represents the newline character.]["n" ]]
  120. [[131][The character which when preceded by an escape character represents the carriage return character.]["r" ]]
  121. [[132][The character which when preceded by an escape character represents the tab character.]["t" ]]
  122. [[133][The character which when preceded by an escape character represents the vertical tab character.]["v" ]]
  123. [[134][The character which when preceded by an escape character represents the start of a hexadecimal character constant.]["x" ]]
  124. [[135][The character which when preceded by an escape character represents the start of an ASCII escape character.]["c" ]]
  125. [[136][The colon character.][":" ]]
  126. [[137][The equals character.]["=" ]]
  127. [[138][The character which when preceded by an escape character represents the ASCII escape character.]["e" ]]
  128. [[139][The character which when preceded by an escape character represents any lower case character.]["l" ]]
  129. [[140][The character which when preceded by an escape character represents any non-lower case character.]["L" ]]
  130. [[141][The character which when preceded by an escape character represents any upper case character.]["u" ]]
  131. [[142][The character which when preceded by an escape character represents any non-upper case character.]["U" ]]
  132. [[143][The character which when preceded by an escape character represents any space character.]["s" ]]
  133. [[144][The character which when preceded by an escape character represents any non-space character.]["S" ]]
  134. [[145][The character which when preceded by an escape character represents any digit character.]["d" ]]
  135. [[146][The character which when preceded by an escape character represents any non-digit character.]["D" ]]
  136. [[147][The character which when preceded by an escape character represents the end quote operator.]["E" ]]
  137. [[148][The character which when preceded by an escape character represents the start quote operator.]["Q" ]]
  138. [[149][The character which when preceded by an escape character represents a Unicode combining character sequence.]["X" ]]
  139. [[150][The character which when preceded by an escape character represents any single character.]["C" ]]
  140. [[151][The character which when preceded by an escape character represents end of buffer operator.]["Z" ]]
  141. [[152][The character which when preceded by an escape character represents the continuation assertion.]["G" ]]
  142. [[153][The character which when preceded by (? indicates a zero width negated forward lookahead assert.][! ]]
  143. ]
  144. Custom error messages are loaded as follows:
  145. [table
  146. [[Message ID][Error message ID][Default string ]]
  147. [[201][REG_NOMATCH]["No match" ]]
  148. [[202][REG_BADPAT]["Invalid regular expression" ]]
  149. [[203][REG_ECOLLATE]["Invalid collation character" ]]
  150. [[204][REG_ECTYPE]["Invalid character class name" ]]
  151. [[205][REG_EESCAPE]["Trailing backslash" ]]
  152. [[206][REG_ESUBREG]["Invalid back reference" ]]
  153. [[207][REG_EBRACK]["Unmatched \[ or \[^" ]]
  154. [[208][REG_EPAREN]["Unmatched ( or \\(" ]]
  155. [[209][REG_EBRACE]["Unmatched \\{" ]]
  156. [[210][REG_BADBR]["Invalid content of \\{\\}" ]]
  157. [[211][REG_ERANGE]["Invalid range end" ]]
  158. [[212][REG_ESPACE]["Memory exhausted" ]]
  159. [[213][REG_BADRPT]["Invalid preceding regular expression" ]]
  160. [[214][REG_EEND]["Premature end of regular expression" ]]
  161. [[215][REG_ESIZE]["Regular expression too big" ]]
  162. [[216][REG_ERPAREN]["Unmatched ) or \\)" ]]
  163. [[217][REG_EMPTY]["Empty expression" ]]
  164. [[218][REG_E_UNKNOWN]["Unknown error" ]]
  165. ]
  166. Custom character class names are loaded as followed:
  167. [table
  168. [[Message ID][Description][Equivalent default class name ]]
  169. [[300][The character class name for alphanumeric characters.]["alnum" ]]
  170. [[301][The character class name for alphabetic characters.]["alpha" ]]
  171. [[302][The character class name for control characters.]["cntrl" ]]
  172. [[303][The character class name for digit characters.]["digit" ]]
  173. [[304][The character class name for graphics characters.]["graph" ]]
  174. [[305][The character class name for lower case characters.]["lower" ]]
  175. [[306][The character class name for printable characters.]["print" ]]
  176. [[307][The character class name for punctuation characters.]["punct" ]]
  177. [[308][The character class name for space characters.]["space" ]]
  178. [[309][The character class name for upper case characters.]["upper" ]]
  179. [[310][The character class name for hexadecimal characters.]["xdigit" ]]
  180. [[311][The character class name for blank characters.]["blank" ]]
  181. [[312][The character class name for word characters.]["word" ]]
  182. [[313][The character class name for Unicode characters.]["unicode" ]]
  183. ]
  184. Finally, custom collating element names are loaded starting from message
  185. id 400, and terminating when the first load thereafter fails. Each message
  186. looks something like: "tagname string" where tagname is the name used
  187. inside [[.tagname.]] and string is the actual text of the collating element.
  188. Note that the value of collating element [[.zero.]] is used for the
  189. conversion of strings to numbers - if you replace this with another value then
  190. that will be used for string parsing - for example use the Unicode
  191. character 0x0660 for [[.zero.]] if you want to use Unicode Arabic-Indic
  192. digits in your regular expressions in place of Latin digits.
  193. Note that the POSIX defined names for character classes and collating elements
  194. are always available - even if custom names are defined, in contrast,
  195. custom error messages, and custom syntax messages replace the default ones.
  196. [endsect]