refactor: bring utf8 patch for std::ostream back.
This commit is contained in:
@ -13,6 +13,7 @@ PRIVATE
|
|||||||
# Sources
|
# Sources
|
||||||
yycc/string/reinterpret.cpp
|
yycc/string/reinterpret.cpp
|
||||||
yycc/string/op.cpp
|
yycc/string/op.cpp
|
||||||
|
yycc/string/stream.cpp
|
||||||
yycc/patch/fopen.cpp
|
yycc/patch/fopen.cpp
|
||||||
yycc/rust/panic.cpp
|
yycc/rust/panic.cpp
|
||||||
yycc/rust/env.cpp
|
yycc/rust/env.cpp
|
||||||
@ -45,6 +46,7 @@ FILES
|
|||||||
yycc/flag_enum.hpp
|
yycc/flag_enum.hpp
|
||||||
yycc/string/reinterpret.hpp
|
yycc/string/reinterpret.hpp
|
||||||
yycc/string/op.hpp
|
yycc/string/op.hpp
|
||||||
|
yycc/string/stream.hpp
|
||||||
yycc/patch/ptr_pad.hpp
|
yycc/patch/ptr_pad.hpp
|
||||||
yycc/patch/fopen.hpp
|
yycc/patch/fopen.hpp
|
||||||
yycc/num/parse.hpp
|
yycc/num/parse.hpp
|
||||||
|
23
src/yycc/string/stream.cpp
Normal file
23
src/yycc/string/stream.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "stream.hpp"
|
||||||
|
#include "reinterpret.hpp"
|
||||||
|
|
||||||
|
#define REINTERPRET ::yycc::string::reinterpret
|
||||||
|
|
||||||
|
namespace yycc::string::stream {
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const std::u8string_view& u8str) {
|
||||||
|
os << REINTERPRET::as_ordinary_view(u8str);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const char8_t* u8str) {
|
||||||
|
os << REINTERPRET::as_ordinary(u8str);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, char8_t u8chr) {
|
||||||
|
os << static_cast<char>(u8chr);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
17
src/yycc/string/stream.hpp
Normal file
17
src/yycc/string/stream.hpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <ostream>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This namespace add UTF8 support for \c std::ostream.
|
||||||
|
* @details
|
||||||
|
* The operator overloads written in this namespace will give \c std::ostream ability to write UTF8 string and its char.
|
||||||
|
* For using this feature, please directly use <TT>using namespace yycc::string:stream;</TT> to import this namespace.
|
||||||
|
*/
|
||||||
|
namespace yycc::string::stream {
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const std::u8string_view& u8str);
|
||||||
|
std::ostream& operator<<(std::ostream& os, const char8_t* u8str);
|
||||||
|
std::ostream& operator<<(std::ostream& os, char8_t u8chr);
|
||||||
|
|
||||||
|
}
|
@ -19,8 +19,9 @@ PRIVATE
|
|||||||
yycc/patch/ptr_pad.cpp
|
yycc/patch/ptr_pad.cpp
|
||||||
yycc/patch/fopen.cpp
|
yycc/patch/fopen.cpp
|
||||||
yycc/rust/env.cpp
|
yycc/rust/env.cpp
|
||||||
yycc/string/op.cpp
|
|
||||||
yycc/string/reinterpret.cpp
|
yycc/string/reinterpret.cpp
|
||||||
|
yycc/string/op.cpp
|
||||||
|
yycc/string/stream.cpp
|
||||||
yycc/num/parse.cpp
|
yycc/num/parse.cpp
|
||||||
yycc/num/stringify.cpp
|
yycc/num/stringify.cpp
|
||||||
yycc/num/op.cpp
|
yycc/num/op.cpp
|
||||||
|
31
testbench/yycc/string/stream.cpp
Normal file
31
testbench/yycc/string/stream.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <yycc.hpp>
|
||||||
|
#include <yycc/string/stream.hpp>
|
||||||
|
#include <yycc/string/reinterpret.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#define REINTERPRET ::yycc::string::reinterpret
|
||||||
|
using namespace std::literals::string_view_literals;
|
||||||
|
using namespace ::yycc::string::stream;
|
||||||
|
|
||||||
|
namespace yycctest::string::stream {
|
||||||
|
|
||||||
|
TEST(StringStream, StringView) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << u8"hello"sv;
|
||||||
|
EXPECT_EQ(REINTERPRET::as_utf8_view(ss.view()), u8"hello"sv);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StringStream, CStrPtr) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << u8"hello";
|
||||||
|
EXPECT_EQ(REINTERPRET::as_utf8_view(ss.view()), u8"hello");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StringStream, Character) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << u8'y';
|
||||||
|
EXPECT_EQ(REINTERPRET::as_utf8_view(ss.view()), u8"y");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user