-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathstandard_library_externs.rs
83 lines (81 loc) · 3.37 KB
/
standard_library_externs.rs
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
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Annotation to ignore the case of this module
use crate::r#_Wrappers_Compile;
use crate::implementation_from_dafny::UTF8;
impl crate::implementation_from_dafny::UTF8::_default {
pub fn Encode(
s: &::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
) -> ::std::rc::Rc<
r#_Wrappers_Compile::Result<
UTF8::ValidUTF8Bytes,
::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
>,
> {
let v = s.to_array();
let mut _accumulator: Vec<u8> = vec![];
// Use of .encode_utf8 method.
let mut surrogate: Option<u16> = None;
for c in v.iter() {
let s = if let Some(s) = surrogate {
String::from_utf16(&[s, c.0])
} else {
String::from_utf16(&[c.0])
};
surrogate = None;
match s {
Ok(value) => {
_accumulator.extend(value.as_bytes());
continue;
}
Err(e) => {
if 0xD800 <= c.0 && c.0 <= 0xDFFF {
surrogate = Some(c.0);
continue;
}
return ::std::rc::Rc::new(r#_Wrappers_Compile::Result::<UTF8::ValidUTF8Bytes, ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>>::Failure {
error: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(
&e.to_string())
});
}
}
}
if let Some(s) = surrogate {
return ::std::rc::Rc::new(r#_Wrappers_Compile::Result::<UTF8::ValidUTF8Bytes, ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>>::Failure {
error: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(
&format!("Surrogate pair missing: 0x{:04x}", s))
});
}
::std::rc::Rc::new(r#_Wrappers_Compile::Result::<
UTF8::ValidUTF8Bytes,
::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
>::Success {
value: ::dafny_runtime::Sequence::from_array_owned(_accumulator),
})
}
pub fn Decode(
b: &::dafny_runtime::Sequence<u8>,
) -> ::std::rc::Rc<
r#_Wrappers_Compile::Result<
::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
>,
> {
let b = String::from_utf8(b.to_array().as_ref().clone());
match b {
Ok(s) => {
::std::rc::Rc::new(r#_Wrappers_Compile::Result::<::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>>::Success {
value: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&s)
})
},
Err(e) => {
return ::std::rc::Rc::new(r#_Wrappers_Compile::Result::<::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>>::Failure {
error: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(
&e.to_string())
})
}
}
}
}