Skip to content

Commit

Permalink
✨ Windows-1251 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed May 11, 2023
1 parent 6ba5588 commit 6c5d7ba
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 53 deletions.
44 changes: 44 additions & 0 deletions documentation/source/api/encodings/windows_1251.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.. =============================================================================
..
.. ztd.text
.. Copyright © 2022-2023 JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
.. Contact: opensource@soasis.org
..
.. Commercial License Usage
.. Licensees holding valid commercial ztd.text licenses may use this file in
.. accordance with the commercial license agreement provided with the
.. Software or, alternatively, in accordance with the terms contained in
.. a written agreement between you and Shepherd's Oasis, LLC.
.. For licensing terms and conditions see your agreement. For
.. further information contact opensource@soasis.org.
..
.. Apache License Version 2 Usage
.. Alternatively, this file may be used under the terms of Apache License
.. Version 2.0 (the "License") for non-commercial use; you may not use this
.. file except in compliance with the License. You may obtain a copy of the
.. License at
..
.. https://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.
..
.. =============================================================================>
Windows-1251
============



.. doxygenvariable:: ztd::text::windows_1251



Base Template
-------------

.. doxygenclass:: ztd::text::basic_windows_1251
:members:
104 changes: 52 additions & 52 deletions include/ztd/text/cuneicode_encoding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,83 +50,83 @@ namespace ztd { namespace text {
/// @tparam _CodeUnit The type for the unit of encoded data.
/// @tparam _CodePoint The type for the unit of decoded data.
template <typename _CodeUnit = char, typename _CodePoint = unicode_code_point>
class basic_big5_hkscs : public __txt_impl::__fixed_cuneicode<basic_big5_hkscs<_CodeUnit, _CodePoint>,
// code unit / code point type
_CodeUnit, _CodePoint,
// max code units / code points
2, 2,
// decode functions, type + (constexpr) value
decltype(&::cnc_mcnrtoc32n_big5_hkscs), (&::cnc_mcnrtoc32n_big5_hkscs),
// encode functions, type + (constexpr) value
decltype(&::cnc_c32nrtomcn_big5_hkscs), (&::cnc_c32nrtomcn_big5_hkscs),
// decode state/completion
cnc_mcstate_t, decltype(&::cnc_mcstate_is_complete), &::cnc_mcstate_is_complete,
// encode state/completion
cnc_mcstate_t, decltype(&::cnc_mcstate_is_complete), &::cnc_mcstate_is_complete,
// is_injective
true, false,
// true code unit / code point types
char, char32_t> { };
class basic_cnc_big5_hkscs : public __txt_impl::__fixed_cuneicode<basic_cnc_big5_hkscs<_CodeUnit, _CodePoint>,
// code unit / code point type
_CodeUnit, _CodePoint,
// max code units / code points
2, 2,
// decode functions, type + (constexpr) value
decltype(&::cnc_mcnrtoc32n_big5_hkscs), (&::cnc_mcnrtoc32n_big5_hkscs),
// encode functions, type + (constexpr) value
decltype(&::cnc_c32nrtomcn_big5_hkscs), (&::cnc_c32nrtomcn_big5_hkscs),
// decode state/completion
cnc_mcstate_t, decltype(&::cnc_mcstate_is_complete), &::cnc_mcstate_is_complete,
// encode state/completion
cnc_mcstate_t, decltype(&::cnc_mcstate_is_complete), &::cnc_mcstate_is_complete,
// is_injective
true, false,
// true code unit / code point types
char, char32_t> { };

//////
/// @brief A convenience for ease of use.
inline constexpr basic_big5_hkscs<char, char32_t> big5_hkscs = {};
inline constexpr basic_cnc_big5_hkscs<char, char32_t> big5_cnc_hkscs = {};

//////
/// @brief An encoding implementing WHATWG's GBK.
///
/// @tparam _CodeUnit The type for the unit of encoded data.
/// @tparam _CodePoint The type for the unit of decoded data.
template <typename _CodeUnit = char, typename _CodePoint = unicode_code_point>
class basic_gbk : public __txt_impl::__fixed_cuneicode<basic_gbk<_CodeUnit, _CodePoint>,
// code unit / code point type
_CodeUnit, _CodePoint,
// max code units / code points
2, 1,
// decode functions, type + (constexpr) value
decltype(&::cnc_mcnrtoc32n_gbk), (&::cnc_mcnrtoc32n_gbk),
// encode functions, type + (constexpr) value
decltype(&::cnc_c32nrtomcn_gbk), (&::cnc_c32nrtomcn_gbk),
// decode state/completion
cnc_mcstate_t, decltype(&::cnc_mcstate_is_complete), &::cnc_mcstate_is_complete,
// encode state/completion
cnc_mcstate_t, decltype(&::cnc_mcstate_is_complete), &::cnc_mcstate_is_complete,
// is_injective
true, false,
// true code unit / code point types
char, char32_t> { };

//////
/// @brief A convenience alias for ease of use.
inline constexpr basic_gbk<char, char32_t> gbk = {};

//////
/// @brief An encoding implementing WHATWG's GB18030
///
/// @tparam _CodeUnit The type for the unit of encoded data.
/// @tparam _CodePoint The type for the unit of decoded data.
template <typename _CodeUnit = char, typename _CodePoint = unicode_code_point>
class basic_gb18030 : public __txt_impl::__fixed_cuneicode<basic_gb18030<_CodeUnit, _CodePoint>,
class basic_cnc_gbk : public __txt_impl::__fixed_cuneicode<basic_cnc_gbk<_CodeUnit, _CodePoint>,
// code unit / code point type
_CodeUnit, _CodePoint,
// max code units / code points
4, 2,
2, 1,
// decode functions, type + (constexpr) value
decltype(&::cnc_mcnrtoc32n_gb18030), (&::cnc_mcnrtoc32n_gb18030),
decltype(&::cnc_mcnrtoc32n_gbk), (&::cnc_mcnrtoc32n_gbk),
// encode functions, type + (constexpr) value
decltype(&::cnc_c32nrtomcn_gb18030), (&::cnc_c32nrtomcn_gb18030),
decltype(&::cnc_c32nrtomcn_gbk), (&::cnc_c32nrtomcn_gbk),
// decode state/completion
cnc_mcstate_t, decltype(&::cnc_mcstate_is_complete), &::cnc_mcstate_is_complete,
// encode state/completion
cnc_mcstate_t, decltype(&::cnc_mcstate_is_complete), &::cnc_mcstate_is_complete,
// is_injective
true, true,
true, false,
// true code unit / code point types
char, char32_t> { };

//////
/// @brief A convenience alias for ease of use.
inline constexpr basic_gb18030<char, char32_t> gb18030 = {};
inline constexpr basic_cnc_gbk<char, char32_t> cnc_gbk = {};

//////
/// @brief An encoding implementing WHATWG's GB18030
///
/// @tparam _CodeUnit The type for the unit of encoded data.
/// @tparam _CodePoint The type for the unit of decoded data.
template <typename _CodeUnit = char, typename _CodePoint = unicode_code_point>
class basic_cnc_gb18030 : public __txt_impl::__fixed_cuneicode<basic_cnc_gb18030<_CodeUnit, _CodePoint>,
// code unit / code point type
_CodeUnit, _CodePoint,
// max code units / code points
4, 2,
// decode functions, type + (constexpr) value
decltype(&::cnc_mcnrtoc32n_gb18030), (&::cnc_mcnrtoc32n_gb18030),
// encode functions, type + (constexpr) value
decltype(&::cnc_c32nrtomcn_gb18030), (&::cnc_c32nrtomcn_gb18030),
// decode state/completion
cnc_mcstate_t, decltype(&::cnc_mcstate_is_complete), &::cnc_mcstate_is_complete,
// encode state/completion
cnc_mcstate_t, decltype(&::cnc_mcstate_is_complete), &::cnc_mcstate_is_complete,
// is_injective
true, true,
// true code unit / code point types
char, char32_t> { };

//////
/// @brief A convenience alias for ease of use.
inline constexpr basic_cnc_gb18030<char, char32_t> cnc_gb18030 = {};

ZTD_TEXT_INLINE_ABI_NAMESPACE_CLOSE_I_
}} // namespace ztd::text
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 @@ -56,12 +56,12 @@
#include <ztd/text/ibm_1006_urdu.hpp>
#include <ztd/text/kazakh_strk1048.hpp>
#include <ztd/text/koi8_u.hpp>
#include <ztd/text/punycode.hpp>
#include <ztd/text/shift_jis_x0208.hpp>
#include <ztd/text/punycode.hpp>
#include <ztd/text/utf8.hpp>
#include <ztd/text/utf16.hpp>
#include <ztd/text/utf32.hpp>
#include <ztd/text/windows_1251.hpp>
#include <ztd/text/windows_1252.hpp>

