Skip to content

Commit 60b149f

Browse files
committed
Export utf8_char_width() publicly in core::std behind the "str_internals" feature gate and use it in sys::windows::stdio instead of reimplementing it there.
1 parent a941e68 commit 60b149f

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

library/core/src/str/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ pub use iter::SplitInclusive;
7171
#[unstable(feature = "str_internals", issue = "none")]
7272
pub use validations::next_code_point;
7373

74+
#[unstable(feature = "str_internals", issue = "none")]
75+
pub use validations::utf8_char_width;
76+
7477
use iter::MatchIndicesInternal;
7578
use iter::SplitInternal;
7679
use iter::{MatchesInternal, SplitNInternal};

library/std/src/sys/windows/stdio.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::str;
88
use crate::sys::c;
99
use crate::sys::cvt;
1010
use crate::sys::handle::Handle;
11+
use core::str::utf8_char_width;
1112

1213
// Don't cache handles but get them fresh for every read/write. This allows us to track changes to
1314
// the value over time (such as if a process calls `SetStdHandle` while it's running). See #40490.
@@ -60,18 +61,6 @@ fn is_console(handle: c::HANDLE) -> bool {
6061
unsafe { c::GetConsoleMode(handle, &mut mode) != 0 }
6162
}
6263

63-
// Simple reimplementation of std::str::utf8_char_width() which is feature-gated
64-
fn utf8_char_width(b: u8) -> usize {
65-
match b {
66-
0x00..=0x7F => 1,
67-
0x80..=0xC1 => 0,
68-
0xC2..=0xDF => 2,
69-
0xE0..=0xEF => 3,
70-
0xF0..=0xF4 => 4,
71-
0xF5..=0xFF => 0,
72-
}
73-
}
74-
7564
fn write(
7665
handle_id: c::DWORD,
7766
data: &[u8],

0 commit comments

Comments
 (0)