CTTL on
SourceForge |
Download
Latest |
Documentation
Index |
Library
News |
CVS
Repository |
Other
Links |
Implements user-defined white space policy.
// sample code: follow_whitespace.cpp // demonstrates custom white space policy // defined as dash characters, '-'. #include <iostream> #include "cttl/cttl.h" using namespace cttl; struct policy_dash : public policy_default { template< typename UniverseT > static size_t match( UniverseT& universe_ ) { typedef typename UniverseT::char_T char_T; size_t non_greedy_offset = universe_.first.offset(); ( true ^ *symbol( char_T( '-' ) ) ).match( universe_ ); // policy_dash is non-greedy: return non_greedy_offset; } }; // struct policy_dash int main() { input<> inp( "-a-b-c--d-e-f---" ); const_edge< policy_dash > universe( new_edge( inp ) ); const_edge<> data( new_edge( inp ) ); size_t result = ( data( +entity( isalpha ) ) ).match( universe ); assert( result != std::string::npos ); std::cout << "data: /" << data.text() << '/' << std::endl; return 0; }
data: /a-b-c--d-e-f/
Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.