#include <ztd/prologue.hpp>
Expand Down
64 changes: 64 additions & 0 deletions include/ztd/text/windows_1251.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// =============================================================================
//
// ztd.text
// Copyright © 2022-2023 JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
// Contact: opensource@soasis.org
//
// Commercial License Usage
// Licensees holding valid commercial ztd.text licenses may use this file in
// accordance with the commercial license agreement provided with the
// Software or, alternatively, in accordance with the terms contained in
// a written agreement between you and Shepherd's Oasis, LLC.
// For licensing terms and conditions see your agreement. For
// further information contact opensource@soasis.org.
//
// Apache License Version 2 Usage
// Alternatively, this file may be used under the terms of Apache License
// Version 2.0 (the "License") for non-commercial use; you may not use this
// file except in compliance with the License. You may obtain a copy of the
// License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ============================================================================ //

#pragma once

#ifndef ZTD_TEXT_WINDOWS_1251_HPP
#define ZTD_TEXT_WINDOWS_1251_HPP

#include <ztd/text/version.hpp>

#include <ztd/text/unicode_code_point.hpp>
#include <ztd/text/impl/single_ascii_byte_high_bit_lookup_encoding.hpp>

#include <ztd/encoding_tables/windows_1251.tables.hpp>

#include <ztd/prologue.hpp>

namespace ztd { namespace text {
ZTD_TEXT_INLINE_ABI_NAMESPACE_OPEN_I_

template <typename _CodeUnit = char, typename _CodePoint = unicode_code_point>
class basic_windows_1251
: public __txt_impl::__single_ascii_byte_high_bit_lookup_encoding<basic_windows_1251<_CodeUnit, _CodePoint>,
&::ztd::et::windows_1251_index_to_code_point, &::ztd::et::windows_1251_code_point_to_index, _CodeUnit,
_CodePoint> { };

//////
/// @brief An instance of skip_handler_t for ease of use.
inline constexpr basic_windows_1251<char> windows_1251 = {};

ZTD_TEXT_INLINE_ABI_NAMESPACE_CLOSE_I_
}} // namespace ztd::text


#include <ztd/epilogue.hpp>

#endif

0 comments on commit 6c5d7ba

Please sign in to comment.