1bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===----------------------------------------------------------------------===//
2bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
3f5256e16dfc425c1d466f6308d4026d529ce9e0bHoward Hinnant//                     The LLVM Compiler Infrastructure
4bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
5b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// This file is dual licensed under the MIT and the University of Illinois Open
6b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// Source Licenses. See LICENSE.TXT for details.
7bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
8bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===----------------------------------------------------------------------===//
9bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
10bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// <istream>
11bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
12256813f4e7915d64776a4edd5f4765d893b9f062Howard Hinnant// basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb,
13256813f4e7915d64776a4edd5f4765d893b9f062Howard Hinnant//                                  char_type delim);
14bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
15bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <istream>
16bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <cassert>
17bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
18bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnanttemplate <class CharT>
19bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantclass testbuf
20bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    : public std::basic_streambuf<CharT>
21bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
22bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    typedef std::basic_streambuf<CharT> base;
23bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    std::basic_string<CharT> str_;
24bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantpublic:
25bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    testbuf()
26bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    {
27bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    }
28bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    testbuf(const std::basic_string<CharT>& str)
29bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        : str_(str)
30bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    {
31bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        base::setg(const_cast<CharT*>(str_.data()),
32bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant                   const_cast<CharT*>(str_.data()),
33bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant                   const_cast<CharT*>(str_.data() + str_.size()));
34bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    }
35bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
36bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    std::basic_string<CharT> str() const
37bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        {return std::basic_string<CharT>(base::pbase(), base::pptr());}
38bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
39bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantprotected:
40bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
41bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    virtual typename base::int_type
42bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        overflow(typename base::int_type __c = base::traits_type::eof())
43bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        {
44bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant            if (__c != base::traits_type::eof())
45bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant            {
46bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant                int n = str_.size();
47bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant                str_.push_back(__c);
48bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant                str_.resize(str_.capacity());
49bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant                base::setp(const_cast<CharT*>(str_.data()),
50bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant                           const_cast<CharT*>(str_.data() + str_.size()));
51bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant                base::pbump(n+1);
52bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant            }
53bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant            return __c;
54bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        }
55bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant};
56bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
57bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantint main()
58bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
59bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    {
60bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        testbuf<char> sb("testing*...");
61bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        std::istream is(&sb);
62bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        testbuf<char> sb2;
63bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        is.get(sb2, '*');
64bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(sb2.str() == "testing");
65bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(is.good());
66bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(is.gcount() == 7);
67bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(is.get() == '*');
68bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        is.get(sb2, '*');
69bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(sb2.str() == "testing...");
70bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(is.eof());
71bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(!is.fail());
72bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(is.gcount() == 3);
73bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    }
74bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    {
75bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        testbuf<wchar_t> sb(L"testing*...");
76bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        std::wistream is(&sb);
77bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        testbuf<wchar_t> sb2;
78bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        is.get(sb2, L'*');
79bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(sb2.str() == L"testing");
80bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(is.good());
81bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(is.gcount() == 7);
82bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(is.get() == L'*');
83bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        is.get(sb2, L'*');
84bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(sb2.str() == L"testing...");
85bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(is.eof());
86bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(!is.fail());
87bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(is.gcount() == 3);
88bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    }
89bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
90