...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
The string
parser matches
a string of characters. The string
parser is an implicit lexeme: the skip
parser is not applied in between characters of the string. The string
parser has an associated Character
Encoding Namespace. This is needed when doing basic operations
such as inhibiting case sensitivity. Examples:
string("Hello") string(L"Hello") string(s) // s is a std::string
lit
, like string
, also matches a string of characters.
The main difference is that lit
does not synthesize an attribute. A plain string like "hello"
or a std::basic_string
is equivalent to a lit
. Examples:
"Hello" lit("Hello") lit(L"Hello") lit(s) // s is a std::string
// forwards to <boost/spirit/home/qi/string/lit.hpp> #include <boost/spirit/include/qi_lit.hpp>
Name |
---|
|
|
In the table above, ns
represents a Character
Encoding Namespace.
Notation
s
A String or a Lazy Argument that evaluates to a String.
ns
Semantics of an expression is defined only where it differs from, or
is not defined in PrimitiveParser
.
Expression |
Semantics |
---|---|
|
Create string parser from a string, |
|
Create a string parser from a string, |
|
Create a string parser with |
Expression |
Attribute |
---|---|
|
|
|
|
|
|
O(N)
where N
is the number
of characters in the string to be parsed.
Note | |
---|---|
The test harness for the example(s) below is presented in the Basics Examples section. |
Some using declarations:
using boost::spirit::qi::lit; using boost::spirit::ascii::string;
Basic literals:
test_parser("boost", "boost"); // plain literal test_parser("boost", lit("boost")); // explicit literal test_parser("boost", string("boost")); // ascii::string
From a std::string
std::string s("boost"); test_parser("boost", s); // direct test_parser("boost", lit(s)); // explicit test_parser("boost", string(s)); // ascii::string
Lazy strings using Phoenix
namespace phx = boost::phoenix; test_parser("boost", phx::val("boost")); // direct test_parser("boost", lit(phx::val("boost"))); // explicit test_parser("boost", string(phx::val("boost"))); // ascii::string