Skip to content

Commit

Permalink
🛠 Fix bad header names and repair shitty MSVC u8"" string literal beh…
Browse files Browse the repository at this point in the history
…avior
  • Loading branch information
ThePhD committed Dec 24, 2022
1 parent 828a382 commit 07d1109
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 26 deletions.
10 changes: 5 additions & 5 deletions benchmarks/conversion_speed/source/iconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ inline namespace ztd_text_benchmarks_conversion_speed_iconv {
struct pointer {
ztd::plat::icnv::descriptor handle;

pointer(nullptr_t = nullptr) noexcept : handle(ztd::plat::icnv::failure_descriptor) {
pointer(::std::nullptr_t = nullptr) noexcept : handle(ztd::plat::icnv::failure_descriptor) {
}

pointer(ztd::plat::icnv::descriptor desc) noexcept : handle(desc) {
Expand All @@ -69,19 +69,19 @@ inline namespace ztd_text_benchmarks_conversion_speed_iconv {
return this->handle;
}

friend bool operator==(pointer p, nullptr_t) noexcept {
friend bool operator==(pointer p, ::std::nullptr_t) noexcept {
return !ztd::plat::icnv::descriptor_is_valid(p.handle);
}

friend bool operator==(nullptr_t, pointer p) noexcept {
friend bool operator==(::std::nullptr_t, pointer p) noexcept {
return !ztd::plat::icnv::descriptor_is_valid(p.handle);
}

friend bool operator!=(pointer p, nullptr_t) noexcept {
friend bool operator!=(pointer p, ::std::nullptr_t) noexcept {
return ztd::plat::icnv::descriptor_is_valid(p.handle);
}

friend bool operator!=(nullptr_t, pointer p) noexcept {
friend bool operator!=(::std::nullptr_t, pointer p) noexcept {
return ztd::plat::icnv::descriptor_is_valid(p.handle);
}
};
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/conversion_speed/source/iconv.init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ inline namespace ztd_text_benchmarks_conversion_speed_iconv_init {
struct pointer {
ztd::plat::icnv::descriptor handle;

pointer(nullptr_t = nullptr) noexcept : handle(ztd::plat::icnv::failure_descriptor) {
pointer(::std::nullptr_t = nullptr) noexcept : handle(ztd::plat::icnv::failure_descriptor) {
}

pointer(ztd::plat::icnv::descriptor desc) noexcept : handle(desc) {
Expand All @@ -69,19 +69,19 @@ inline namespace ztd_text_benchmarks_conversion_speed_iconv_init {
return this->handle;
}

friend bool operator==(pointer p, nullptr_t) noexcept {
friend bool operator==(pointer p, ::std::nullptr_t) noexcept {
return !ztd::plat::icnv::descriptor_is_valid(p.handle);
}

friend bool operator==(nullptr_t, pointer p) noexcept {
friend bool operator==(::std::nullptr_t, pointer p) noexcept {
return !ztd::plat::icnv::descriptor_is_valid(p.handle);
}

friend bool operator!=(pointer p, nullptr_t) noexcept {
friend bool operator!=(pointer p, ::std::nullptr_t) noexcept {
return ztd::plat::icnv::descriptor_is_valid(p.handle);
}

friend bool operator!=(nullptr_t, pointer p) noexcept {
friend bool operator!=(::std::nullptr_t, pointer p) noexcept {
return ztd::plat::icnv::descriptor_is_valid(p.handle);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
int main(int, char*[]) {
// Scuffed UTF-8 input: 'C0' is not a legal sequence starter
// for regular, pure UTF-8
constexpr const char input[] = u8"Me\xC0\x9F\x90\xB1ow!";
constexpr const char input[]
= { 'M', 'e', '\xC0', '\x9F', '\x90', '\xB1', 'o', 'w', '!', '\0' };
constexpr const char32_t expected_default_output[] = U"Me�ow!";

std::u32string utf32_string_with_default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
int main(int, char*[]) {
// Scuffed UTF-8 input: 'C0' is not a legal sequence starter
// for regular, pure UTF-8
constexpr const char input[] = u8"Me\xC0\x9F\x90\xB1ow!";
constexpr const char input[]
= { 'M', 'e', '\xC0', '\x9F', '\x90', '\xB1', 'o', 'w', '!', '\0' };
constexpr const char32_t expected_pass_output[] = U"Me";
constexpr const char expected_pass_leftover_input[] = u8"\xC0\x9F\x90\xB1ow!";
constexpr const char expected_pass_leftover_input[]
= { '\xC0', '\x9F', '\x90', '\xB1', 'o', 'w', '!', '\0' };

std::u32string utf32_string_with_pass = ztd::text::transcode(input,
ztd::text::compat_utf8, ztd::text::utf32, ztd::text::pass_handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
int main(int, char*[]) {
// Scuffed UTF-8 input: 'C0' is not a legal sequence starter
// for regular, pure UTF-8
constexpr const char input[] = u8"Me\xC0\x9F\x90\xB1ow!";
constexpr const char input[]
= { 'M', 'e', '\xC0', '\x9F', '\x90', '\xB1', 'o', 'w', '!', '\0' };
constexpr const char32_t expected_replacement_output[] = U"Me�ow!";

std::u32string utf32_string_with_replacement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
int main(int, char*[]) {
// Scuffed UTF-8 input: 'C0' is not a legal sequence starter
// for regular, pure UTF-8
constexpr const char input[] = u8"Me\xC0\x9F\x90\xB1ow!";
constexpr const char input[]
= { 'M', 'e', '\xC0', '\x9F', '\x90', '\xB1', 'o', 'w', '!', '\0' };
constexpr const char32_t expected_skip_output[] = U"Meow!";

std::u32string utf32_string_with_skip = ztd::text::transcode(input,
Expand Down
2 changes: 1 addition & 1 deletion examples/documentation/quick/setup/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main(int argc, char* argv[]) {

// overlong encoded null
// (https://ztdtext.rtfd.io/en/latest/api/encodings/mutf8.html)
const char mutf8_text[] = u8"meow\xc0\x80meow!";
const char mutf8_text[] = { 'm','e','o','w','\xc0','\x80','m','e','o','w','!' };
const auto is_valid_mutf8_text
= ztd::text::validate_decodable_as(mutf8_text, ztd::text::compat_mutf8);

Expand Down
2 changes: 1 addition & 1 deletion include/ztd/text/encoding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include <ztd/text/ascii.hpp>
#include <ztd/text/shift_jis.hpp>
#include <ztd/text/euc_kr.hpp>
#include <ztd/text/latin1.hpp>
#include <ztd/text/windows_1252.hpp>
#include <ztd/text/utf8.hpp>
#include <ztd/text/utf16.hpp>
#include <ztd/text/utf32.hpp>
Expand Down
6 changes: 4 additions & 2 deletions include/ztd/text/transcode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#include <ztd/text/is_unicode_code_point.hpp>
#include <ztd/text/transcode_one.hpp>
#include <ztd/text/pivot.hpp>
#include <ztd/text/encode.hpp>
#include <ztd/text/decode.hpp>
#include <ztd/text/detail/is_lossless.hpp>
#include <ztd/text/detail/encoding_range.hpp>
#include <ztd/text/detail/transcode_extension_points.hpp>
Expand Down Expand Up @@ -238,7 +240,7 @@ namespace ztd { namespace text {
(void)__to_encoding;
(void)__to_error_handler;
(void)__pivot;
auto __result = decode_into_raw(::std::forward<_Input>(__input),
auto __result = ::ztd::text::decode_into_raw(::std::forward<_Input>(__input),
::std::forward<_FromEncoding>(__from_encoding), ::std::forward<_Output>(__output),
::std::forward<_FromErrorHandler>(__from_error_handler), __from_state);
using _Result
Expand All @@ -255,7 +257,7 @@ namespace ztd { namespace text {
(void)__from_encoding;
(void)__from_error_handler;
(void)__pivot;
auto __result = encode_into_raw(::std::forward<_Input>(__input),
auto __result = ::ztd::text::encode_into_raw(::std::forward<_Input>(__input),
::std::forward<_ToEncoding>(__to_encoding), ::std::forward<_Output>(__output),
::std::forward<_FromErrorHandler>(__to_error_handler), __to_state);
using _Result
Expand Down
15 changes: 8 additions & 7 deletions include/ztd/text/windows_1252.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@

#pragma once

#ifndef ZTD_TEXT_LATIN1_HPP
#define ZTD_TEXT_LATIN1_HPP
#ifndef ZTD_TEXT_WINDOWS_1252_HPP
#define ZTD_TEXT_WINDOWS_1252_HPP

#include <ztd/text/version.hpp>

#include <ztd/text/impl/single_byte_lookup_encoding.hpp>

#include <ztd/idk/latin1.tables.hpp>
#include <ztd/idk/windows_1252.tables.hpp>
#include <ztd/ranges/adl.hpp>

#include <ztd/prologue.hpp>
Expand All @@ -46,13 +46,14 @@ namespace ztd { namespace text {
ZTD_TEXT_INLINE_ABI_NAMESPACE_OPEN_I_

template <typename _CodeUnit = char, typename _CodePoint = unicode_code_point>
struct basic_latin1
: public __txt_impl::__single_byte_lookup_encoding<basic_latin1<_CodeUnit, _CodePoint>,
&::ztd::latin1_index_to_code_point, &::ztd::latin1_code_point_to_index, _CodeUnit, _CodePoint> { };
struct basic_windows_1252
: public __txt_impl::__single_byte_lookup_encoding<basic_windows_1252<_CodeUnit, _CodePoint>,
&::ztd::windows_1252_index_to_code_point, &::ztd::windows_1252_code_point_to_index, _CodeUnit, _CodePoint> {
};

//////
/// @brief An instance of skip_handler_t for ease of use.
inline constexpr basic_latin1<char> latin1 = {};
inline constexpr basic_windows_1252<char> windows_1252 = {};

ZTD_TEXT_INLINE_ABI_NAMESPACE_CLOSE_I_
}} // namespace ztd::text
Expand Down

0 comments on commit 07d1109

Please sign in to comment.