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

client_regions.cpp


SourceForge.net Logo     CTTL on    
    SourceForge    
    Download    
    Latest    
    Documentation    
    Index    
    Library    
    News    
    CVS    
    Repository    
   Other    
   Links    

Demonstrates policy_space< flag_follow_region >, a white space policy that relies on pre-defined regions of the input text.

// sample code: client_regions.cpp
// demonstrates
// const_edge< policy_space< flag_follow_region > >

//#define CTTL_TRACE_EVERYTHING
//#define CTTL_TRACE_RULES  //define to turn light tracing on
//#define CTTL_TRACE_TRIVIAL    //define for trace messages only mode

#include <iostream>
#include "cttl/cttl.h"

using namespace cttl;

int main()
{
    input<> inp( "0123456789" );

    std::cout
        << "   the input is /"
        << inp.text()
        << '/'
        << std::endl
        << "valid chars are /"
        ;

    policy_space< flag_follow_region > void_region;
    void_region.region_insert( 0, 1 );
    void_region.region_insert( 9, 10 );
    void_region.region_insert( 5, 8 );

    size_t valid_offset = 0;
    while ( valid_offset < inp.length() ) {
        valid_offset = void_region.lower_bound( valid_offset, inp.length() );
        if ( valid_offset >= inp.length() )
            break;

        std::cout << inp.text()[ valid_offset ];
        ++valid_offset;
    }

    const_edge< policy_space< flag_follow_region > > universe( new_edge( inp ), void_region );
    std::cout
        << '/'
        << std::endl
        << " universe.region_difference() is /"
        << universe.region_difference()
        << '/'
        << std::endl
        ;

    universe.first.go_bof();
    universe.second.go_eof();
    const_edge<> data( new_edge( inp ) );
    std::cout
        << "the symbols are /"
        ;
    while( ( data( !first( isdigit ) ) ).match( universe ) != std::string::npos )
        std::cout
            << data.text()
            ;

    std::cout
        << '/'
        << std::endl
        ;

    return 0;
}
This program displays the following output:
   the input is /0123456789/
valid chars are /12348/
 region diff is /12348/
the symbols are /12348/



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:54 2006 for Common Text Transformation Library by  doxygen 1.3.9.1