Skip to content

Commit

Permalink
💣 Remove sub_view; not used!
Browse files Browse the repository at this point in the history
- 🍷 Enjoy polishing off the last of the derps and the bugs
- ✨ Publicly expose the reconstruct function
  • Loading branch information
ThePhD committed Jun 25, 2021
1 parent 0c56962 commit 39ea6d6
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 235 deletions.
62 changes: 36 additions & 26 deletions include/ztd/text/basic_c_string_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
namespace ztd { namespace text {
ZTD_TEXT_INLINE_ABI_NAMESPACE_OPEN_I_

//////
/// @brief A sentinel type for ztd::text::basic_c_string_view. Provides additional type safety.
///
//////
class c_string_sentinel_t {};

//////
/// @brief An instance of the c_string_sentinel_t type, for ease of use.
///
//////
inline constexpr c_string_sentinel_t c_string_sentinel = {};

//////
/// @brief A class that is identical to std::string_view, except that it attempts to verify and guarantee that
/// ``.data() + .size()``, when dereferenced, is valid and gives a nullptr. The ``.size()`` does not include the
Expand Down Expand Up @@ -246,6 +258,30 @@ namespace ztd { namespace text {
using __base_t::find_first_of;
using __base_t::find_last_not_of;
using __base_t::find_last_of;

template <typename _It, typename _Sen>
friend constexpr __base_t reconstruct(
::std::in_place_type_t<basic_c_string_view>, _It __iterator, _Sen __sentinel) {
using _SizeType = typename __base_t::size_type;
if constexpr (!::std::is_integral_v<_Sen>) {
#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL >= 1
if (__iterator == __sentinel) {
const auto& __empty_str = __txt_detail::__empty_string<value_type>();
return __base_t(__empty_str + 0, 0);
}
#endif
return __base_t(::std::addressof(*__iterator), static_cast<_SizeType>(__sentinel - __iterator));
}
else {
#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL >= 1
if (static_cast<_SizeType>(__sentinel) == static_cast<_SizeType>(0)) {
const auto& __empty_str = __txt_detail::__empty_string<value_type>();
return __base_t(__empty_str + 0, 0);
}
#endif
return __base_t(::std::addressof(*__iterator), static_cast<_SizeType>(__sentinel));
}
}
};


Expand Down Expand Up @@ -357,32 +393,6 @@ namespace ztd { namespace text {
return __left.compare(__right) >= 0;
}


template <typename _Ty, typename _Traits, typename _It, typename _Sen>
constexpr ::std::basic_string_view<_Ty, _Traits> reconstruct(
::std::in_place_type_t<basic_c_string_view<_Ty, _Traits>>, _It __iterator, _Sen __sentinel) {
using _SizeType = typename ::std::basic_string_view<_Ty, _Traits>::size_type;
if constexpr (!::std::is_integral_v<_Sen>) {
#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL >= 1
if (__iterator == __sentinel) {
const auto& __empty_str = __txt_detail::__empty_string<_Ty>();
return ::std::basic_string_view<_Ty, _Traits>(__empty_str + 0, 0);
}
#endif
return ::std::basic_string_view<_Ty, _Traits>(
::std::addressof(*__iterator), static_cast<_SizeType>(__sentinel - __iterator));
}
else {
#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL >= 1
if (static_cast<_SizeType>(__sentinel) == static_cast<_SizeType>(0)) {
const auto& __empty_str = __txt_detail::__empty_string<_Ty>();
return ::std::basic_string_view<_Ty, _Traits>(__empty_str + 0, 0);
}
#endif
return ::std::basic_string_view<_Ty, _Traits>(
::std::addressof(*__iterator), static_cast<_SizeType>(__sentinel));
}
}
ZTD_TEXT_INLINE_ABI_NAMESPACE_CLOSE_I_
}} // namespace ztd::text

Expand Down
3 changes: 1 addition & 2 deletions include/ztd/text/count_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
#include <ztd/text/char8_t.hpp>
#include <ztd/text/unicode_code_point.hpp>
#include <ztd/text/encoding_error.hpp>

#include <ztd/text/detail/reconstruct.hpp>
#include <ztd/text/reconstruct.hpp>

#include <cstddef>
#include <array>
Expand Down
4 changes: 2 additions & 2 deletions include/ztd/text/decode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
#include <ztd/text/unbounded.hpp>
#include <ztd/text/is_unicode_code_point.hpp>
#include <ztd/text/tag.hpp>
#include <ztd/text/reconstruct.hpp>

#include <ztd/text/detail/is_lossless.hpp>
#include <ztd/text/detail/encoding_range.hpp>
#include <ztd/text/detail/type_traits.hpp>
#include <ztd/text/detail/span.hpp>
#include <ztd/text/detail/reconstruct.hpp>
#include <ztd/text/detail/transcode_one.hpp>

#include <string>
Expand Down Expand Up @@ -203,7 +203,7 @@ namespace ztd { namespace text {
__intermediate_initial_output, ::std::forward<_ErrorHandler>(__error_handler), __state);
_Output __intermediate_output(
__intermediate_initial_output.data(), __result.output.data());
using _SpanIterator = typename ::ztd::text::span<_IntermediateValueType>::iterator;
using _SpanIterator = typename _Output::iterator;
if constexpr (__txt_detail::__is_detected_v<__txt_detail::__detect_insert_bulk, _OutputContainer,
_SpanIterator, _SpanIterator>) {
// inserting in bulk
Expand Down
2 changes: 1 addition & 1 deletion include/ztd/text/decode_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#include <ztd/text/char8_t.hpp>
#include <ztd/text/unicode_code_point.hpp>
#include <ztd/text/encoding_error.hpp>
#include <ztd/text/reconstruct.hpp>

#include <ztd/text/detail/reconstruct.hpp>
#include <ztd/text/detail/span.hpp>
#include <ztd/text/detail/encoding_range.hpp>

Expand Down
2 changes: 1 addition & 1 deletion include/ztd/text/decode_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <ztd/text/code_point.hpp>

#include <ztd/text/subrange.hpp>
#include <ztd/text/detail/reconstruct.hpp>
#include <ztd/text/reconstruct.hpp>

#include <string_view>

Expand Down
2 changes: 1 addition & 1 deletion include/ztd/text/detail/iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace ztd { namespace text {
template <typename _It>
inline constexpr bool __is_iterator_contiguous_iterator_v = (
#if ZTD_TEXT_IS_ON(ZTD_TEXT_STD_LIBRARY_CONTIGUOUS_ITERATOR_TAG_I_)
__is_iterator_concept_or_better_v<contiguous_iterator_tag, _It> &&
__is_iterator_concept_or_better_v<contiguous_iterator_tag, _It>) || (__is_iterator_concept_or_better_v<contiguous_iterator_tag, _It> &&
#else
::std::is_pointer_v<_It> &&
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/ztd/text/detail/span.implementation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ namespace nonstd { namespace span_lite {
/*enum*/ struct enabler { };

template <typename T>
bool is_positive(T x) {
constexpr bool is_positive(T x) {
return std11::is_signed<T>::value ? x >= 0 : true;
}

Expand Down
176 changes: 0 additions & 176 deletions include/ztd/text/detail/subview.hpp

This file was deleted.

21 changes: 12 additions & 9 deletions include/ztd/text/detail/transcode_one.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ namespace ztd { namespace text {
// convertible to one another");


_WorkingIntermediate __working_intermediate = __span_or_reconstruct(__intermediate);
_WorkingIntermediate __working_output = __span_or_reconstruct(__intermediate);
auto __intermediate_result = __basic_decode_one<__consume::__no>(::std::forward<_Input>(__input),
__from_encoding, __working_intermediate, __from_error_handler, __from_state);
__from_encoding, __working_output, __from_error_handler, __from_state);
if (__intermediate_result.error_code != encoding_error::ok) {
#if 0
if constexpr (::std::is_same_v<__range_iterator_t<_OutputView>, __blackhole_iterator>) {
Expand All @@ -364,9 +364,9 @@ namespace ztd { namespace text {
}
#endif
}
_WorkingIntermediate __intermediate_view = __reconstruct(::std::in_place_type<_WorkingIntermediate>,
__adl::__adl_begin(__working_intermediate), __adl::__adl_begin(__intermediate_result.output));
auto __end_result = __basic_encode_one<_ConsumeIntoTheNothingness>(::std::move(__intermediate_view),
_WorkingIntermediate __working_input = __reconstruct(::std::in_place_type<_WorkingIntermediate>,
__adl::__adl_begin(__working_output), __adl::__adl_begin(__intermediate_result.output));
auto __end_result = __basic_encode_one<_ConsumeIntoTheNothingness>(::std::move(__working_input),
__to_encoding, ::std::forward<_Output>(__output), __to_error_handler, __to_state);

return _Result(::std::move(__intermediate_result.input), ::std::move(__end_result.output),
Expand Down Expand Up @@ -637,7 +637,7 @@ namespace ztd { namespace text {
::std::forward<_Encoding>(__encoding), __output, ::std::forward<_ErrorHandler>(__error_handler),
__state);
::std::size_t __written = static_cast<::std::size_t>(
__adl::__adl_begin(__intermediate_result.output) - __adl::__adl_begin(__output));
__adl::__adl_data(__intermediate_result.output) - __adl::__adl_data(__output));

return _Result(::std::move(__intermediate_result.input), __written, __intermediate_result.state,
__intermediate_result.error_code, __intermediate_result.handled_errors);
Expand Down Expand Up @@ -668,7 +668,7 @@ namespace ztd { namespace text {
::std::forward<_Encoding>(__encoding), __output, ::std::forward<_ErrorHandler>(__error_handler),
__state);
::std::size_t __written = static_cast<::std::size_t>(
__adl::__adl_begin(__intermediate_result.output) - __adl::__adl_begin(__output));
__adl::__adl_data(__intermediate_result.output) - __adl::__adl_data(__output));

return _Result(::std::move(__intermediate_result.input), __written, __intermediate_result.state,
__intermediate_result.error_code, __intermediate_result.handled_errors);
Expand All @@ -681,9 +681,12 @@ namespace ztd { namespace text {
using _IntermediateCodePoint = code_point_t<_UEncoding>;
constexpr ::std::size_t _IntermediateMaxCodePoints = max_code_points_v<_UEncoding>;

_IntermediateCodePoint __intermediate_buffer[_IntermediateMaxCodePoints] {};

_IntermediateCodePoint __intermediate_storage[_IntermediateMaxCodePoints] {};
::ztd::text::span<_IntermediateCodePoint, _IntermediateMaxCodePoints> __intermediate(
__intermediate_storage);
return __basic_count_decodable_one(::std::forward<_Input>(__input),
::std::forward<_Encoding>(__encoding), __intermediate_buffer,
::std::forward<_Encoding>(__encoding), __intermediate,
::std::forward<_ErrorHandler>(__error_handler), __state);
}
} // namespace __txt_detail
Expand Down

0 comments on commit 39ea6d6

Please sign in to comment.