diff options
| author | John Schmidt <john.schmidt.h@gmail.com> | 2014-05-31 13:02:29 +0200 |
|---|---|---|
| committer | John <john.schmidt.h@gmail.com> | 2014-06-30 18:50:32 +0200 |
| commit | 3d84b4be3d7691026993d5c733bc26cc637e7c50 (patch) | |
| tree | a86da659fa4c8602ffe111ba4004afca011b9ff5 /src/libstd | |
| parent | b569c77148e8e839b38b678c7c167efc643d2721 (diff) | |
| download | rust-3d84b4be3d7691026993d5c733bc26cc637e7c50.tar.gz rust-3d84b4be3d7691026993d5c733bc26cc637e7c50.zip | |
Add `utf16_units`
This deprecates `.to_utf16`. `x.to_utf16()` should be replaced by either `x.utf16_units().collect::<Vec<u16>>()` (the type annotation may be optional), or just `x.utf16_units()` directly, if it can be used in an iterator context. Closes #14358 [breaking-change]
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/dynamic_lib.rs | 7 | ||||
| -rw-r--r-- | src/libstd/os.rs | 14 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index ec2cc67a60a..728875ce260 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -281,19 +281,22 @@ pub mod dl { #[cfg(target_os = "win32")] pub mod dl { use c_str::ToCStr; + use iter::Iterator; use libc; use os; use ptr; use result::{Ok, Err, Result}; - use str::StrAllocating; + use str::StrSlice; use str; use string::String; + use vec::Vec; pub unsafe fn open_external<T: ToCStr>(filename: T) -> *mut u8 { // Windows expects Unicode data let filename_cstr = filename.to_c_str(); let filename_str = str::from_utf8(filename_cstr.as_bytes_no_nul()).unwrap(); - let filename_str = filename_str.to_utf16().append_one(0); + let filename_str: Vec<u16> = filename_str.utf16_units().collect(); + let filename_str = filename_str.append_one(0); LoadLibraryW(filename_str.as_ptr() as *const libc::c_void) as *mut u8 } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 90f4cbb2577..be3b6be57b3 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -365,7 +365,8 @@ pub fn getenv(n: &str) -> Option<String> { unsafe { with_env_lock(|| { use os::win32::{fill_utf16_buf_and_decode}; - let n = n.to_utf16().append_one(0); + let n: Vec<u16> = n.utf16_units().collect(); + let n = n.append_one(0); fill_utf16_buf_and_decode(|buf, sz| { libc::GetEnvironmentVariableW(n.as_ptr(), buf, sz) }) @@ -411,8 +412,10 @@ pub fn setenv(n: &str, v: &str) { #[cfg(windows)] fn _setenv(n: &str, v: &str) { - let n = n.to_utf16().append_one(0); - let v = v.to_utf16().append_one(0); + let n: Vec<u16> = n.utf16_units().collect(); + let n = n.append_one(0); + let v: Vec<u16> = v.utf16_units().collect(); + let v = v.append_one(0); unsafe { with_env_lock(|| { libc::SetEnvironmentVariableW(n.as_ptr(), v.as_ptr()); @@ -437,7 +440,8 @@ pub fn unsetenv(n: &str) { #[cfg(windows)] fn _unsetenv(n: &str) { - let n = n.to_utf16().append_one(0); + let n: Vec<u16> = n.utf16_units().collect(); + let n = n.append_one(0); unsafe { with_env_lock(|| { libc::SetEnvironmentVariableW(n.as_ptr(), ptr::null()); @@ -804,7 +808,7 @@ pub fn change_dir(p: &Path) -> bool { #[cfg(windows)] fn chdir(p: &Path) -> bool { let p = match p.as_str() { - Some(s) => s.to_utf16().append_one(0), + Some(s) => s.utf16_units().collect::<Vec<u16>>().append_one(0), None => return false, }; unsafe { |
