Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

follow_whitespace.cpp


SourceForge.net Logo     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;
}
This program displays the following output:
data: /a-b-c--d-e-f/



Copyright © 1997-2006 Igor Kholodov mailto:cttl@users.sourceforge.net.

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.


Generated on Thu Nov 2 17:44:55 2006 for Common Text Transformation Library by  doxygen 1.3.9.1