Changeset 62994


Ignore:
Timestamp:
Jun 15, 2010, 7:54:45 PM (7 years ago)
Author:
Steven Watanabe
Message:

Make aggregate_filter work with wide characters. Fixes #3851.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/boost/iostreams/filter/aggregate.hpp

    r43799 r62994  
    127127
    128128    template<typename Sink>
    129     void do_write(Sink& sink, const char* s, std::streamsize n)
     129    void do_write(Sink& sink, const char_type* s, std::streamsize n)
    130130    {
    131131        typedef typename iostreams::category_of<Sink>::type  category;
     
    135135
    136136    template<typename Sink>
    137     void do_write(Sink& sink, const char* s, std::streamsize n, mpl::true_)
     137    void do_write(Sink& sink, const char_type* s, std::streamsize n, mpl::true_)
    138138    { iostreams::write(sink, s, n); }
    139139
    140140    template<typename Sink>
    141     void do_write(Sink&, const char*, std::streamsize, mpl::false_) { }
     141    void do_write(Sink&, const char_type*, std::streamsize, mpl::false_) { }
    142142
    143143    void close_impl()
  • trunk/libs/iostreams/test/regex_filter_test.cpp

    r43799 r62994  
    2323    std::string operator() (const boost::match_results<const char*>&)
    2424    { return "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
     25#ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
     26    std::wstring operator() (const boost::match_results<const wchar_t*>&)
     27    { return L"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
     28#endif
    2529};
    2630
     
    168172}
    169173
     174#ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
     175
     176void wregex_filter_test()
     177{
     178    // Note: Given the basic stream and filter tests, two regex tests
     179    // are probably sufficient: reading with a filter based on a function,
     180    // and writing with a filter based on a format string.
     181
     182    test_file       test;
     183    uppercase_file  upper;
     184
     185    boost::wregex match_lower(L"[a-z]+");
     186    std::wstring fmt = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     187
     188    {
     189        // Note: the ifstream second is placed in a nested scope because
     190        // closing and reopening a single ifstream failed for CW 9.4 on Windows.
     191
     192        // Test reading from a regex filter based on a function in chars.
     193        filtering_wistream
     194            first(boost::iostreams::wregex_filter(match_lower, replace_lower()));
     195        first.push(wfile_source(test.name(), in_mode));
     196        {
     197            wifstream second(upper.name().c_str(), in_mode); 
     198            BOOST_CHECK_MESSAGE(
     199                compare_streams_in_chars(first, second),
     200                "failed reading from function-based regex_filter in chars"
     201            );
     202        }
     203        first.pop();
     204
     205        // Test reading from a regex filter based on a function in chunks.
     206        // (Also tests reusing the regex filter.)
     207        first.push(wfile_source(test.name(), in_mode));
     208        {
     209            wifstream second(upper.name().c_str(), in_mode);
     210            BOOST_CHECK_MESSAGE(
     211                compare_streams_in_chunks(first, second),
     212                "failed reading from function-based regex_filter in chunks"
     213            );
     214        }
     215    }
     216
     217    {
     218        // Note: the ifstream second is placed in a nested scope because
     219        // closing and reopening a single ifstream failed for CW 9.4 on Windows.
     220
     221        // Test reading from a regex filter based on a format string in chars.
     222        filtering_wistream
     223            first(boost::iostreams::wregex_filter(match_lower, fmt));
     224        first.push(wfile_source(test.name(), in_mode));
     225        {
     226            wifstream second(upper.name().c_str(), in_mode);
     227            BOOST_CHECK_MESSAGE(
     228                compare_streams_in_chars(first, second),
     229                "failed reading from format-string-based regex_filter in chars"
     230            );
     231        }
     232        first.pop();
     233
     234        // Test reading from a regex filter based on a format string in chunks.
     235        // (Also tests reusing the regex filter.)
     236        first.push(wfile_source(test.name(), in_mode));
     237        {
     238            wifstream second(upper.name().c_str(), in_mode);
     239            BOOST_CHECK_MESSAGE(
     240                compare_streams_in_chars(first, second),
     241                "failed reading from format-string-based regex_filter in chunks"
     242            );
     243        }
     244    }
     245
     246    {
     247        test_file dest1;
     248        test_file dest2;
     249
     250        // Test writing to a regex filter based on a function in chars.
     251        filtering_wostream
     252            out(boost::iostreams::wregex_filter(match_lower, replace_lower()));
     253        out.push(wfile_sink(dest1.name(), out_mode));
     254        write_data_in_chars(out);
     255        out.pop();
     256        BOOST_CHECK_MESSAGE(
     257            compare_files(dest1.name(), upper.name()),
     258            "failed writing to function-based regex_filter in chars"
     259        );
     260
     261        // Test writing to a regex filter based on a function in chunks.
     262        // (Also tests reusing the regex filter.)
     263        out.push(wfile_sink(dest2.name(), out_mode));
     264        write_data_in_chunks(out);
     265        out.pop();
     266        BOOST_CHECK_MESSAGE(
     267            compare_files(dest2.name(), upper.name()),
     268            "failed writing to function-based regex_filter in chunks"
     269        );
     270    }
     271
     272    {
     273        test_file dest1;
     274        test_file dest2;
     275
     276        // Test writing to a regex filter based on a format string in chars.
     277        filtering_wostream 
     278            out(boost::iostreams::wregex_filter(match_lower, fmt));
     279        out.push(wfile_sink(dest1.name(), out_mode));
     280        write_data_in_chars(out);
     281        out.pop();
     282        BOOST_CHECK_MESSAGE(
     283            compare_files(dest1.name(), upper.name()),
     284            "failed writing to format-string-based regex_filter in chars"
     285        );
     286
     287        // Test writing to a regex filter based on a format string in chunks.
     288        // (Also tests reusing the regex filter.)
     289        out.push(wfile_sink(dest2.name(), out_mode));
     290        write_data_in_chunks(out);
     291        out.pop();
     292        BOOST_CHECK_MESSAGE(
     293            compare_files(dest2.name(), upper.name()),
     294            "failed writing to format-string-based regex_filter in chunks"
     295        );
     296    }
     297
     298    {
     299        // Note: the ifstream second is placed in a nested scope because
     300        // closing and reopening a single ifstream failed for CW 9.4 on Windows.
     301
     302        // Test reading from a regex filter with no matches; this checks that
     303        // Ticket #1139 is fixed
     304        boost::wregex   match_xxx(L"xxx");
     305        test_file      test2;
     306        filtering_wistream
     307            first(boost::iostreams::wregex_filter(match_xxx, replace_lower()));
     308        first.push(wfile_source(test.name(), in_mode));
     309        {
     310            wifstream second(test2.name().c_str(), in_mode); 
     311            BOOST_CHECK_MESSAGE(
     312                compare_streams_in_chars(first, second),
     313                "failed reading from a regex filter with no matches"
     314            );
     315        }
     316    }
     317}
     318
     319#endif
     320
    170321test_suite* init_unit_test_suite(int, char* [])
    171322{
    172323    test_suite* test = BOOST_TEST_SUITE("regex_filter test");
    173324    test->add(BOOST_TEST_CASE(&regex_filter_test));
     325#ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
     326    test->add(BOOST_TEST_CASE(&wregex_filter_test));
     327#endif
    174328    return test;
    175329}
Note: See TracChangeset for help on using the changeset viewer.