12 std::istringstream is{
"line1\nline2\nline3\n"};
14 std::vector<std::string> v;
18 REQUIRE(v == std::vector<std::string>{
"line1",
"line2",
"line3"});
21 std::wistringstream is{L
"line1\nline2\nline3\n"};
23 std::vector<std::wstring> v;
27 REQUIRE(v == std::vector<std::wstring>{L
"line1", L
"line2", L
"line3"});
31 std::istringstream is(
"abc \t \n"
38 CHECK(is.peek() ==
' ');
51 std::wistringstream is(L
"abc \t \n"
58 REQUIRE(is.peek() ==
' ');
60 REQUIRE(v == L
" xyz ");
65 REQUIRE(v == L
"sgdf");
71 std::istringstream is(
"11/17/2020");
72 int day{}, month{}, year{};
79 REQUIRE(year == 2020);
83 std::istringstream is(
"11-17-2020");
84 int day{}, month{}, year{};
99 REQUIRE(year == 2020);
103 std::wistringstream is(L
"11/17/2020");
104 int day{}, month{}, year{};
109 REQUIRE(month == 11);
111 REQUIRE(year == 2020);
115 std::wistringstream is(L
"11-17-2020");
116 int day{}, month{}, year{};
129 REQUIRE(month == 11);
131 REQUIRE(year == 2020);
135 std::wistringstream is(L
"11/17/2020");
136 int day{}, month{}, year{};
141 REQUIRE(month == 11);
143 REQUIRE(year == 2020);
147 std::wistringstream is(L
"11-17-2020");
148 int day{}, month{}, year{};
161 REQUIRE(month == 11);
163 REQUIRE(year == 2020);
168TEST_CASE(
"expect(widening, UFT-16, good)") {
169 std::basic_istringstream<char16_t> is(u
"11/17/2020");
170 int day{}, month{}, year{};
175 REQUIRE(month == 11);
177 REQUIRE(year == 2020);
180TEST_CASE(
"expect(widening, UTF-16, fail)") {
181 std::basic_istringstream<char16_t> is(u
"11-17-2020");
182 int day{}, month{}, year{};
195 REQUIRE(month == 11);
197 REQUIRE(year == 2020);
200TEST_CASE(
"expect(widening, UFT-32, good)") {
201 std::basic_istringstream<char32_t> is(U
"11/17/2020");
202 int day{}, month{}, year{};
207 REQUIRE(month == 11);
209 REQUIRE(year == 2020);
212TEST_CASE(
"expect(widening, UTF-32, fail)") {
213 std::basic_istringstream<char32_t> is(U
"11-17-2020");
214 int day{}, month{}, year{};
227 REQUIRE(month == 11);
229 REQUIRE(year == 2020);
232TEST_CASE(
"expect(widening, UTF-16 to UFT-32, good)") {
233 std::basic_istringstream<char32_t> is(U
"11/17/2020");
234 int day{}, month{}, year{};
239 REQUIRE(month == 11);
241 REQUIRE(year == 2020);
244TEST_CASE(
"expect(widening, UTF-16 to UTF-32, fail)") {
245 std::basic_istringstream<char32_t> is(U
"11-17-2020");
246 int day{}, month{}, year{};
259 REQUIRE(month == 11);
261 REQUIRE(year == 2020);
267 std::istringstream is(
"11/17/2020");
268 int day{}, month{}, year{};
273 REQUIRE(month == 11);
275 REQUIRE(year == 2020);
279 std::istringstream is(
"11-17-2020");
280 int day{}, month{}, year{};
293 REQUIRE(month == 11);
295 REQUIRE(year == 2020);
301 auto filename =
"kblib";
304 std::cout <<
"FNV32a(" << filename <<
"): " <<
kblib::FNV32a(*filestr)
307 std::cout <<
"failed to open " << filename <<
"\n";
309 auto filevec = kblib::get_file_contents<std::vector<uint8_t>>(filename);
311 std::cout <<
"FNV32a(" << filename
312 <<
"): " << kblib::FNVa<std::uint32_t>(*filevec) <<
'\n';
314 std::cout <<
"failed to open " << filename <<
"\n";
321 auto fileerror = kblib::get_file_contents<std::deque<char>>(filename);
326 std::ostringstream
a, b;
334 os <<
"test" << std::flush;
336 CHECK(
a.str() ==
"test");
337 CHECK(b.str() ==
"test");
338 CHECK(
a.str() == b.str());
340 os <<
's' << std::flush;
342 CHECK(
a.str() ==
"tests");
343 CHECK(b.str() ==
"tests");
344 CHECK(
a.str() == b.str());
346 os << std::setw(8) << 42 << std::flush;
348 CHECK(
a.str() ==
"tests 42");
349 CHECK(b.str() ==
"tests 42");
350 CHECK(
a.str() == b.str());
353 auto len =
a.str().length();
355 os <<
'.' << std::flush;
356 CHECK(
a.str() == b.str());
357 CHECK(
a.str().length() == ++len);
358 CHECK(
a.str().back() ==
'.');
365 auto big_str = std::string(2048,
'?');
366 os << big_str << std::flush;
368 CHECK(
a.str() == big_str);
369 CHECK(
a.str() == b.str());
Provides generic facilities for hashing data, and aliases for standard unordered containers using the...
auto nl(std::basic_istream< CharT, Traits > &is) -> std::basic_istream< CharT, Traits > &
Read in spaces until the end of the line is found.
constexpr auto a(const std::initializer_list< T > &a) -> auto
Index an array literal without naming its type.
auto tee(StreamA &a, StreamB &b) -> basic_teestream< StreamA, StreamB >
constexpr auto range(Value min, Value max, Delta step=0) -> range_t< Value, Delta >
Constructs a range from beginning, end, and step amount. The range is half-open, that is min is in th...
auto get_file_contents(const string &filename) -> std::optional< D >
Read the entire contents of a file into a container, such as std::string or std::vector<char>....
constexpr auto FNV32a(std::string_view s, std::uint32_t hval=fnv::fnv_offset< std::uint32_t >::value) noexcept -> std::uint32_t
A standard FNV32a hash function, for string_views.
auto getline(std::istream &is) -> std::string
By-value std::getline wrapper.
auto expect(CharT c) -> auto
Read a character from an input stream only if it equals c. Acts as a FormattedInputOperation,...
auto get_line(string< CharT, O... > &str) -> auto
Read a whole line into a std::basic_string-like class template.
#define KBLIB_UNUSED
This internal macro is used to provide a fallback for [[maybe_unused]] in C++14.