summaryrefslogtreecommitdiffstats
path: root/vendor/icu_provider/src/helpers.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/icu_provider/src/helpers.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/icu_provider/src/helpers.rs')
-rw-r--r--vendor/icu_provider/src/helpers.rs108
1 files changed, 24 insertions, 84 deletions
diff --git a/vendor/icu_provider/src/helpers.rs b/vendor/icu_provider/src/helpers.rs
index 8d499f7ef..998e656da 100644
--- a/vendor/icu_provider/src/helpers.rs
+++ b/vendor/icu_provider/src/helpers.rs
@@ -4,79 +4,6 @@
//! Internal helper functions.
-use alloc::string::String;
-
-/// Prints a JSON-safe string to the output.
-pub fn escape_for_json<'o>(input: &str, output: &'o mut String) -> &'o mut String {
- // From the ECMA-404 specification:
- // "A string is a sequence of Unicode code points wrapped with quotation marks (U+0022).
- // All code points may be placed within the quotation marks except for the code points
- // that must be escaped: quotation mark (U+0022), reverse solidus (U+005C), and the
- // control characters U+0000 to U+001F. There are two-character escape sequence
- // representations of some characters."
- for cp in input.chars() {
- let str_to_append = match cp {
- '\u{0000}' => "\\u0000",
- '\u{0001}' => "\\u0001",
- '\u{0002}' => "\\u0002",
- '\u{0003}' => "\\u0003",
- '\u{0004}' => "\\u0004",
- '\u{0005}' => "\\u0005",
- '\u{0006}' => "\\u0006",
- '\u{0007}' => "\\u0007",
- '\u{0008}' => "\\b",
- '\u{0009}' => "\\t",
- '\u{000A}' => "\\n",
- '\u{000B}' => "\\u000B",
- '\u{000C}' => "\\f",
- '\u{000D}' => "\\r",
- '\u{000E}' => "\\u000E",
- '\u{000F}' => "\\u000F",
- '\u{0010}' => "\\u0010",
- '\u{0011}' => "\\u0011",
- '\u{0012}' => "\\u0012",
- '\u{0013}' => "\\u0013",
- '\u{0014}' => "\\u0014",
- '\u{0015}' => "\\u0015",
- '\u{0016}' => "\\u0016",
- '\u{0017}' => "\\u0017",
- '\u{0018}' => "\\u0018",
- '\u{0019}' => "\\u0019",
- '\u{001A}' => "\\u001A",
- '\u{001B}' => "\\u001B",
- '\u{001C}' => "\\u001C",
- '\u{001D}' => "\\u001D",
- '\u{001E}' => "\\u001E",
- '\u{001F}' => "\\u001F",
- '\u{0022}' => "\\\"",
- '\u{005C}' => "\\\\",
- cp => {
- output.push(cp);
- continue;
- }
- };
- output.push_str(str_to_append);
- }
- output
-}
-
-#[test]
-fn test_escape_for_json() {
- assert_eq!("", escape_for_json("", &mut String::new()));
- assert_eq!("abc", escape_for_json("abc", &mut String::new()));
- assert_eq!("ab\\nc", escape_for_json("ab\nc", &mut String::new()));
- assert_eq!("ab\\\\c", escape_for_json("ab\\c", &mut String::new()));
- assert_eq!("ab\\\"c", escape_for_json("ab\"c", &mut String::new()));
- assert_eq!(
- "ab\\u0000c",
- escape_for_json("ab\u{0000}c", &mut String::new())
- );
- assert_eq!(
- "ab\\u001Fc",
- escape_for_json("ab\u{001F}c", &mut String::new())
- );
-}
-
/// Const function to compute the FxHash of a byte array with little-endian byte order.
///
/// FxHash is a speedy hash algorithm used within rustc. The algorithm is satisfactory for our
@@ -248,7 +175,22 @@ macro_rules! gen_any_buffer_constructors {
}
};
- (locale: skip, $options_arg:ident: $options_ty:path, error: $error_ty:path) => {
+
+ (locale: skip, options: skip, result: $result_ty:path, functions: [$f1:path, $f2:ident, $f3:ident]) => {
+ #[doc = $crate::gen_any_buffer_docs!(ANY, $crate, $f1)]
+ pub fn $f2(provider: &(impl $crate::AnyProvider + ?Sized)) -> $result_ty {
+ use $crate::AsDowncastingAnyProvider;
+ $f1(&provider.as_downcasting())
+ }
+ #[cfg(feature = "serde")]
+ #[doc = $crate::gen_any_buffer_docs!(BUFFER, $crate, $f1)]
+ pub fn $f3(provider: &(impl $crate::BufferProvider + ?Sized)) -> $result_ty {
+ use $crate::AsDeserializingBufferProvider;
+ $f1(&provider.as_deserializing())
+ }
+ };
+
+ (locale: skip, $options_arg:ident: $options_ty:ty, error: $error_ty:path) => {
$crate::gen_any_buffer_constructors!(
locale: skip,
$options_arg: $options_ty,
@@ -260,34 +202,32 @@ macro_rules! gen_any_buffer_constructors {
]
);
};
- (locale: skip, $options_arg:ident: $options_ty:path, error: $error_ty:path, functions: [$f1:path, $f2:ident, $f3:ident]) => {
+ (locale: skip, $options_arg:ident: $options_ty:ty, result: $result_ty:ty, functions: [$f1:path, $f2:ident, $f3:ident]) => {
#[doc = $crate::gen_any_buffer_docs!(ANY, $crate, $f1)]
- pub fn $f2(provider: &(impl $crate::AnyProvider + ?Sized), $options_arg: $options_ty) -> Result<Self, $error_ty> {
+ pub fn $f2(provider: &(impl $crate::AnyProvider + ?Sized), $options_arg: $options_ty) -> $result_ty {
use $crate::AsDowncastingAnyProvider;
$f1(&provider.as_downcasting(), $options_arg)
}
#[cfg(feature = "serde")]
#[doc = $crate::gen_any_buffer_docs!(BUFFER, $crate, $f1)]
- pub fn $f3(provider: &(impl $crate::BufferProvider + ?Sized), $options_arg: $options_ty) -> Result<Self, $error_ty> {
+ pub fn $f3(provider: &(impl $crate::BufferProvider + ?Sized), $options_arg: $options_ty) -> $result_ty {
use $crate::AsDeserializingBufferProvider;
$f1(&provider.as_deserializing(), $options_arg)
}
};
-
- (locale: skip, options: skip, result: $result_ty:path, functions: [$f1:path, $f2:ident, $f3:ident]) => {
+ (locale: skip, $options_arg:ident: $options_ty:ty, error: $error_ty:ty, functions: [$f1:path, $f2:ident, $f3:ident]) => {
#[doc = $crate::gen_any_buffer_docs!(ANY, $crate, $f1)]
- pub fn $f2(provider: &(impl $crate::AnyProvider + ?Sized)) -> $result_ty {
+ pub fn $f2(provider: &(impl $crate::AnyProvider + ?Sized), $options_arg: $options_ty) -> Result<Self, $error_ty> {
use $crate::AsDowncastingAnyProvider;
- $f1(&provider.as_downcasting())
+ $f1(&provider.as_downcasting(), $options_arg)
}
#[cfg(feature = "serde")]
#[doc = $crate::gen_any_buffer_docs!(BUFFER, $crate, $f1)]
- pub fn $f3(provider: &(impl $crate::BufferProvider + ?Sized)) -> $result_ty {
+ pub fn $f3(provider: &(impl $crate::BufferProvider + ?Sized), $options_arg: $options_ty) -> Result<Self, $error_ty> {
use $crate::AsDeserializingBufferProvider;
- $f1(&provider.as_deserializing())
+ $f1(&provider.as_deserializing(), $options_arg)
}
};
-
(locale: include, options: skip, error: $error_ty:path) => {
$crate::gen_any_buffer_constructors!(
locale: include,