1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Character Generators (char_, lit)</title> 5<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../../index.html" title="Spirit 2.5.8"> 8<link rel="up" href="../char.html" title="Char Generators"> 9<link rel="prev" href="../char.html" title="Char Generators"> 10<link rel="next" href="char_class.html" title="Character Classification Generators (alnum, digit, etc.)"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="../char.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../char.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="char_class.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h5 class="title"> 27<a name="spirit.karma.reference.char.char_generator"></a><a class="link" href="char_generator.html" title="Character Generators (char_, lit)">Character 28 Generators (<code class="computeroutput"><span class="identifier">char_</span></code>, <code class="computeroutput"><span class="identifier">lit</span></code>)</a> 29</h5></div></div></div> 30<h6> 31<a name="spirit.karma.reference.char.char_generator.h0"></a> 32 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.description"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.description">Description</a> 33 </h6> 34<p> 35 The character generators described in this section are: 36 </p> 37<p> 38 The <code class="computeroutput"><span class="identifier">char_</span></code> generator emits 39 single characters. The <code class="computeroutput"><span class="identifier">char_</span></code> 40 generator has an associated <a class="link" href="../basics.html#spirit.karma.reference.basics.character_encoding_namespace">Character 41 Encoding Namespace</a>. This is needed when doing basic operations 42 such as forcing lower or upper case and dealing with character ranges. 43 </p> 44<p> 45 There are various forms of <code class="computeroutput"><span class="identifier">char_</span></code>. 46 </p> 47<h6> 48<a name="spirit.karma.reference.char.char_generator.h1"></a> 49 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.char_"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.char_">char_</a> 50 </h6> 51<p> 52 The no argument form of <code class="computeroutput"><span class="identifier">char_</span></code> 53 emits any character in the associated <a class="link" href="../basics.html#spirit.karma.reference.basics.character_encoding_namespace">Character 54 Encoding Namespace</a>. 55 </p> 56<pre class="programlisting"><span class="identifier">char_</span> <span class="comment">// emits any character as supplied by the attribute</span> 57</pre> 58<h6> 59<a name="spirit.karma.reference.char.char_generator.h2"></a> 60 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.char__ch_"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.char__ch_">char_(ch)</a> 61 </h6> 62<p> 63 The single argument form of <code class="computeroutput"><span class="identifier">char_</span></code> 64 (with a character argument) emits the supplied character. 65 </p> 66<pre class="programlisting"><span class="identifier">char_</span><span class="special">(</span><span class="char">'x'</span><span class="special">)</span> <span class="comment">// emits 'x'</span> 67<span class="identifier">char_</span><span class="special">(</span><span class="identifier">L</span><span class="char">'x'</span><span class="special">)</span> <span class="comment">// emits L'x'</span> 68<span class="identifier">char_</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span> <span class="comment">// emits x (a char)</span> 69</pre> 70<h6> 71<a name="spirit.karma.reference.char.char_generator.h3"></a> 72 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.char__first__last_"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.char__first__last_">char_(first, 73 last)</a> 74 </h6> 75<p> 76 <code class="computeroutput"><span class="identifier">char_</span></code> with two arguments, 77 emits any character from a range of characters as supplied by the attribute. 78 </p> 79<pre class="programlisting"><span class="identifier">char_</span><span class="special">(</span><span class="char">'a'</span><span class="special">,</span><span class="char">'z'</span><span class="special">)</span> <span class="comment">// alphabetic characters</span> 80<span class="identifier">char_</span><span class="special">(</span><span class="identifier">L</span><span class="char">'0'</span><span class="special">,</span><span class="identifier">L</span><span class="char">'9'</span><span class="special">)</span> <span class="comment">// digits</span> 81</pre> 82<p> 83 A range of characters is created from a low-high character pair. Such 84 a generator emits a single character that is in the range, including 85 both endpoints. Note, the first character must be <span class="emphasis"><em>before</em></span> 86 the second, according to the underlying <a class="link" href="../basics.html#spirit.karma.reference.basics.character_encoding_namespace">Character 87 Encoding Namespace</a>. 88 </p> 89<p> 90 Character mapping is inherently platform dependent. It is not guaranteed 91 in the standard for example that <code class="computeroutput"><span class="char">'A'</span> 92 <span class="special"><</span> <span class="char">'Z'</span></code>, 93 that is why in Spirit2, we purposely attach a specific <a class="link" href="../basics.html#spirit.karma.reference.basics.character_encoding_namespace">Character 94 Encoding Namespace</a> (such as ASCII, ISO-8859-1) to the <code class="computeroutput"><span class="identifier">char_</span></code> generator to eliminate such ambiguities. 95 </p> 96<div class="note"><table border="0" summary="Note"> 97<tr> 98<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 99<th align="left">Note</th> 100</tr> 101<tr><td align="left" valign="top"> 102<p> 103 <span class="bold"><strong>Sparse bit vectors</strong></span> 104 </p> 105<p> 106 To accommodate 16/32 and 64 bit characters, the char-set statically 107 switches from a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bitset</span></code> 108 implementation when the character type is not greater than 8 bits, 109 to a sparse bit/boolean set which uses a sorted vector of disjoint 110 ranges (<code class="computeroutput"><span class="identifier">range_run</span></code>). 111 The set is constructed from ranges such that adjacent or overlapping 112 ranges are coalesced. 113 </p> 114<p> 115 <code class="computeroutput"><span class="identifier">range_runs</span></code> are very 116 space-economical in situations where there are lots of ranges and a 117 few individual disjoint values. Searching is O(log n) where n is the 118 number of ranges. 119 </p> 120</td></tr> 121</table></div> 122<h6> 123<a name="spirit.karma.reference.char.char_generator.h4"></a> 124 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.char__def_"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.char__def_">char_(def)</a> 125 </h6> 126<p> 127 Lastly, when given a string (a plain C string, a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_string</span></code>, 128 etc.), the string is regarded as a char-set definition string following 129 a syntax that resembles posix style regular expression character sets 130 (except that double quotes delimit the set elements instead of square 131 brackets and there is no special negation ^ character). Examples: 132 </p> 133<pre class="programlisting"><span class="identifier">char_</span><span class="special">(</span><span class="string">"a-zA-Z"</span><span class="special">)</span> <span class="comment">// alphabetic characters</span> 134<span class="identifier">char_</span><span class="special">(</span><span class="string">"0-9a-fA-F"</span><span class="special">)</span> <span class="comment">// hexadecimal characters</span> 135<span class="identifier">char_</span><span class="special">(</span><span class="string">"actgACTG"</span><span class="special">)</span> <span class="comment">// DNA identifiers</span> 136<span class="identifier">char_</span><span class="special">(</span><span class="string">"\x7f\x7e"</span><span class="special">)</span> <span class="comment">// Hexadecimal 0x7F and 0x7E</span> 137</pre> 138<p> 139 These generators emit any character from a range of characters as supplied 140 by the attribute. 141 </p> 142<h6> 143<a name="spirit.karma.reference.char.char_generator.h5"></a> 144 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.lit_ch_"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.lit_ch_">lit(ch)</a> 145 </h6> 146<p> 147 <code class="computeroutput"><span class="identifier">lit</span></code>, when passed a single 148 character, behaves like the single argument <code class="computeroutput"><span class="identifier">char_</span></code> 149 except that <code class="computeroutput"><span class="identifier">lit</span></code> does 150 not consume an attribute. A plain <code class="computeroutput"><span class="keyword">char</span></code> 151 or <code class="computeroutput"><span class="keyword">wchar_t</span></code> is equivalent 152 to a <code class="computeroutput"><span class="identifier">lit</span></code>. 153 </p> 154<div class="note"><table border="0" summary="Note"> 155<tr> 156<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 157<th align="left">Note</th> 158</tr> 159<tr><td align="left" valign="top"><p> 160 <code class="computeroutput"><span class="identifier">lit</span></code> is reused by the 161 <a class="link" href="../string.html" title="String Generators">String Generators</a>, 162 the char generators, and the Numeric Generators (see <a class="link" href="../numeric/signed_int.html" title="Signed Integer Number Generators (int_, etc.)">signed 163 integer</a>, <a class="link" href="../numeric/unsigned_int.html" title="Unsigned Integer Number Generators (uint_, etc.)">unsigned 164 integer</a>, and <a class="link" href="../numeric/real_number.html" title="Real Number Generators (float_, double_, etc.)">real 165 number</a> generators). In general, a char generator is created 166 when you pass in a character, a string generator is created when you 167 pass in a string, and a numeric generator is created when you use a 168 numeric literal. The exception is when you pass a single element literal 169 string, e.g. <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="string">"x"</span><span class="special">)</span></code>. 170 In this case, we optimize this to create a char generator instead of 171 a string generator. 172 </p></td></tr> 173</table></div> 174<p> 175 Examples: 176 </p> 177<pre class="programlisting"><span class="char">'x'</span> 178<span class="identifier">lit</span><span class="special">(</span><span class="char">'x'</span><span class="special">)</span> 179<span class="identifier">lit</span><span class="special">(</span><span class="identifier">L</span><span class="char">'x'</span><span class="special">)</span> 180<span class="identifier">lit</span><span class="special">(</span><span class="identifier">c</span><span class="special">)</span> <span class="comment">// c is a char</span> 181</pre> 182<h6> 183<a name="spirit.karma.reference.char.char_generator.h6"></a> 184 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.header"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.header">Header</a> 185 </h6> 186<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/karma/char/char.hpp></span> 187<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">karma_char_</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 188</pre> 189<p> 190 Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>. 191 </p> 192<h6> 193<a name="spirit.karma.reference.char.char_generator.h7"></a> 194 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.namespace"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.namespace">Namespace</a> 195 </h6> 196<div class="informaltable"><table class="table"> 197<colgroup><col></colgroup> 198<thead><tr><th> 199 <p> 200 Name 201 </p> 202 </th></tr></thead> 203<tbody> 204<tr><td> 205 <p> 206 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">lit</span> <span class="comment">// alias: 207 boost::spirit::karma::lit</span></code> 208 </p> 209 </td></tr> 210<tr><td> 211 <p> 212 <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span></code> 213 </p> 214 </td></tr> 215</tbody> 216</table></div> 217<p> 218 In the table above, <code class="computeroutput"><span class="identifier">ns</span></code> 219 represents a <a class="link" href="../basics.html#spirit.karma.reference.basics.character_encoding_namespace">Character 220 Encoding Namespace</a>. 221 </p> 222<h6> 223<a name="spirit.karma.reference.char.char_generator.h8"></a> 224 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.model_of"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.model_of">Model of</a> 225 </h6> 226<div class="blockquote"><blockquote class="blockquote"><p> 227 <a class="link" href="../generator_concepts/primitivegenerator.html" title="PrimitiveGenerator"><code class="computeroutput"><span class="identifier">PrimitiveGenerator</span></code></a> 228 </p></blockquote></div> 229<div class="variablelist"> 230<p class="title"><b>Notation</b></p> 231<dl class="variablelist"> 232<dt><span class="term"><code class="computeroutput"><span class="identifier">ch</span></code>, <code class="computeroutput"><span class="identifier">ch1</span></code>, <code class="computeroutput"><span class="identifier">ch2</span></code></span></dt> 233<dd><p> 234 Character-class specific character (See Character Class Types), 235 or a <a class="link" href="../basics.html#spirit.karma.reference.basics.lazy_argument">Lazy 236 Argument</a> that evaluates to a character-class specific character 237 value 238 </p></dd> 239<dt><span class="term"><code class="computeroutput"><span class="identifier">cs</span></code></span></dt> 240<dd><p> 241 Character-set specifier string (See Character Class Types), or 242 a <a class="link" href="../basics.html#spirit.karma.reference.basics.lazy_argument">Lazy 243 Argument</a> that evaluates to a character-set specifier string, 244 or a pointer/reference to a null-terminated array of characters. 245 This string specifies a char-set definition string following a 246 syntax that resembles posix style regular expression character 247 sets (except the square brackets and the negation <code class="computeroutput"><span class="special">^</span></code> character). 248 </p></dd> 249<dt><span class="term"><code class="computeroutput"><span class="identifier">ns</span></code></span></dt> 250<dd><p> 251 A <a class="link" href="../basics.html#spirit.karma.reference.basics.character_encoding_namespace">Character 252 Encoding Namespace</a>. 253 </p></dd> 254<dt><span class="term"><code class="computeroutput"><span class="identifier">cg</span></code></span></dt> 255<dd><p> 256 A char generator, a char range generator, or a char set generator. 257 </p></dd> 258</dl> 259</div> 260<h6> 261<a name="spirit.karma.reference.char.char_generator.h9"></a> 262 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.expression_semantics"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.expression_semantics">Expression 263 Semantics</a> 264 </h6> 265<p> 266 Semantics of an expression is defined only where it differs from, or 267 is not defined in <a class="link" href="../generator_concepts/primitivegenerator.html" title="PrimitiveGenerator"><code class="computeroutput"><span class="identifier">PrimitiveGenerator</span></code></a>. 268 </p> 269<div class="informaltable"><table class="table"> 270<colgroup> 271<col> 272<col> 273</colgroup> 274<thead><tr> 275<th> 276 <p> 277 Expression 278 </p> 279 </th> 280<th> 281 <p> 282 Description 283 </p> 284 </th> 285</tr></thead> 286<tbody> 287<tr> 288<td> 289 <p> 290 <code class="computeroutput"><span class="identifier">ch</span></code> 291 </p> 292 </td> 293<td> 294 <p> 295 Generate the character literal <code class="computeroutput"><span class="identifier">ch</span></code>. 296 This generator never fails (unless the underlying output stream 297 reports an error). 298 </p> 299 </td> 300</tr> 301<tr> 302<td> 303 <p> 304 <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">ch</span><span class="special">)</span></code> 305 </p> 306 </td> 307<td> 308 <p> 309 Generate the character literal <code class="computeroutput"><span class="identifier">ch</span></code>. 310 This generator never fails (unless the underlying output stream 311 reports an error). 312 </p> 313 </td> 314</tr> 315<tr> 316<td> 317 <p> 318 <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span></code> 319 </p> 320 </td> 321<td> 322 <p> 323 Generate the character provided by a mandatory attribute interpreted 324 in the character set defined by <code class="computeroutput"><span class="identifier">ns</span></code>. 325 This generator never fails (unless the underlying output stream 326 reports an error). 327 </p> 328 </td> 329</tr> 330<tr> 331<td> 332 <p> 333 <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">ch</span><span class="special">)</span></code> 334 </p> 335 </td> 336<td> 337 <p> 338 Generate the character <code class="computeroutput"><span class="identifier">ch</span></code> 339 as provided by the immediate literal value the generator is 340 initialized from. If this generator has an associated attribute 341 it succeeds only as long as the attribute is equal to the immediate 342 literal (unless the underlying output stream reports an error). 343 Otherwise this generator fails and does not generate any output. 344 </p> 345 </td> 346</tr> 347<tr> 348<td> 349 <p> 350 <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="string">"c"</span><span class="special">)</span></code> 351 </p> 352 </td> 353<td> 354 <p> 355 Generate the character <code class="computeroutput"><span class="identifier">c</span></code> 356 as provided by the immediate literal value the generator is 357 initialized from. If this generator has an associated attribute 358 it succeeds only as long as the attribute is equal to the immediate 359 literal (unless the underlying output stream reports an error). 360 Otherwise this generator fails and does not generate any output. 361 </p> 362 </td> 363</tr> 364<tr> 365<td> 366 <p> 367 <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">ch1</span><span class="special">,</span> 368 <span class="identifier">ch2</span><span class="special">)</span></code> 369 </p> 370 </td> 371<td> 372 <p> 373 Generate the character provided by a mandatory attribute interpreted 374 in the character set defined by <code class="computeroutput"><span class="identifier">ns</span></code>. 375 The generator succeeds as long as the attribute belongs to 376 the character range <code class="computeroutput"><span class="special">[</span><span class="identifier">ch1</span><span class="special">,</span> 377 <span class="identifier">ch2</span><span class="special">]</span></code> 378 (unless the underlying output stream reports an error). Otherwise 379 this generator fails and does not generate any output. 380 </p> 381 </td> 382</tr> 383<tr> 384<td> 385 <p> 386 <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">cs</span><span class="special">)</span></code> 387 </p> 388 </td> 389<td> 390 <p> 391 Generate the character provided by a mandatory attribute interpreted 392 in the character set defined by <code class="computeroutput"><span class="identifier">ns</span></code>. 393 The generator succeeds as long as the attribute belongs to 394 the character set <code class="computeroutput"><span class="identifier">cs</span></code> 395 (unless the underlying output stream reports an error). Otherwise 396 this generator fails and does not generate any output. 397 </p> 398 </td> 399</tr> 400<tr> 401<td> 402 <p> 403 <code class="computeroutput"><span class="special">~</span><span class="identifier">cg</span></code> 404 </p> 405 </td> 406<td> 407 <p> 408 Negate <code class="computeroutput"><span class="identifier">cg</span></code>. 409 The result is a negated char generator that inverts the test 410 condition of the character generator it is attached to. 411 </p> 412 </td> 413</tr> 414</tbody> 415</table></div> 416<p> 417 A character <code class="computeroutput"><span class="identifier">ch</span></code> is assumed 418 to belong to the character range defined by <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">ch1</span><span class="special">,</span> <span class="identifier">ch2</span><span class="special">)</span></code> if its character value (binary representation) 419 interpreted in the character set defined by <code class="computeroutput"><span class="identifier">ns</span></code> 420 is not smaller than the character value of <code class="computeroutput"><span class="identifier">ch1</span></code> 421 and not larger then the character value of <code class="computeroutput"><span class="identifier">ch2</span></code> 422 (i.e. <code class="computeroutput"><span class="identifier">ch1</span> <span class="special"><=</span> 423 <span class="identifier">ch</span> <span class="special"><=</span> 424 <span class="identifier">ch2</span></code>). 425 </p> 426<p> 427 The <code class="computeroutput"><span class="identifier">charset</span></code> parameter 428 passed to <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">charset</span><span class="special">)</span></code> 429 must be a string containing more than one character. Every single character 430 in this string is assumed to belong to the character set defined by this 431 expression. An exception to this is the <code class="computeroutput"><span class="char">'-'</span></code> 432 character which has a special meaning if it is not specified as the first 433 and not the last character in <code class="computeroutput"><span class="identifier">charset</span></code>. 434 If the <code class="computeroutput"><span class="char">'-'</span></code> is used in between 435 to characters it is interpreted as spanning a character range. A character 436 <code class="computeroutput"><span class="identifier">ch</span></code> is considered to belong 437 to the defined character set <code class="computeroutput"><span class="identifier">charset</span></code> 438 if it matches one of the characters as specified by the string parameter 439 described above. For example 440 </p> 441<div class="informaltable"><table class="table"> 442<colgroup> 443<col> 444<col> 445</colgroup> 446<thead><tr> 447<th> 448 <p> 449 Example 450 </p> 451 </th> 452<th> 453 <p> 454 Description 455 </p> 456 </th> 457</tr></thead> 458<tbody> 459<tr> 460<td> 461 <p> 462 <code class="computeroutput"><span class="identifier">char_</span><span class="special">(</span><span class="string">"abc"</span><span class="special">)</span></code> 463 </p> 464 </td> 465<td> 466 <p> 467 'a', 'b', and 'c' 468 </p> 469 </td> 470</tr> 471<tr> 472<td> 473 <p> 474 <code class="computeroutput"><span class="identifier">char_</span><span class="special">(</span><span class="string">"a-z"</span><span class="special">)</span></code> 475 </p> 476 </td> 477<td> 478 <p> 479 all characters (and including) from 'a' to 'z' 480 </p> 481 </td> 482</tr> 483<tr> 484<td> 485 <p> 486 <code class="computeroutput"><span class="identifier">char_</span><span class="special">(</span><span class="string">"a-zA-Z"</span><span class="special">)</span></code> 487 </p> 488 </td> 489<td> 490 <p> 491 all characters (and including) from 'a' to 'z' and 'A' and 492 'Z' 493 </p> 494 </td> 495</tr> 496<tr> 497<td> 498 <p> 499 <code class="computeroutput"><span class="identifier">char_</span><span class="special">(</span><span class="string">"-1-9"</span><span class="special">)</span></code> 500 </p> 501 </td> 502<td> 503 <p> 504 '-' and all characters (and including) from '1' to '9' 505 </p> 506 </td> 507</tr> 508</tbody> 509</table></div> 510<h6> 511<a name="spirit.karma.reference.char.char_generator.h10"></a> 512 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.attributes"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.attributes">Attributes</a> 513 </h6> 514<div class="informaltable"><table class="table"> 515<colgroup> 516<col> 517<col> 518</colgroup> 519<thead><tr> 520<th> 521 <p> 522 Expression 523 </p> 524 </th> 525<th> 526 <p> 527 Attribute 528 </p> 529 </th> 530</tr></thead> 531<tbody> 532<tr> 533<td> 534 <p> 535 <code class="computeroutput"><span class="identifier">ch</span></code> 536 </p> 537 </td> 538<td> 539 <p> 540 <code class="computeroutput"><span class="identifier">unused</span></code> 541 </p> 542 </td> 543</tr> 544<tr> 545<td> 546 <p> 547 <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">ch</span><span class="special">)</span></code> 548 </p> 549 </td> 550<td> 551 <p> 552 <code class="computeroutput"><span class="identifier">unused</span></code> 553 </p> 554 </td> 555</tr> 556<tr> 557<td> 558 <p> 559 <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span></code> 560 </p> 561 </td> 562<td> 563 <p> 564 <code class="computeroutput"><span class="identifier">Ch</span></code>, attribute 565 is mandatory (otherwise compilation will fail). <code class="computeroutput"><span class="identifier">Ch</span></code> is the character type 566 of the <a class="link" href="../basics.html#spirit.karma.reference.basics.character_encoding_namespace">Character 567 Encoding Namespace</a>, <code class="computeroutput"><span class="identifier">ns</span></code>. 568 </p> 569 </td> 570</tr> 571<tr> 572<td> 573 <p> 574 <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">ch</span><span class="special">)</span></code> 575 </p> 576 </td> 577<td> 578 <p> 579 <code class="computeroutput"><span class="identifier">Ch</span></code>, attribute 580 is optional, if it is supplied, the generator compares the 581 attribute with <code class="computeroutput"><span class="identifier">ch</span></code> 582 and succeeds only if both are equal, failing otherwise. <code class="computeroutput"><span class="identifier">Ch</span></code> is the character type 583 of the <a class="link" href="../basics.html#spirit.karma.reference.basics.character_encoding_namespace">Character 584 Encoding Namespace</a>, <code class="computeroutput"><span class="identifier">ns</span></code>. 585 </p> 586 </td> 587</tr> 588<tr> 589<td> 590 <p> 591 <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="string">"c"</span><span class="special">)</span></code> 592 </p> 593 </td> 594<td> 595 <p> 596 <code class="computeroutput"><span class="identifier">Ch</span></code>, attribute 597 is optional, if it is supplied, the generator compares the 598 attribute with <code class="computeroutput"><span class="identifier">c</span></code> 599 and succeeds only if both are equal, failing otherwise. <code class="computeroutput"><span class="identifier">Ch</span></code> is the character type 600 of the <a class="link" href="../basics.html#spirit.karma.reference.basics.character_encoding_namespace">Character 601 Encoding Namespace</a>, <code class="computeroutput"><span class="identifier">ns</span></code>. 602 </p> 603 </td> 604</tr> 605<tr> 606<td> 607 <p> 608 <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">ch1</span><span class="special">,</span> 609 <span class="identifier">ch2</span><span class="special">)</span></code> 610 </p> 611 </td> 612<td> 613 <p> 614 <code class="computeroutput"><span class="identifier">Ch</span></code>, attribute 615 is mandatory (otherwise compilation will fail), the generator 616 succeeds if the attribute belongs to the character range <code class="computeroutput"><span class="special">[</span><span class="identifier">ch1</span><span class="special">,</span> <span class="identifier">ch2</span><span class="special">]</span></code> interpreted in the character 617 set defined by <code class="computeroutput"><span class="identifier">ns</span></code>. 618 <code class="computeroutput"><span class="identifier">Ch</span></code> is the character 619 type of the <a class="link" href="../basics.html#spirit.karma.reference.basics.character_encoding_namespace">Character 620 Encoding Namespace</a>, <code class="computeroutput"><span class="identifier">ns</span></code>. 621 </p> 622 </td> 623</tr> 624<tr> 625<td> 626 <p> 627 <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">cs</span><span class="special">)</span></code> 628 </p> 629 </td> 630<td> 631 <p> 632 <code class="computeroutput"><span class="identifier">Ch</span></code>, attribute 633 is mandatory (otherwise compilation will fail), the generator 634 succeeds if the attribute belongs to the character set <code class="computeroutput"><span class="identifier">cs</span></code>, interpreted in the character 635 set defined by <code class="computeroutput"><span class="identifier">ns</span></code>. 636 <code class="computeroutput"><span class="identifier">Ch</span></code> is the character 637 type of the <a class="link" href="../basics.html#spirit.karma.reference.basics.character_encoding_namespace">Character 638 Encoding Namespace</a>, <code class="computeroutput"><span class="identifier">ns</span></code>. 639 </p> 640 </td> 641</tr> 642<tr> 643<td> 644 <p> 645 <code class="computeroutput"><span class="special">~</span><span class="identifier">cg</span></code> 646 </p> 647 </td> 648<td> 649 <p> 650 Attribute of <code class="computeroutput"><span class="identifier">cg</span></code> 651 </p> 652 </td> 653</tr> 654</tbody> 655</table></div> 656<div class="note"><table border="0" summary="Note"> 657<tr> 658<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 659<th align="left">Note</th> 660</tr> 661<tr><td align="left" valign="top"><p> 662 In addition to their usual attribute of type <code class="computeroutput"><span class="identifier">Ch</span></code> 663 all listed generators accept an instance of a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><</span><span class="identifier">Ch</span><span class="special">></span></code> as well. If the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><></span></code> is initialized (holds a value) 664 the generators behave as if their attribute was an instance of <code class="computeroutput"><span class="identifier">Ch</span></code> and emit the value stored in the 665 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><></span></code>. 666 Otherwise the generators will fail. 667 </p></td></tr> 668</table></div> 669<h6> 670<a name="spirit.karma.reference.char.char_generator.h11"></a> 671 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.complexity"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.complexity">Complexity</a> 672 </h6> 673<div class="blockquote"><blockquote class="blockquote"><p> 674 O(1) 675 </p></blockquote></div> 676<p> 677 The complexity of <code class="computeroutput"><span class="identifier">ch</span></code>, 678 <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="identifier">ch</span><span class="special">)</span></code>, 679 <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span></code>, <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">ch</span><span class="special">)</span></code>, and <code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="string">"c"</span><span class="special">)</span></code> is constant as all generators emit exactly 680 one character per invocation. 681 </p> 682<p> 683 The character range generator (<code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">ch1</span><span class="special">,</span> <span class="identifier">ch2</span><span class="special">)</span></code>) additionally requires constant lookup 684 time for the verification whether the attribute belongs to the character 685 range. 686 </p> 687<p> 688 The character set generator (<code class="computeroutput"><span class="identifier">ns</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">cs</span><span class="special">)</span></code>) additionally requires O(log N) lookup 689 time for the verification whether the attribute belongs to the character 690 set, where N is the number of characters in the character set. 691 </p> 692<h6> 693<a name="spirit.karma.reference.char.char_generator.h12"></a> 694 <span class="phrase"><a name="spirit.karma.reference.char.char_generator.example"></a></span><a class="link" href="char_generator.html#spirit.karma.reference.char.char_generator.example">Example</a> 695 </h6> 696<div class="note"><table border="0" summary="Note"> 697<tr> 698<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 699<th align="left">Note</th> 700</tr> 701<tr><td align="left" valign="top"><p> 702 The test harness for the example(s) below is presented in the <a class="link" href="../basics.html#spirit.karma.reference.basics.examples">Basics Examples</a> 703 section. 704 </p></td></tr> 705</table></div> 706<p> 707 Some includes: 708 </p> 709<p> 710</p> 711<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">karma</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 712<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">support_utree</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 713<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">phoenix_core</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 714<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">phoenix_operator</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 715<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">fusion</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">std_pair</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 716<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 717<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">string</span><span class="special">></span> 718</pre> 719<p> 720 </p> 721<p> 722 Some using declarations: 723 </p> 724<p> 725</p> 726<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">lit</span><span class="special">;</span> 727<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">char_</span><span class="special">;</span> 728</pre> 729<p> 730 </p> 731<p> 732 Basic usage of <code class="computeroutput"><span class="identifier">char_</span></code> 733 generators: 734 </p> 735<p> 736</p> 737<pre class="programlisting"><span class="identifier">test_generator</span><span class="special">(</span><span class="string">"A"</span><span class="special">,</span> <span class="char">'A'</span><span class="special">);</span> 738<span class="identifier">test_generator</span><span class="special">(</span><span class="string">"A"</span><span class="special">,</span> <span class="identifier">lit</span><span class="special">(</span><span class="char">'A'</span><span class="special">));</span> 739 740<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"a"</span><span class="special">,</span> <span class="identifier">char_</span><span class="special">,</span> <span class="char">'a'</span><span class="special">);</span> 741<span class="identifier">test_generator</span><span class="special">(</span><span class="string">"A"</span><span class="special">,</span> <span class="identifier">char_</span><span class="special">(</span><span class="char">'A'</span><span class="special">));</span> 742<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"A"</span><span class="special">,</span> <span class="identifier">char_</span><span class="special">(</span><span class="char">'A'</span><span class="special">),</span> <span class="char">'A'</span><span class="special">);</span> 743<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">""</span><span class="special">,</span> <span class="identifier">char_</span><span class="special">(</span><span class="char">'A'</span><span class="special">),</span> <span class="char">'B'</span><span class="special">);</span> <span class="comment">// fails (as 'A' != 'B')</span> 744 745<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"A"</span><span class="special">,</span> <span class="identifier">char_</span><span class="special">(</span><span class="char">'A'</span><span class="special">,</span> <span class="char">'Z'</span><span class="special">),</span> <span class="char">'A'</span><span class="special">);</span> 746<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">""</span><span class="special">,</span> <span class="identifier">char_</span><span class="special">(</span><span class="char">'A'</span><span class="special">,</span> <span class="char">'Z'</span><span class="special">),</span> <span class="char">'a'</span><span class="special">);</span> <span class="comment">// fails (as 'a' does not belong to 'A'...'Z')</span> 747 748<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">"k"</span><span class="special">,</span> <span class="identifier">char_</span><span class="special">(</span><span class="string">"a-z0-9"</span><span class="special">),</span> <span class="char">'k'</span><span class="special">);</span> 749<span class="identifier">test_generator_attr</span><span class="special">(</span><span class="string">""</span><span class="special">,</span> <span class="identifier">char_</span><span class="special">(</span><span class="string">"a-z0-9"</span><span class="special">),</span> <span class="char">'A'</span><span class="special">);</span> <span class="comment">// fails (as 'A' does not belong to "a-z0-9")</span> 750</pre> 751<p> 752 </p> 753</div> 754<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 755<td align="left"></td> 756<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 757 Distributed under the Boost Software License, Version 1.0. (See accompanying 758 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 759 </p> 760</div></td> 761</tr></table> 762<hr> 763<div class="spirit-nav"> 764<a accesskey="p" href="../char.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../char.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="char_class.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 765</div> 766</body> 767</html> 768