1// Copyright 2019 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
1415// Notes:
16// * deref_nullptr: since rustc 1.53, bindgen causes UB warnings -- see
17// https://github.com/rust-lang/rust-bindgen/issues/1651 remove this once bindgen has fixed the
18// issue (currently at version 1.59.1)
19#![allow(
20 dead_code,
21 non_snake_case,
22 non_camel_case_types,
23 non_upper_case_globals,
24 unused_imports,
25 rustdoc::bare_urls,
26 deref_nullptr
27)]
2829#[cfg(all(feature = "icu_version_in_env", feature = "icu_config"))]
30compile_error!(
31"Features `icu_version_in_env` and `icu_config` are not compatible."
32+ " Choose at most one of them."
33);
3435#[cfg(all(feature = "icu_config", not(feature = "use-bindgen")))]
36compile_error!("Feature `icu_config` is useless without the feature `use-bindgen`");
3738// This feature combination is not inherrently a problem; we had no use case that
39// required it just yet.
40#[cfg(all(not(feature = "renaming"), not(feature = "use-bindgen")))]
41compile_error!("You must use `renaming` when not using `use-bindgen`");
4243#[cfg(feature = "use-bindgen")]
44include!(concat!(env!("OUT_DIR"), "/macros.rs"));
45#[cfg(all(
46 feature = "use-bindgen",
47 feature = "icu_config",
48 not(feature = "icu_version_in_env")
49))]
50include!(concat!(env!("OUT_DIR"), "/lib.rs"));
5152#[cfg(not(feature = "use-bindgen"))]
53include!("../bindgen/macros.rs");
5455#[cfg(all(
56 not(feature = "use-bindgen"),
57 not(feature = "icu_version_in_env"),
58 not(feature = "icu_config")
59))]
60include!("../bindgen/lib.rs");
6162#[cfg(all(
63 not(feature = "use-bindgen"),
64 feature = "icu_version_in_env",
65 not(feature = "icu_config")
66))]
67include!(concat!(
68"../bindgen/lib_",
69env!("RUST_ICU_MAJOR_VERSION_NUMBER"),
70".rs"
71));
7273// Add the ability to print the error code, so that it can be reported in
74// aggregated errors.
75impl std::fmt::Display for UErrorCode {
76fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
77write!(f, "{:?}", self)
78 }
79}
8081extern crate libc;
8283impl From<i8> for UCharCategory {
84fn from(value: i8) -> Self {
85match value {
860 => UCharCategory::U_UNASSIGNED,
871 => UCharCategory::U_UPPERCASE_LETTER,
882 => UCharCategory::U_LOWERCASE_LETTER,
893 => UCharCategory::U_TITLECASE_LETTER,
904 => UCharCategory::U_MODIFIER_LETTER,
915 => UCharCategory::U_OTHER_LETTER,
926 => UCharCategory::U_NON_SPACING_MARK,
937 => UCharCategory::U_ENCLOSING_MARK,
948 => UCharCategory::U_COMBINING_SPACING_MARK,
959 => UCharCategory::U_DECIMAL_DIGIT_NUMBER,
9610 => UCharCategory::U_LETTER_NUMBER,
9711 => UCharCategory::U_OTHER_NUMBER,
9812 => UCharCategory::U_SPACE_SEPARATOR,
9913 => UCharCategory::U_LINE_SEPARATOR,
10014 => UCharCategory::U_PARAGRAPH_SEPARATOR,
10115 => UCharCategory::U_CONTROL_CHAR,
10216 => UCharCategory::U_FORMAT_CHAR,
10317 => UCharCategory::U_PRIVATE_USE_CHAR,
10418 => UCharCategory::U_SURROGATE,
10519 => UCharCategory::U_DASH_PUNCTUATION,
10620 => UCharCategory::U_START_PUNCTUATION,
10721 => UCharCategory::U_END_PUNCTUATION,
10822 => UCharCategory::U_CONNECTOR_PUNCTUATION,
10923 => UCharCategory::U_OTHER_PUNCTUATION,
11024 => UCharCategory::U_MATH_SYMBOL,
11125 => UCharCategory::U_CURRENCY_SYMBOL,
11226 => UCharCategory::U_MODIFIER_SYMBOL,
11327 => UCharCategory::U_OTHER_SYMBOL,
11428 => UCharCategory::U_INITIAL_PUNCTUATION,
11529 => UCharCategory::U_FINAL_PUNCTUATION,
11630 => UCharCategory::U_CHAR_CATEGORY_COUNT,
117_ => {
118panic!("could not convert: {}", value);
119 }
120 }
121 }
122}
123124// Items used by the `versioned_function!` macro. Unstable private API; do not use.
125#[doc(hidden)]
126pub mod __private_do_not_use {
127pub extern crate paste;
128}