1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// Thomas Wang and utf8conv contributors, Copyright 2022
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//!
//! Implementation of UTF 8 / UTF32 converters and converting iterators,
//! including the supporting recognition and translation functions.
//!
//! Works on a single buffer as well as multiple buffers without needing
//! heap allocation.
//!
//! An invalid Unicode decoding sequence is replaced with an Unicode Replacement codepoint.
//!
//! Includes an adapter iterator to filter out Byte Order Mark at the
//! beginning of a stream, and substituting carriage returns with newlines.
//!
//! utf8conv is dual licensed under the Apache 2.0 license, or the MIT license.
//!
//! Source Repository: [link](https://github.com/tttwang23/utf8conv)
//!
//! Credits attribution of utf8conv is located in source directory doc/utf8conv-credits.md.
//!
//! #### Single buffer iterator based parsing
//!
//! ```rust
//! use utf8conv::*;
//!
//! // Single buffer iterator based UTF8 parsing converting to char
//! fn utf8_to_char_single_buffer_iterator() {
//! let mybuffer = "abc".as_bytes();
//! let mut utf8_ref_iter = mybuffer.iter();
//! let mut parser = FromUtf8::new();
//! let mut iterator = parser.utf8_ref_to_char_with_iter(& mut utf8_ref_iter);
//! while let Some(char_val) = iterator.next() {
//! println!("{}", char_val);
//! println!("{}", iterator.has_invalid_sequence());
//! }
//! }
//!
//! // Single buffer iterator based char parsing converting to UTF8
//! fn char_to_utf8_single_buffer_iterator() {
//! let mybuffer = [ '\u{7F}', '\u{80}', '\u{81}', '\u{82}' ];
//! let mut char_ref_iter = mybuffer.iter();
//! let mut parser = FromUnicode::new();
//! let mut iterator = parser.char_ref_to_utf8_with_iter(& mut char_ref_iter);
//! while let Some(utf8_val) = iterator.next() {
//! println!("{:#02x}", utf8_val);
//! println!("{}", iterator.has_invalid_sequence());
//! }
//! }
//! ```
//!
//! #### Multi-buffer iterator based parsing
//!
//! ```rust
//! use utf8conv::*;
//!
//! // Multi-buffer iterator based UTF8 parsing converting to char
//! fn utf8_to_char_multi_buffer_iterator() {
//! let mybuffers = ["ab".as_bytes(), "".as_bytes(), "cde".as_bytes()];
//! let mut parser = FromUtf8::new();
//! for indx in 0 .. mybuffers.len() {
//! parser.set_is_last_buffer(indx == mybuffers.len() - 1);
//! let mut utf8_ref_iter = mybuffers[indx].iter();
//! let mut iterator = parser.utf8_ref_to_char_with_iter(& mut utf8_ref_iter);
//! while let Some(char_val) = iterator.next() {
//! println!("{}", char_val);
//! println!("{}", iterator.has_invalid_sequence());
//! }
//! }
//! }
//!
//! // Multi-buffer iterator based char parsing converting to UTF8
//! fn char_to_utf8_multi_buffer_iterator() {
//! let mybuffers = [[ '\u{7F}', '\u{80}' ] , [ '\u{81}', '\u{82}' ]];
//! let mut parser = FromUnicode::new();
//! for indx in 0 .. mybuffers.len() {
//! parser.set_is_last_buffer(indx == mybuffers.len() - 1);
//! let mut char_ref_iter = mybuffers[indx].iter();
//! let mut iterator = parser.char_ref_to_utf8_with_iter(& mut char_ref_iter);
//! while let Some(utf8_val) = iterator.next() {
//! println!("{:#02x}", utf8_val);
//! println!("{}", iterator.has_invalid_sequence());
//! }
//! }
//! }
//! ```
//!
//! #### Single-buffer slice based parsing
//!
//! ```rust
//! use utf8conv::*;
//!
//! // Single-buffer slice reading based UTF8 parsing converting to char
//! fn utf8_to_char_single_buffer_slice_reading() {
//! let mybuffer = "Wxyz".as_bytes();
//! let mut parser = FromUtf8::new();
//! let mut cur_slice = mybuffer;
//! loop {
//! match parser.utf8_to_char(cur_slice) {
//! Result::Ok((slice_pos, char_val)) => {
//! cur_slice = slice_pos;
//! println!("{}", char_val);
//! println!("{}", parser.has_invalid_sequence());
//! }
//! Result::Err(MoreEnum::More(_amt)) => {
//! // _amt equals to 0 when end of data
//! break;
//! }
//! }
//! }
//! }
//!
//! // Single-buffer slice reading based UTF32 parsing converting to UTF8
//! fn utf32_to_utf8_single_buffer_slice_reading() {
//! let mybuffer = [0x7Fu32, 0x80u32, 0x81u32, 0x82u32];
//! let mut parser = FromUnicode::new();
//! let mut current_slice = & mybuffer[..];
//! loop {
//! match parser.utf32_to_utf8(current_slice) {
//! Result::Ok((slice_pos, utf8_val)) => {
//! current_slice = slice_pos;
//! println!("{:02x}", utf8_val);
//! println!("{}", parser.has_invalid_sequence());
//! }
//! Result::Err(MoreEnum::More(_amt)) => {
//! // _amt equals to 0 when end of data
//! break;
//! }
//! }
//! }
//! }
//! ```
//!
//! #### Multi-buffer slice based parsing
//!
//! ```rust
//! use utf8conv::*;
//!
//! // Multi-buffer slice reading based UTF8 parsing converting to char
//! fn utf8_to_char_multi_buffer_slice_reading() {
//! let mybuffers = ["Wx".as_bytes(), "".as_bytes(), "yz".as_bytes()];
//! let mut parser = FromUtf8::new();
//! for indx in 0 .. mybuffers.len() {
//! parser.set_is_last_buffer(indx == mybuffers.len() - 1);
//! let mut cur_slice = mybuffers[indx];
//! loop {
//! match parser.utf8_to_char(cur_slice) {
//! Result::Ok((slice_pos, char_val)) => {
//! cur_slice = slice_pos;
//! println!("{}", char_val);
//! println!("{}", parser.has_invalid_sequence());
//! }
//! Result::Err(MoreEnum::More(_amt)) => {
//! // _amt equals to 0 when end of data
//! break;
//! }
//! }
//! }
//! }
//! }
//!
//! // Multi-buffer slice reading based UTF32 parsing converting to UTF8
//! fn utf32_to_utf8_multi_buffer_slice_reading() {
//! let mybuffers = [[0x7Fu32, 0x80u32], [0x81u32, 0x82u32]];
//! let mut parser = FromUnicode::new();
//! for indx in 0 .. mybuffers.len() {
//! parser.set_is_last_buffer(indx == mybuffers.len() - 1);
//! let current_array = mybuffers[indx];
//! let mut current_slice = & current_array[..];
//! loop {
//! match parser.utf32_to_utf8(current_slice) {
//! Result::Ok((slice_pos, utf8_val)) => {
//! current_slice = slice_pos;
//! println!("{:02x}", utf8_val);
//! println!("{}", parser.has_invalid_sequence());
//! }
//! Result::Err(MoreEnum::More(_amt)) => {
//! // _amt equals to 0 when end of data
//! break;
//! }
//! }
//! }
//! }
//! }
//! ```
extern crate doc_comment;
pub use crateREPLACE_UTF32;
pub use crateREPLACE_PART1;
pub use crateREPLACE_PART2;
pub use crateREPLACE_PART3;
pub use crateFromUtf8;
pub use crateFromUnicode;
pub use crateUtfParserCommon;
pub use crateUtf8IterToCharIter;
pub use crateUtf32IterToUtf8Iter;
pub use crateUtf8RefIterToCharIter;
pub use crateCharRefIterToUtf8Iter;
pub use crateUtf8TypeEnum;
pub use crateUtf8EndEnum;
pub use crateMoreEnum;
pub use crateclassify_utf32;
pub use crateutf8_decode;
pub use cratechar_ref_iter_to_char_iter;
pub use crateutf32_ref_iter_to_utf32_iter;
pub use crateutf8_ref_iter_to_utf8_iter;
pub use cratechar_iter_to_utf32_iter;
pub use cratefilter_bom_and_cr_iter;
pub use crateEightBytes;