maplibre/legacy/util/
i18n.rs

1//! Translated from https://github.com/maplibre/maplibre-native/blob/4add9ea/src/mbgl/util/i18n.cpp
2
3use widestring::U16String;
4
5use crate::legacy::bidi::Char16;
6
7/// maplibre/maplibre-native#4add9ea original name: allowsWordBreaking
8pub fn allows_word_breaking(chr: Char16) -> bool {
9    chr == 0x0a      /* newline */
10        || chr == 0x20   /* space */
11        || chr == 0x26   /* ampersand */
12        || chr == 0x28   /* open parenthesis */
13        || chr == 0x29   /* close parenthesis */
14        || chr == 0x2b   /* plus sign */
15        || chr == 0x2d   /* hyphen-minus */
16        || chr == 0x2f   /* solidus */
17        || chr == 0xad   /* soft hyphen */
18        || chr == 0xb7   /* middle dot */
19        || chr == 0x200b /* zero-width space */
20        || chr == 0x2010 /* hyphen */
21        || chr == 0x2013
22}
23
24/// maplibre/maplibre-native#4add9ea original name: charAllowsLetterSpacing
25pub fn char_allows_letter_spacing(chr: Char16) -> bool {
26    return false;
27    todo!()
28}
29
30/// maplibre/maplibre-native#4add9ea original name: allowsLetterSpacing
31pub fn allows_letter_spacing(string: &U16String) -> bool {
32    return false;
33    todo!()
34}
35
36/// maplibre/maplibre-native#4add9ea original name: allowsIdeographicBreaking_str
37pub fn allows_ideographic_breaking_str(string: &U16String) -> bool {
38    return false;
39    todo!()
40}
41
42/// maplibre/maplibre-native#4add9ea original name: allowsIdeographicBreaking
43pub fn allows_ideographic_breaking(chr: Char16) -> bool {
44    return false;
45    todo!()
46}
47
48/// maplibre/maplibre-native#4add9ea original name: allowsFixedWidthGlyphGeneration
49pub fn allows_fixed_width_glyph_generation(chr: Char16) -> bool {
50    return false;
51    todo!()
52}
53
54/// maplibre/maplibre-native#4add9ea original name: allowsVerticalWritingMode
55pub fn allows_vertical_writing_mode(string: &U16String) -> bool {
56    return false;
57    todo!()
58}
59
60// The following logic comes from
61// <http://www.unicode.org/Public/12.0.0/ucd/VerticalOrientation.txt>.
62// Keep it synchronized with
63// <http://www.unicode.org/Public/UCD/latest/ucd/VerticalOrientation.txt>.
64// The data file denotes with “U” or “Tu” any codepoint that may be drawn
65// upright in vertical text but does not distinguish between upright and
66// “neutral” characters.
67
68/// maplibre/maplibre-native#4add9ea original name: hasUprightVerticalOrientation
69pub fn has_upright_vertical_orientation(chr: Char16) -> bool {
70    return false;
71    todo!()
72}
73
74/// maplibre/maplibre-native#4add9ea original name: hasNeutralVerticalOrientation
75pub fn has_neutral_vertical_orientation(chr: Char16) -> bool {
76    return false;
77    todo!()
78}
79
80/// maplibre/maplibre-native#4add9ea original name: hasRotatedVerticalOrientation
81pub fn has_rotated_vertical_orientation(chr: Char16) -> bool {
82    !(has_upright_vertical_orientation(chr) || has_neutral_vertical_orientation(chr))
83}
84
85// Replaces "horizontal" with "vertical" punctuation in place
86// Does not re-order or change length of string
87// (TaggedString::verticalizePunctuation depends on this behavior)
88/// maplibre/maplibre-native#4add9ea original name: verticalizePunctuation_str
89pub fn verticalize_punctuation_str(input: &U16String) -> U16String {
90    return input.clone();
91    todo!()
92}
93
94/// maplibre/maplibre-native#4add9ea original name: verticalizePunctuation
95pub fn verticalize_punctuation(chr: Char16) -> Char16 {
96    return 0;
97    todo!()
98}
99
100/// maplibre/maplibre-native#4add9ea original name: charInSupportedScript
101pub fn char_in_supported_script(chr: Char16) -> bool {
102    return true;
103    todo!()
104}
105
106/// maplibre/maplibre-native#4add9ea original name: isStringInSupportedScript
107pub fn is_string_in_supported_script(input: &str) -> bool {
108    let u16string = U16String::from(input); // TODO: verify if this is correct
109    for chr in u16string.as_slice() {
110        if !char_in_supported_script(*chr) {
111            return false;
112        }
113    }
114    true
115}
116
117/// maplibre/maplibre-native#4add9ea original name: isCharInComplexShapingScript
118pub fn is_char_in_complex_shaping_script(chr: Char16) -> bool {
119    false
120}
121
122pub const BACKSLACK_V: Char16 = '\u{000B}' as Char16;
123pub const BACKSLACK_F: Char16 = '\u{000C}' as Char16;
124
125/// maplibre/maplibre-native#4add9ea original name: isWhitespace
126pub fn is_whitespace(chr: Char16) -> bool {
127    // TODO verify that his is correct \v and \f where not available
128    chr == ' ' as Char16
129        || chr == '\t' as Char16
130        || chr == '\n' as Char16
131        || chr == BACKSLACK_V
132        || chr == BACKSLACK_F
133        || chr == '\r' as Char16
134}