simdutf  5.6.3
Unicode at GB/s.
error.h
1 #ifndef SIMDUTF_ERROR_H
2 #define SIMDUTF_ERROR_H
3 namespace simdutf {
4 
5 enum error_code {
6  SUCCESS = 0,
7  HEADER_BITS, // Any byte must have fewer than 5 header bits.
8  TOO_SHORT, // The leading byte must be followed by N-1 continuation bytes,
9  // where N is the UTF-8 character length This is also the error
10  // when the input is truncated.
11  TOO_LONG, // We either have too many consecutive continuation bytes or the
12  // string starts with a continuation byte.
13  OVERLONG, // The decoded character must be above U+7F for two-byte characters,
14  // U+7FF for three-byte characters, and U+FFFF for four-byte
15  // characters.
16  TOO_LARGE, // The decoded character must be less than or equal to
17  // U+10FFFF,less than or equal than U+7F for ASCII OR less than
18  // equal than U+FF for Latin1
19  SURROGATE, // The decoded character must be not be in U+D800...DFFF (UTF-8 or
20  // UTF-32) OR a high surrogate must be followed by a low surrogate
21  // and a low surrogate must be preceded by a high surrogate
22  // (UTF-16) OR there must be no surrogate at all (Latin1)
23  INVALID_BASE64_CHARACTER, // Found a character that cannot be part of a valid
24  // base64 string. This may include a misplaced
25  // padding character ('=').
26  BASE64_INPUT_REMAINDER, // The base64 input terminates with a single
27  // character, excluding padding (=).
28  BASE64_EXTRA_BITS, // The base64 input terminates with non-zero
29  // padding bits.
30  OUTPUT_BUFFER_TOO_SMALL, // The provided buffer is too small.
31  OTHER // Not related to validation/transcoding.
32 };
33 
34 struct result {
35  error_code error;
36  size_t count; // In case of error, indicates the position of the error. In
37  // case of success, indicates the number of code units
38  // validated/written.
39 
40  simdutf_really_inline result() : error{error_code::SUCCESS}, count{0} {}
41 
42  simdutf_really_inline result(error_code err, size_t pos)
43  : error{err}, count{pos} {}
44 };
45 
46 struct full_result {
47  error_code error;
48  size_t input_count;
49  size_t output_count;
50 
51  simdutf_really_inline full_result()
52  : error{error_code::SUCCESS}, input_count{0}, output_count{0} {}
53 
54  simdutf_really_inline full_result(error_code err, size_t pos_in,
55  size_t pos_out)
56  : error{err}, input_count{pos_in}, output_count{pos_out} {}
57 
58  simdutf_really_inline operator result() const noexcept {
59  if (error == error_code::SUCCESS ||
60  error == error_code::BASE64_INPUT_REMAINDER) {
61  return result{error, output_count};
62  } else {
63  return result{error, input_count};
64  }
65  }
66 };
67 
68 } // namespace simdutf
69 #endif