Skip to content

Commit edee586

Browse files
committed
Add outline of encoding code
1 parent 4b8e8a0 commit edee586

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

common/src/encodings.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,45 @@ fn unicode_encode_ucs1<E: ErrorHandler>(
119119
_errors: &E,
120120
_encoding_name: &str,
121121
) -> Result<Vec<u8>, E::Error> {
122-
todo!("handle_encode_error")
122+
todo!("handle encode error");
123+
// let limit: u32 = match encoding_name {
124+
// "latin-1" => 256,
125+
// "ascii" => 128,
126+
// _ => 0, // inappropriate encoding got passed here
127+
// };
128+
// let reason = format!("ordinal not in range({})", limit);
129+
130+
// if s.is_empty() {
131+
// return Ok(Vec::<u8>::new());
132+
// }
133+
134+
// let mut out = Vec::<u8>::with_capacity(s.len());
135+
// let mut skip_until: usize = 0;
136+
137+
// for (i, c) in s.chars().enumerate() {
138+
// if i < skip_until {
139+
// continue;
140+
// }
141+
142+
// if (c as u32) < limit {
143+
// out.push(c as u8); // here, `limit` is constrained to at most 256
144+
// } else {
145+
// let coll_start = i;
146+
// let coll_end = s
147+
// .chars()
148+
// .enumerate()
149+
// .skip(i)
150+
// .find(|(_, x)| (*x as u32) < limit)
151+
// .unwrap_or((s.len(), '\0'))
152+
// .0;
153+
// skip_until = coll_end + 1;
154+
// let _reduse, recycle = errors.handle_encode_error(col_start..=col_end, reason)
155+
// // et cetera...
156+
// // see https://foss.heptapod.net/pypy/pypy/-/blob/branch/py3.8/rpython/rlib/runicode.py#L1265
157+
// }
158+
// }
159+
160+
// Ok(out)
123161
}
124162

125163
pub mod latin_1 {

0 commit comments

Comments
 (0)