Skip to content

Commit e0e676e

Browse files
committed
✨ windows_code_page encoding type is now live
1 parent 4d19525 commit e0e676e

26 files changed

Lines changed: 725 additions & 201 deletions

CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ FetchContent_Declare(ztd.idk
141141
GIT_TAG main)
142142
FetchContent_MakeAvailable(ztd.idk)
143143

144-
# ztd.static_containers
145-
FetchContent_Declare(ztd.static_containers
146-
GIT_REPOSITORY https://github.com/soasis/static_containers.git
144+
# ztd.inline_containers
145+
FetchContent_Declare(ztd.inline_containers
146+
GIT_REPOSITORY https://github.com/soasis/inline_containers.git
147147
GIT_SHALLOW ON
148148
GIT_TAG main)
149-
FetchContent_MakeAvailable(ztd.static_containers)
149+
FetchContent_MakeAvailable(ztd.inline_containers)
150150

151151
# ztd.encoding_tables
152152
FetchContent_Declare(ztd.encoding_tables
@@ -187,7 +187,7 @@ target_sources(ztd.text INTERFACE ${ztd.text.includes})
187187
target_link_libraries(ztd.text
188188
INTERFACE
189189
ztd::idk
190-
ztd::static_containers
190+
ztd::inline_containers
191191
ztd::platform
192192
ztd::cuneicode)
193193
target_compile_definitions(ztd.idk

CMakePresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"ZTD_TEXT_BENCHMARKS_REPETITIONS": "2",
117117
"FETCHCONTENT_SOURCE_DIR_ZTD.CMAKE": "${sourceDir}/../cmake",
118118
"FETCHCONTENT_SOURCE_DIR_ZTD.IDK": "${sourceDir}/../idk",
119-
"FETCHCONTENT_SOURCE_DIR_ZTD.STATIC_CONTAINERS": "${sourceDir}/../static_containers",
119+
"FETCHCONTENT_SOURCE_DIR_ZTD.INLINE_CONTAINERS": "${sourceDir}/../inline_containers",
120120
"FETCHCONTENT_SOURCE_DIR_ZTD.CUNEICODE": "${sourceDir}/../cuneicode",
121121
"FETCHCONTENT_SOURCE_DIR_ZTD.ENCODING_TABLES": "${sourceDir}/../encoding_tables",
122122
"FETCHCONTENT_SOURCE_DIR_ZTD.PLATFORM": "${sourceDir}/../platform",

documentation/source/api/encodings/any_encoding.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
..
2929
.. =============================================================================>
3030
31-
any_encoding
32-
============
31+
``any_encoding`` omni-encoding type
32+
===================================
3333

3434
``any_encoding`` is a class type whose sole purpose is to provide a type-generic, byte-based, runtime-deferred way of handling encodings.
3535

@@ -40,14 +40,19 @@ Aliases
4040

4141
.. doxygentypedef:: ztd::text::any_encoding
4242

43+
.. doxygentypedef:: ztd::text::any_encoding_of
44+
4345
.. doxygentypedef:: ztd::text::compat_any_encoding
4446

4547
.. doxygentypedef:: ztd::text::ucompat_any_encoding
4648

4749

4850

49-
Base Template
50-
-------------
51+
Base
52+
----
53+
54+
This is based off of :cpp:class:`ztd::text::any_encoding_with`; the only thing special about it is the constructor logic on top of :cpp:class:`ztd::text::any_encoding_with`.
5155

5256
.. doxygenclass:: ztd::text::any_byte_encoding
53-
:members:
57+
:members: any_byte_encoding, operator=
58+

documentation/source/api/encodings/any_encoding_with.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@
2828
..
2929
.. =============================================================================>
3030
31-
any_encoding_with
32-
=================
31+
``any_encoding_with`` omni-encoding base type
32+
=============================================
3333

3434
This is the lowest level base template, ``any_encoding_with``, that sits beneath :doc:`any_encoding and any_byte_encoding </api/encodings/any_encoding>`. It is recommended for power users with specific goals for the input and output types of the encode and decode operations, where normal buffer-based I/O is unsuitable. In general, you should be relying on :doc:`any_encoding and any_byte_encoding </api/encodings/any_encoding>`.
3535

36-
37-
3836
Base Template
3937
-------------
4038

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
.. =============================================================================
2+
..
3+
.. ztd.text
4+
.. Copyright © JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
5+
.. Contact: [email protected]
6+
..
7+
.. Commercial License Usage
8+
.. Licensees holding valid commercial ztd.text licenses may use this file in
9+
.. accordance with the commercial license agreement provided with the
10+
.. Software or, alternatively, in accordance with the terms contained in
11+
.. a written agreement between you and Shepherd's Oasis, LLC.
12+
.. For licensing terms and conditions see your agreement. For
13+
.. further information contact [email protected].
14+
..
15+
.. Apache License Version 2 Usage
16+
.. Alternatively, this file may be used under the terms of Apache License
17+
.. Version 2.0 (the "License") for non-commercial use; you may not use this
18+
.. file except in compliance with the License. You may obtain a copy of the
19+
.. License at
20+
..
21+
.. https://www.apache.org/licenses/LICENSE-2.0
22+
..
23+
.. Unless required by applicable law or agreed to in writing, software
24+
.. distributed under the License is distributed on an "AS IS" BASIS,
25+
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26+
.. See the License for the specific language governing permissions and
27+
.. limitations under the License.
28+
..
29+
.. =============================================================================>
30+
31+
Windows Code Page
32+
=================
33+
34+
``WideCharToMultiByte`` and ``MultiByteToWideChar`` on Windows platforms has a multitude of encodings with a particular set of quirks. Therefore, on Windows platforms, it may be advantageous to use this over the regular :cpp:class:`execution_encoding_t` type or :cpp:var:`execution_encoding` object. The constructor takes a raw ``int32_t`` whose sole purpose is to be one of the known `Code Page Identifiers`_ that Microsoft supplies on its platforms.
35+
36+
.. warning::
37+
38+
This type is inefficient due to the poor design of the ``WideCharToMultiByte``/``MultiByteToWideChar`` functions. While this will allow users to achieve parity, if the user knows their encoding ahead of time and can provide either their own encoding object or :doc:`/api//encodings <one of the encoding types provided by this library>`, it is highly preferred over this methodology.
39+
40+
.. warning::
41+
42+
For certain distributions, specific language packs may need to be installed in order to use certain conversions tied to specific `Code Page Identifiers`_.
43+
44+
Alias
45+
-----
46+
47+
.. doxygentypedef:: ztd::text::windows_code_page
48+
49+
50+
51+
Base Templates
52+
--------------
53+
54+
.. doxygenclass:: ztd::text::basic_windows_code_page
55+
:members:
56+
57+
58+
.. _Code Page Identifiers: https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers

documentation/source/encodings.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ As a general point, we hope to support almost all of the encodings here in one f
103103
- Yes
104104
- Yes
105105
- :doc:`Yes ✅ </api/encodings/cuneicode_registry_encoding>`
106+
* - Windows Code Page Encoding
107+
- Yes
108+
- Yes
109+
- :doc:`Yes ✅ </api/encodings/windows_code_page>`
106110
* - ARMSCII-8
107111
- ❓ Unresearched
108112
- ❓ Unconfirmed

include/ztd/text/any_encoding_with.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,13 @@ namespace ztd { namespace text {
510510
constexpr ::std::size_t __code_point_max = max_code_points_v<_Encoding>;
511511
using _CodeUnit = code_unit_t<_Encoding>;
512512
using _CodePoint = code_point_t<_Encoding>;
513-
using _Pivot = ::ztd::span<_CodePoint, __code_point_max>;
513+
using _Pivot = ::ztd::span<_CodePoint>;
514514
constexpr bool _AssumeValid = false;
515515

516516
_CodePoint __code_point_buf[__code_point_max] {};
517517
_CodeUnit __code_unit_buf[__code_unit_max] {};
518-
::ztd::span<_CodeUnit, __code_unit_max> __code_unit_view(__code_unit_buf);
519-
_Pivot __pivot(__code_point_buf);
518+
::ztd::span<_CodeUnit> __code_unit_view(__code_unit_buf, __code_unit_max);
519+
_Pivot __pivot(__code_point_buf, __code_point_max);
520520
__txt_detail::__progress_handler<_AssumeValid, _Encoding> __pass_handler {};
521521
__real_encode_state __encode_state = make_encode_state(__encoding);
522522

@@ -558,13 +558,13 @@ namespace ztd { namespace text {
558558
constexpr ::std::size_t __code_point_max = max_recode_code_points_v<_Encoding, _Encoding>;
559559
using _CodeUnit = code_unit_t<_Encoding>;
560560
using _CodePoint = code_point_t<_Encoding>;
561-
using _Pivot = ::ztd::span<_CodeUnit, __code_unit_max>;
561+
using _Pivot = ::ztd::span<_CodeUnit>;
562562
constexpr bool _AssumeValid = false;
563563

564564
_CodePoint __code_point_buf[__code_point_max] {};
565565
_CodeUnit __code_unit_buf[__code_unit_max] {};
566-
::ztd::span<_CodePoint, __code_point_max> __code_point_view(__code_point_buf);
567-
_Pivot __pivot(__code_unit_buf);
566+
::ztd::span<_CodePoint> __code_point_view(__code_point_buf, __code_point_max);
567+
_Pivot __pivot(__code_unit_buf, __code_unit_max);
568568

569569
__txt_detail::__progress_handler<_AssumeValid, _Encoding> __pass_handler {};
570570
__real_decode_state __decode_state = make_decode_state(__encoding);
@@ -619,12 +619,12 @@ namespace ztd { namespace text {
619619
__raw_result.error_code, __raw_result.error_count),
620620
__pass_handler._M_code_units_progress(), __pass_handler._M_code_points_progress());
621621
::std::size_t __used_size = static_cast<::std::size_t>(
622-
::ztd::ranges::distance(__code_point_view.begin(), __err_result.output.begin()));
622+
::ztd::ranges::distance(__code_point_view.data(), __err_result.output.data()));
623623
return __count_as_decoded_result(__err_result.input, __used_size, __state,
624624
__err_result.error_code, __err_result.error_count);
625625
}
626626
::std::size_t __used_size = static_cast<::std::size_t>(
627-
::ztd::ranges::distance(__code_point_view.begin(), __raw_result.output.begin()));
627+
::ztd::ranges::distance(__code_point_view.data(), __raw_result.output.data()));
628628
return __count_as_decoded_result(::std::move(__raw_result.input), __used_size, __state,
629629
__raw_result.error_code, __raw_result.error_count);
630630
}
@@ -656,7 +656,7 @@ namespace ztd { namespace text {
656656
constexpr bool _AssumeValid = is_ignorable_error_handler_v<__encode_error_handler>;
657657

658658
_CodeUnit __code_unit_buf[__code_unit_max] {};
659-
::ztd::span<_CodeUnit, __code_unit_max> __code_unit_view(__code_unit_buf);
659+
::ztd::span<_CodeUnit> __code_unit_view(__code_unit_buf, __code_unit_max);
660660
__txt_detail::__progress_handler<_AssumeValid, _Encoding> __pass_handler {};
661661

662662
auto __raw_result = encode_one_into_raw(::std::move(__input), __encoding, __code_unit_view,

include/ztd/text/basic_encoding_scheme.hpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -326,19 +326,18 @@ namespace ztd { namespace text {
326326
template <typename _Input, typename _Output, typename _ErrorHandler>
327327
constexpr auto decode_one(
328328
_Input&& __input, _Output&& __output, _ErrorHandler&& __error_handler, decode_state& __s) const {
329-
using _UInputRange = remove_cvref_t<_Input>;
330329
using _UOutputRange = remove_cvref_t<_Output>;
331330
using _CVErrorHandler = ::std::remove_reference_t<_ErrorHandler>;
332331
using _SubInput = ztd::ranges::subrange_for_t<::std::remove_reference_t<_Input>>;
333332
using _SubOutput = ztd::ranges::subrange_for_t<::std::remove_reference_t<_Output>>;
334333
using _Result = decode_result<_SubInput, _SubOutput, decode_state>;
335334

336-
using _InByteIt = ranges::word_iterator<_BaseCodeUnit, _UInputRange, _Endian>;
335+
using _InByteIt = ranges::word_iterator<_BaseCodeUnit, _SubInput, _Endian>;
337336
using _InByteSen = ranges::word_sentinel;
338337
::ztd::ranges::subrange<_InByteIt, _InByteSen> __inbytes(
339338
_InByteIt(::std::in_place, ::std::forward<_Input>(__input)), _InByteSen());
340-
__txt_detail::__scheme_handler<_Byte, _UInputRange, _UOutputRange, _CVErrorHandler>
341-
__intermediate_handler(__error_handler);
339+
__txt_detail::__scheme_handler<_Byte, _SubInput, _UOutputRange, _CVErrorHandler> __intermediate_handler(
340+
__error_handler);
342341
auto __result = this->base().decode_one(
343342
::std::move(__inbytes), ::std::forward<_Output>(__output), __intermediate_handler, __s);
344343
return _Result(::std::move(__result.input).begin().range(), ::std::move(__result.output), __s,
@@ -365,23 +364,23 @@ namespace ztd { namespace text {
365364
template <typename _Input, typename _Output, typename _ErrorHandler>
366365
constexpr auto encode_one(
367366
_Input&& __input, _Output&& __output, _ErrorHandler&& __error_handler, encode_state& __s) const {
368-
using _UInputRange = remove_cvref_t<_Input>;
369-
using _UOutputRange = remove_cvref_t<_Output>;
370-
using _CVErrorHandler = ::std::remove_reference_t<_ErrorHandler>;
371-
using _SubInput = ztd::ranges::subrange_for_t<::std::remove_reference_t<_Input>>;
367+
using _SubInput = ztd::ranges::csubrange_for_t<::std::remove_reference_t<_Input>>;
372368
using _SubOutput = ztd::ranges::subrange_for_t<::std::remove_reference_t<_Output>>;
373-
using _Result = encode_result<_SubInput, _SubOutput, encode_state>;
374-
using _OutByteIt = ranges::word_iterator<_BaseCodeUnit, _UOutputRange, _Endian>;
369+
using _OutByteIt = ranges::word_iterator<_BaseCodeUnit, _SubOutput, _Endian>;
375370
using _OutByteSen = ranges::word_sentinel;
371+
using _CVErrorHandler = ::std::remove_reference_t<_ErrorHandler>;
372+
using _Result = encode_result<_SubInput, _SubOutput, encode_state>;
376373

374+
_SubOutput __outwords_output(::std::forward<_Output>(__output));
377375
ranges::subrange<_OutByteIt, _OutByteSen> __outwords(
378-
_OutByteIt(::std::forward<_Output>(__output)), _OutByteSen());
379-
__txt_detail::__scheme_handler<_Byte, _UInputRange, _UOutputRange, _CVErrorHandler>
380-
__intermediate_handler(__error_handler);
376+
_OutByteIt(::std::move(__outwords_output)), _OutByteSen());
377+
__txt_detail::__scheme_handler<_Byte, _SubInput, _SubOutput, _CVErrorHandler> __intermediate_handler(
378+
__error_handler);
381379
auto __result
382380
= this->base().encode_one(::std::forward<_Input>(__input), __outwords, __intermediate_handler, __s);
383-
return _Result(::std::move(__result.input), ::std::move(__result.output).begin().range(), __s,
384-
__result.error_code, __result.error_count);
381+
_SubOutput __result_output(::std::move(__result.output).begin().range());
382+
return _Result(::std::move(__result.input), ::std::move(__result_output), __s, __result.error_code,
383+
__result.error_count);
385384
}
386385
};
387386

include/ztd/text/decode_one.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#include <ztd/idk/type_traits.hpp>
5454
#include <ztd/idk/char_traits.hpp>
5555
#include <ztd/idk/tag.hpp>
56-
#include <ztd/static_containers.hpp>
56+
#include <ztd/inline_containers.hpp>
5757

5858
#include <ztd/prologue.hpp>
5959

@@ -396,14 +396,14 @@ namespace ztd { namespace text {
396396
constexpr ::std::size_t __max_units = max_decode_code_points_v<_UEncoding>;
397397
if constexpr (_IsVoidContainer && _IsStringable) {
398398
// prevent instantiation errors with basic_string by boxing it inside of an "if constexpr"
399-
using _RealOutputContainer = ::ztd::static_basic_string<_OutputCodePoint, __max_units>;
399+
using _RealOutputContainer = ::ztd::inline_basic_string<_OutputCodePoint, __max_units>;
400400
return __txt_detail::__decode_one_dispatch<false, false, _RealOutputContainer>(
401401
::std::forward<_Input>(__input), ::std::forward<_Encoding>(__encoding),
402402
::std::forward<_ErrorHandler>(__error_handler), __state);
403403
}
404404
else {
405405
using _RealOutputContainer = ::std::conditional_t<_IsVoidContainer,
406-
::ztd::static_vector<_OutputCodePoint, __max_units>, _OutputContainer>;
406+
::ztd::inline_vector<_OutputCodePoint, __max_units>, _OutputContainer>;
407407
return __txt_detail::__decode_one_dispatch<false, false, _RealOutputContainer>(
408408
::std::forward<_Input>(__input), ::std::forward<_Encoding>(__encoding),
409409
::std::forward<_ErrorHandler>(__error_handler), __state);
@@ -520,14 +520,14 @@ namespace ztd { namespace text {
520520
= (is_char_traitable_v<_OutputCodePoint> || is_unicode_code_point_v<_OutputCodePoint>);
521521

522522
if constexpr (_IsVoidContainer && _IsStringable) {
523-
using _RealOutputContainer = ::ztd::static_basic_string<_OutputCodePoint, __max_units>;
523+
using _RealOutputContainer = ::ztd::inline_basic_string<_OutputCodePoint, __max_units>;
524524
return __txt_detail::__decode_one_dispatch<true, false, _RealOutputContainer>(
525525
::std::forward<_Input>(__input), ::std::forward<_Encoding>(__encoding),
526526
::std::forward<_ErrorHandler>(__error_handler), __state);
527527
}
528528
else {
529529
using _RealOutputContainer = ::std::conditional_t<_IsVoidContainer,
530-
::ztd::static_vector<_OutputCodePoint, max_code_points_v<_UEncoding>>, _OutputContainer>;
530+
::ztd::inline_vector<_OutputCodePoint, max_code_points_v<_UEncoding>>, _OutputContainer>;
531531
return __txt_detail::__decode_one_dispatch<true, false, _RealOutputContainer>(
532532
::std::forward<_Input>(__input), ::std::forward<_Encoding>(__encoding),
533533
::std::forward<_ErrorHandler>(__error_handler), __state);

include/ztd/text/default_handler.hpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,9 @@ namespace ztd { namespace text {
5151
//////
5252
/// @brief The default error handler for the entire library. Can be configured to use different strategies at build
5353
/// time. Without configuration, it defaults to the ztd::text::replacement_handler_t.
54-
class default_handler_t
55-
#if ZTD_IS_ON(ZTD_TEXT_DEFAULT_HANDLER_THROWS)
56-
: private throw_handler_t {
54+
class default_handler_t : private replacement_handler_t {
5755
private:
58-
using __error_handler_base_t = throw_handler_t;
59-
#else
60-
: private replacement_handler_t {
61-
private:
62-
using __error_handler_base_t = replacement_handler_t;
63-
#endif
56+
using __error_handler_base_t = __txt_detail::__default_handler_base_t;
6457

6558
public:
6659
//////
@@ -76,6 +69,27 @@ namespace ztd { namespace text {
7669
/// @brief An instance of the default_handler_t type for ease of use.
7770
inline constexpr default_handler_t default_handler = {};
7871

72+
//////
73+
/// @brief The default error handler for the entire library. Can be configured to use different strategies at build
74+
/// time. Without configuration, it defaults to the ztd::text::replacement_handler_t.
75+
class unchecked_default_handler_t : private default_handler_t {
76+
private:
77+
using __error_handler_base_t = default_handler_t;
78+
79+
public:
80+
//////
81+
///@brief The underlying error handler type.
82+
using error_handler = __error_handler_base_t;
83+
84+
using __error_handler_base_t::__error_handler_base_t;
85+
86+
using __error_handler_base_t::operator();
87+
};
88+
89+
//////
90+
/// @brief An instance of the default_handler_t type for ease of use.
91+
inline constexpr unchecked_default_handler_t unchecked_default_handler = {};
92+
7993
namespace __txt_detail {
8094
template <typename _ErrorHandler>
8195
constexpr auto __duplicate_or_be_careless(_ErrorHandler& __original) {

0 commit comments

Comments
 (0)