HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
exception_intf.hpp
1// Copyright Take Vos 2020-2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
8#pragma once
9
10#include "../macros.hpp"
11#include <exception>
12#include <stdexcept>
13#include <bit>
14#include <format>
15#include <atomic>
16
17hi_export_module(hikogui.utility.exception : intf);
18
19hi_export namespace hi { inline namespace v1 {
20
26[[nodiscard]] std::string get_last_error_message(uint32_t error_code);
27
33
48public:
50
59 template<typename It, typename... Args>
60 [[nodiscard]] constexpr parse_error(It first, It last, int tab_size, char const *msg, Args const&...args) noexcept :
61 runtime_error(make_what(first, last, tab_size, msg, args...))
62 {
63 }
64
72 template<typename It, typename... Args>
73 [[nodiscard]] constexpr parse_error(It first, It last, char const *msg, Args const&...args) noexcept :
74 parse_error(first, last, 8, msg, args...)
75 {
76 }
77
85 template<typename It>
86 [[nodiscard]] constexpr static std::pair<size_t, size_t> get_line_position(It first, It last, size_t tab_size) noexcept
87 {
88 auto line_nr = 0_uz;
89 auto column_nr = 0_uz;
90
91 auto c32 = char32_t{};
92 auto continue_count = int{};
93 while (first != last) {
94 hilet c8 = char_cast<char8_t>(*first++);
95
96 if ((c8 & 0xc0) == 0x80) {
98 c32 <<= 6;
99 c32 |= c8 & 0x3f;
100
101 } else if (c8 & 0x80) {
102 continue_count = std::countl_one(c8) - 1;
103 c32 = c8 & (0b00'111'111 >> continue_count);
104
105 } else {
106 continue_count = 0;
107 c32 = c8;
108 }
109
110 if (not continue_count) {
111 ++column_nr;
112 switch (c32) {
113 case '\n':
114 case '\v':
115 case '\f':
116 case U'\u0085':
117 case U'\u2028':
118 case U'\u2029':
119 ++line_nr;
120 [[fallthrough]];
121 case '\r':
122 column_nr = 0;
123 break;
124 case '\t':
125 column_nr /= tab_size;
126 column_nr *= tab_size;
127 break;
128 default:;
129 }
130 }
131 }
132
133 return {line_nr, column_nr};
134 }
135
136private:
137 template<typename It, typename... Args>
138 [[nodiscard]] constexpr static std::string
139 make_what(It first, It last, size_t tab_size, char const *msg, Args const&...args) noexcept
140 {
141 hilet[line_nr, column_nr] = get_line_position(first, last, tab_size);
142 return {std::format("{}:{}: {}", line_nr + 1, column_nr + 1, std::format(msg, args...))};
143 }
144};
145
149public:
151};
152
161public:
163};
164
173public:
175};
176
184public:
186};
187
189public:
191};
192
194public:
196};
197
199public:
201};
202
204public:
206};
207
208class uri_error : public parse_error {
209public:
211};
212
218public:
220};
221
222}} // namespace hi::v1
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
std::string get_last_error_message()
Get the OS error message from the last error received on this thread.
Definition exception_win32_impl.hpp:31
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Exception thrown during parsing on an error.
Definition exception_intf.hpp:47
constexpr parse_error(It first, It last, char const *msg, Args const &...args) noexcept
Create a parse error at a specific point in UTF-8 encoded text.
Definition exception_intf.hpp:73
static constexpr std::pair< size_t, size_t > get_line_position(It first, It last, size_t tab_size) noexcept
Get the line and column position of an iterator in a UTF-8 string.
Definition exception_intf.hpp:86
constexpr parse_error(It first, It last, int tab_size, char const *msg, Args const &...args) noexcept
Create a parse error at a specific point in UTF-8 encoded text.
Definition exception_intf.hpp:60
Exception thrown when an item was not found.
Definition exception_intf.hpp:148
Exception thrown during execution of a dynamic operation.
Definition exception_intf.hpp:160
Exception thrown during I/O on an error.
Definition exception_intf.hpp:172
Exception thrown during an operating system call.
Definition exception_intf.hpp:183
Definition exception_intf.hpp:188
Definition exception_intf.hpp:193
Definition exception_intf.hpp:198
Definition exception_intf.hpp:203
Definition exception_intf.hpp:208
Cancel error is caused by user pressing cancel.
Definition exception_intf.hpp:217