Click here to Skip to main content
15,881,855 members
Articles / Desktop Programming / WTL

Boost.Range support for ATL/WTL CString

Rate me:
Please Sign up or sign in to vote.
4.12/5 (9 votes)
2 Sep 20052 min read 36K   262   11  
Consistent interfaces to CString using Boost.Range.
//  Boost string_algo library iterator_test.cpp file  ---------------------------//

//  Copyright Pavol Droba 2002-2003. Use, modification and
//  distribution is subject to the Boost Software License, Version
//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)

//  See http://www.boost.org for updates, documentation, and revision history.

#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
// equals predicate is used for result comparison
#include <boost/algorithm/string/predicate.hpp>
/*
// Include unit test framework
#include <boost/test/included/test_exec_monitor.hpp>
*/
#include <string>
#include <vector>
#include <iostream>

#include <boost/test/test_tools.hpp>


using namespace std;
using namespace boost;

template< typename T1, typename T2 >
void deep_compare( const T1& X, const T2& Y )
{
    BOOST_REQUIRE( X.size() == Y.size() );
    for( unsigned int nIndex=0; nIndex<X.size(); ++nIndex )
    {
        BOOST_CHECK( equals( X[nIndex], Y[nIndex] ) );
    }
}

inline void iterator_test()
{
		typedef basic_string<TCHAR> sequence_string_t;
    string_t str1(_T("xx-abc--xx-abb"));
    string_t str2(_T("Xx-abc--xX-abb-xx"));
    string_t str3(_T("xx"));
    const TCHAR* pch1=_T("xx-abc--xx-abb");
    vector<sequence_string_t> tokens;
    vector< vector<int> > vtokens;

    // find_all tests
    find_all(
        tokens,
        pch1,
        _T("xx") );

    BOOST_REQUIRE( tokens.size()==2 );
    BOOST_CHECK( equals(tokens[0], string_t(_T("xx"))) );
    BOOST_CHECK( equals(tokens[1], string_t(_T("xx"))) );

    ifind_all(
        tokens,
        str2,
        _T("xx") );

    BOOST_REQUIRE( tokens.size()==3 );
    BOOST_CHECK( equals(tokens[0], string_t(_T("Xx"))) );
    BOOST_CHECK( equals(tokens[1], string_t(_T("xX"))) );
    BOOST_CHECK( equals(tokens[2], string_t(_T("xx"))) );

    find_all(
        tokens,
        str1,
        _T("xx") );

    BOOST_REQUIRE( tokens.size()==2 );
    BOOST_CHECK( equals(tokens[0], string_t(_T("xx"))) );
    BOOST_CHECK( equals(tokens[1], string_t(_T("xx"))) );

    find_all(
        vtokens,
        str1,
        string_t(_T("xx")) );
    deep_compare( tokens, vtokens );

    // split tests
    split(
        tokens,
        str2,
        is_any_of(_T("xX")),
        token_compress_on );

    BOOST_REQUIRE( tokens.size()==4 );
    BOOST_CHECK( equals(tokens[0], string_t(_T(""))) );
    BOOST_CHECK( equals(tokens[1], string_t(_T("-abc--"))) );
    BOOST_CHECK( equals(tokens[2], string_t(_T("-abb-"))) );
    BOOST_CHECK( equals(tokens[3], string_t(_T(""))) );

    split(
        tokens,
        pch1,
        is_any_of(_T("x")),
        token_compress_on );

    BOOST_REQUIRE( tokens.size()==3 );
    BOOST_CHECK( equals(tokens[0], string_t(_T(""))) );
    BOOST_CHECK( equals(tokens[1], string_t(_T("-abc--"))) );
    BOOST_CHECK( equals(tokens[2], string_t(_T("-abb"))) );

    split(
        vtokens,
        str1,
        is_any_of(_T("x")),
        token_compress_on );
    deep_compare( tokens, vtokens );

    split(
        tokens,
        str1,
        is_punct(),
        token_compress_off );

    BOOST_REQUIRE( tokens.size()==5 );
    BOOST_CHECK( equals(tokens[0], string_t(_T("xx"))) );
    BOOST_CHECK( equals(tokens[1], string_t(_T("abc"))) );
    BOOST_CHECK( equals(tokens[2], string_t(_T(""))) );
    BOOST_CHECK( equals(tokens[3], string_t(_T("xx"))) );
    BOOST_CHECK( equals(tokens[4], string_t(_T("abb"))) );
}
/*
// test main 
int test_main( int, TCHAR*[] )
{
    iterator_test();
    
    return 0;
}
*/

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Japan Japan
I am worried about my poor English...

Comments and Discussions