Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Character.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
7#include "Stroika/Foundation/Execution/Exceptions.h"
8
9#include "Character.h"
10
11using namespace Stroika::Foundation;
13
14// see Satisfies Concepts:
15static_assert (regular<Character>);
16
17/*
18 ********************************************************************************
19 **************** Private_::ThrowSurrogatesOutOfRange_ **************************
20 ********************************************************************************
21 */
22void Characters::Private_::ThrowSurrogatesOutOfRange_ ()
23{
24 static const auto kException_ = Execution::RuntimeErrorException<out_of_range>{"UNICODE char16_t surrogates out of range"sv};
25 Execution::Throw (kException_);
26}
27
28/*
29 ********************************************************************************
30 ************************** Private_::ThrowNotIsASCII_ **************************
31 ********************************************************************************
32 */
33void Characters::Private_::ThrowNotIsASCII_ ()
34{
35 static const auto kException_ = Execution::RuntimeErrorException{"Argument not valid ASCII"sv};
36 Execution::Throw (kException_);
37}
38
39/*
40 ********************************************************************************
41 ************************** Private_::ThrowNotIsLatin1_ *************************
42 ********************************************************************************
43 */
44void Characters::Private_::ThrowNotIsLatin1_ ()
45{
46 static const auto kException_ = Execution::RuntimeErrorException{"Argument not valid Latin1 (UNICODE code point > U+00ff)"sv};
47 Execution::Throw (kException_);
48}
49
50/*
51 ********************************************************************************
52 ************************************ Character *********************************
53 ********************************************************************************
54 */
55template <>
56void Character::AsHelper_ (Memory::StackBuffer<char8_t>* buf) const
57{
58 RequireNotNull (buf);
59 buf->resize_uninitialized (4); // enuf
60 char32_t thisC = GetCharacterCode ();
61 auto s = UTFConvert::kThe.ConvertSpan (span{&thisC, 1}, span{*buf});
62 buf->ShrinkTo (s.size ());
63}
64
65template <>
66void Character::AsHelper_ (Memory::StackBuffer<char16_t>* buf) const
67{
68 RequireNotNull (buf);
69 buf->resize_uninitialized (4); // enuf
70 char32_t thisC = GetCharacterCode ();
71 auto s = UTFConvert::kThe.ConvertSpan (span{&thisC, 1}, span{*buf});
72 buf->ShrinkTo (s.size ());
73}
#define RequireNotNull(p)
Definition Assertions.h:347
constexpr char32_t GetCharacterCode() const noexcept
Return the char32_t UNICODE code-point associated with this character.
static const UTFConvert kThe
Nearly always use this default UTFConvert.
Definition UTFConvert.h:369
nonvirtual span< TRG_T > ConvertSpan(span< const SRC_T > source, span< TRG_T > target) const
Convert between UTF-N encoded (including the special case of ASCII, and Latin1) character spans (e....
Logically halfway between std::array and std::vector; Smart 'direct memory array' - which when needed...
nonvirtual void ShrinkTo(size_t nElements)
nonvirtual void resize_uninitialized(size_t nElements)
same as resize (), except leaves newly created elements uninitialized (requires is_trivially_copyable...
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...
Definition Throw.inl:43