2014-09-30 17:03:56 -07:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
2014-11-24 16:21:39 -08:00
|
|
|
//! Implementation of `std::os` functionality for Windows
|
|
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
#![allow(bad_style)]
|
2014-09-30 17:03:56 -07:00
|
|
|
|
2014-12-22 09:04:23 -08:00
|
|
|
use prelude::v1::*;
|
std: Stabilize portions of `std::os::$platform`
This commit starts to organize the `std::os::$platform` modules and in the
process stabilizes some of the functionality contained within. The organization
of these modules will reflect the organization of the standard library itself
with extension traits for primitives in the same corresponding module.
The OS-specific modules will grow more functionality over time including
concrete types that are not extending functionality of other structures, and
these will either go into the closest module in `std::os::$platform` or they
will grow a new module in the hierarchy.
The following items are now stable:
* `os::{unix, windows}`
* `unix::ffi`
* `unix::ffi::OsStrExt`
* `unix::ffi::OsStrExt::{from_bytes, as_bytes, to_cstring}`
* `unix::ffi::OsString`
* `unix::ffi::OsStringExt::{from_vec, into_vec}`
* `unix::process`
* `unix::process::CommandExt`
* `unix::process::CommandExt::{uid, gid}`
* `unix::process::ExitStatusExt`
* `unix::process::ExitStatusExt::signal`
* `unix::prelude`
* `windows::ffi`
* `windows::ffi::OsStringExt`
* `windows::ffi::OsStringExt::from_wide`
* `windows::ffi::OsStrExt`
* `windows::ffi::OsStrExt::encode_wide`
* `windows::prelude`
The following items remain unstable:
* `unix::io`
* `unix::io::{Fd, AsRawFd}`
* `unix::fs::{PermissionsExt, OpenOptionsExt}`
* `windows::io`
* `windows::io::{Handle, AsRawHandle}`
* `windows::io::{Socket, AsRawSocket}`
* `windows::fs`
* `windows::fs::OpenOptionsExt`
Due to the reorgnization of the platform extension modules, this commit is a
breaking change. Most imports can be fixed by adding the relevant libstd module
in the `use` path (such as `ffi` or `fs`).
[breaking-change]
2015-03-13 17:12:38 -07:00
|
|
|
use os::windows::prelude::*;
|
2014-11-24 16:21:39 -08:00
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
use error::Error as StdError;
|
|
|
|
|
use ffi::{OsString, OsStr, AsOsStr};
|
2014-12-31 10:20:31 -08:00
|
|
|
use fmt;
|
2015-02-23 10:59:17 -08:00
|
|
|
use io;
|
2015-01-27 12:20:58 -08:00
|
|
|
use libc::types::os::arch::extra::LPWCH;
|
|
|
|
|
use libc::{self, c_int, c_void};
|
|
|
|
|
use mem;
|
2015-03-11 15:24:14 -07:00
|
|
|
#[allow(deprecated)]
|
2015-01-27 12:20:58 -08:00
|
|
|
use old_io::{IoError, IoResult};
|
2015-02-23 10:59:17 -08:00
|
|
|
use ops::Range;
|
std: Stabilize portions of `std::os::$platform`
This commit starts to organize the `std::os::$platform` modules and in the
process stabilizes some of the functionality contained within. The organization
of these modules will reflect the organization of the standard library itself
with extension traits for primitives in the same corresponding module.
The OS-specific modules will grow more functionality over time including
concrete types that are not extending functionality of other structures, and
these will either go into the closest module in `std::os::$platform` or they
will grow a new module in the hierarchy.
The following items are now stable:
* `os::{unix, windows}`
* `unix::ffi`
* `unix::ffi::OsStrExt`
* `unix::ffi::OsStrExt::{from_bytes, as_bytes, to_cstring}`
* `unix::ffi::OsString`
* `unix::ffi::OsStringExt::{from_vec, into_vec}`
* `unix::process`
* `unix::process::CommandExt`
* `unix::process::CommandExt::{uid, gid}`
* `unix::process::ExitStatusExt`
* `unix::process::ExitStatusExt::signal`
* `unix::prelude`
* `windows::ffi`
* `windows::ffi::OsStringExt`
* `windows::ffi::OsStringExt::from_wide`
* `windows::ffi::OsStrExt`
* `windows::ffi::OsStrExt::encode_wide`
* `windows::prelude`
The following items remain unstable:
* `unix::io`
* `unix::io::{Fd, AsRawFd}`
* `unix::fs::{PermissionsExt, OpenOptionsExt}`
* `windows::io`
* `windows::io::{Handle, AsRawHandle}`
* `windows::io::{Socket, AsRawSocket}`
* `windows::fs`
* `windows::fs::OpenOptionsExt`
Due to the reorgnization of the platform extension modules, this commit is a
breaking change. Most imports can be fixed by adding the relevant libstd module
in the `use` path (such as `ffi` or `fs`).
[breaking-change]
2015-03-13 17:12:38 -07:00
|
|
|
use os::windows::ffi::EncodeWide;
|
2015-02-23 10:59:17 -08:00
|
|
|
use path::{self, PathBuf};
|
2014-12-15 06:03:00 +02:00
|
|
|
use ptr;
|
2014-12-14 00:05:32 -08:00
|
|
|
use slice;
|
2015-01-27 12:20:58 -08:00
|
|
|
use sys::c;
|
2014-12-30 18:51:51 -08:00
|
|
|
use sys::fs::FileDesc;
|
2015-01-27 12:20:58 -08:00
|
|
|
use sys::handle::Handle as RawHandle;
|
2014-09-30 17:03:56 -07:00
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
use libc::funcs::extra::kernel32::{
|
|
|
|
|
GetEnvironmentStringsW,
|
|
|
|
|
FreeEnvironmentStringsW
|
|
|
|
|
};
|
2014-11-24 16:21:39 -08:00
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
pub fn errno() -> i32 {
|
|
|
|
|
unsafe { libc::GetLastError() as i32 }
|
2014-09-30 17:03:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get a detailed string description for the given error number
|
|
|
|
|
pub fn error_string(errnum: i32) -> String {
|
|
|
|
|
use libc::types::os::arch::extra::DWORD;
|
|
|
|
|
use libc::types::os::arch::extra::LPWSTR;
|
|
|
|
|
use libc::types::os::arch::extra::LPVOID;
|
|
|
|
|
use libc::types::os::arch::extra::WCHAR;
|
|
|
|
|
|
|
|
|
|
#[link_name = "kernel32"]
|
|
|
|
|
extern "system" {
|
|
|
|
|
fn FormatMessageW(flags: DWORD,
|
|
|
|
|
lpSrc: LPVOID,
|
|
|
|
|
msgId: DWORD,
|
|
|
|
|
langId: DWORD,
|
|
|
|
|
buf: LPWSTR,
|
|
|
|
|
nsize: DWORD,
|
|
|
|
|
args: *const c_void)
|
|
|
|
|
-> DWORD;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 15:36:53 +01:00
|
|
|
const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000;
|
|
|
|
|
const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200;
|
2014-09-30 17:03:56 -07:00
|
|
|
|
|
|
|
|
// This value is calculated from the macro
|
|
|
|
|
// MAKELANGID(LANG_SYSTEM_DEFAULT, SUBLANG_SYS_DEFAULT)
|
|
|
|
|
let langId = 0x0800 as DWORD;
|
|
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
let mut buf = [0 as WCHAR; 2048];
|
2014-09-30 17:03:56 -07:00
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
let res = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
|
ptr::null_mut(),
|
|
|
|
|
errnum as DWORD,
|
|
|
|
|
langId,
|
|
|
|
|
buf.as_mut_ptr(),
|
|
|
|
|
buf.len() as DWORD,
|
|
|
|
|
ptr::null());
|
|
|
|
|
if res == 0 {
|
|
|
|
|
// Sometimes FormatMessageW can fail e.g. system doesn't like langId,
|
|
|
|
|
let fm_err = errno();
|
2015-01-27 12:20:58 -08:00
|
|
|
return format!("OS Error {} (FormatMessageW() returned error {})",
|
|
|
|
|
errnum, fm_err);
|
2014-09-30 17:03:56 -07:00
|
|
|
}
|
|
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
let b = buf.iter().position(|&b| b == 0).unwrap_or(buf.len());
|
|
|
|
|
let msg = String::from_utf16(&buf[..b]);
|
2014-09-30 17:03:56 -07:00
|
|
|
match msg {
|
2015-01-27 12:20:58 -08:00
|
|
|
Ok(msg) => msg,
|
2014-12-29 16:38:07 -08:00
|
|
|
Err(..) => format!("OS Error {} (FormatMessageW() returned \
|
|
|
|
|
invalid UTF-16)", errnum),
|
2014-09-30 17:03:56 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
pub struct Env {
|
|
|
|
|
base: LPWCH,
|
|
|
|
|
cur: LPWCH,
|
2014-09-30 17:03:56 -07:00
|
|
|
}
|
2014-11-24 16:21:39 -08:00
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
impl Iterator for Env {
|
|
|
|
|
type Item = (OsString, OsString);
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<(OsString, OsString)> {
|
|
|
|
|
unsafe {
|
|
|
|
|
if *self.cur == 0 { return None }
|
|
|
|
|
let p = &*self.cur;
|
|
|
|
|
let mut len = 0;
|
|
|
|
|
while *(p as *const _).offset(len) != 0 {
|
|
|
|
|
len += 1;
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
2015-01-27 12:20:58 -08:00
|
|
|
let p = p as *const u16;
|
2015-02-04 01:00:38 +02:00
|
|
|
let s = slice::from_raw_parts(p, len as usize);
|
2015-01-27 12:20:58 -08:00
|
|
|
self.cur = self.cur.offset(len + 1);
|
|
|
|
|
|
|
|
|
|
let (k, v) = match s.iter().position(|&b| b == '=' as u16) {
|
|
|
|
|
Some(n) => (&s[..n], &s[n+1..]),
|
2015-02-18 14:48:57 -05:00
|
|
|
None => (s, &[][..]),
|
2015-01-27 12:20:58 -08:00
|
|
|
};
|
|
|
|
|
Some((OsStringExt::from_wide(k), OsStringExt::from_wide(v)))
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
impl Drop for Env {
|
|
|
|
|
fn drop(&mut self) {
|
|
|
|
|
unsafe { FreeEnvironmentStringsW(self.base); }
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-24 16:21:39 -08:00
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
pub fn env() -> Env {
|
2014-11-24 16:21:39 -08:00
|
|
|
unsafe {
|
2015-01-27 12:20:58 -08:00
|
|
|
let ch = GetEnvironmentStringsW();
|
|
|
|
|
if ch as usize == 0 {
|
|
|
|
|
panic!("failure getting env string from OS: {}",
|
2015-03-11 15:24:14 -07:00
|
|
|
io::Error::last_os_error());
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
2015-01-27 12:20:58 -08:00
|
|
|
Env { base: ch, cur: ch }
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
2015-01-27 12:20:58 -08:00
|
|
|
}
|
2014-11-24 16:21:39 -08:00
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
pub struct SplitPaths<'a> {
|
|
|
|
|
data: EncodeWide<'a>,
|
|
|
|
|
must_yield: bool,
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
|
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
pub fn split_paths(unparsed: &OsStr) -> SplitPaths {
|
|
|
|
|
SplitPaths {
|
|
|
|
|
data: unparsed.encode_wide(),
|
|
|
|
|
must_yield: true,
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
impl<'a> Iterator for SplitPaths<'a> {
|
2015-02-23 10:59:17 -08:00
|
|
|
type Item = PathBuf;
|
|
|
|
|
fn next(&mut self) -> Option<PathBuf> {
|
2015-01-27 12:20:58 -08:00
|
|
|
// On Windows, the PATH environment variable is semicolon separated.
|
|
|
|
|
// Double quotes are used as a way of introducing literal semicolons
|
|
|
|
|
// (since c:\some;dir is a valid Windows path). Double quotes are not
|
|
|
|
|
// themselves permitted in path names, so there is no way to escape a
|
|
|
|
|
// double quote. Quoted regions can appear in arbitrary locations, so
|
|
|
|
|
//
|
|
|
|
|
// c:\foo;c:\som"e;di"r;c:\bar
|
|
|
|
|
//
|
|
|
|
|
// Should parse as [c:\foo, c:\some;dir, c:\bar].
|
|
|
|
|
//
|
|
|
|
|
// (The above is based on testing; there is no clear reference available
|
|
|
|
|
// for the grammar.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let must_yield = self.must_yield;
|
|
|
|
|
self.must_yield = false;
|
|
|
|
|
|
|
|
|
|
let mut in_progress = Vec::new();
|
|
|
|
|
let mut in_quote = false;
|
|
|
|
|
for b in self.data.by_ref() {
|
|
|
|
|
if b == '"' as u16 {
|
2014-11-24 16:21:39 -08:00
|
|
|
in_quote = !in_quote;
|
2015-01-27 12:20:58 -08:00
|
|
|
} else if b == ';' as u16 && !in_quote {
|
|
|
|
|
self.must_yield = true;
|
|
|
|
|
break
|
|
|
|
|
} else {
|
|
|
|
|
in_progress.push(b)
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
2015-01-27 12:20:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !must_yield && in_progress.is_empty() {
|
|
|
|
|
None
|
|
|
|
|
} else {
|
2015-02-23 10:59:17 -08:00
|
|
|
Some(super::os2path(&in_progress))
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-02 21:39:14 -08:00
|
|
|
#[derive(Debug)]
|
2015-01-27 12:20:58 -08:00
|
|
|
pub struct JoinPathsError;
|
|
|
|
|
|
|
|
|
|
pub fn join_paths<I, T>(paths: I) -> Result<OsString, JoinPathsError>
|
|
|
|
|
where I: Iterator<Item=T>, T: AsOsStr
|
|
|
|
|
{
|
2014-11-24 16:21:39 -08:00
|
|
|
let mut joined = Vec::new();
|
2015-01-27 12:20:58 -08:00
|
|
|
let sep = b';' as u16;
|
2014-11-24 16:21:39 -08:00
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
for (i, path) in paths.enumerate() {
|
|
|
|
|
let path = path.as_os_str();
|
2014-11-24 16:21:39 -08:00
|
|
|
if i > 0 { joined.push(sep) }
|
2015-01-27 12:20:58 -08:00
|
|
|
let v = path.encode_wide().collect::<Vec<u16>>();
|
|
|
|
|
if v.contains(&(b'"' as u16)) {
|
|
|
|
|
return Err(JoinPathsError)
|
|
|
|
|
} else if v.contains(&sep) {
|
|
|
|
|
joined.push(b'"' as u16);
|
2015-02-18 14:48:57 -05:00
|
|
|
joined.push_all(&v[..]);
|
2015-01-27 12:20:58 -08:00
|
|
|
joined.push(b'"' as u16);
|
2014-11-24 16:21:39 -08:00
|
|
|
} else {
|
2015-02-18 14:48:57 -05:00
|
|
|
joined.push_all(&v[..]);
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 14:48:57 -05:00
|
|
|
Ok(OsStringExt::from_wide(&joined[..]))
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
|
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
impl fmt::Display for JoinPathsError {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
|
"path segment contains `\"`".fmt(f)
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
impl StdError for JoinPathsError {
|
|
|
|
|
fn description(&self) -> &str { "failed to join paths" }
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 10:59:17 -08:00
|
|
|
pub fn current_exe() -> io::Result<PathBuf> {
|
|
|
|
|
super::fill_utf16_buf_new(|buf, sz| unsafe {
|
2015-01-27 12:20:58 -08:00
|
|
|
libc::GetModuleFileNameW(ptr::null_mut(), buf, sz)
|
|
|
|
|
}, super::os2path)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 10:59:17 -08:00
|
|
|
pub fn getcwd() -> io::Result<PathBuf> {
|
|
|
|
|
super::fill_utf16_buf_new(|buf, sz| unsafe {
|
2015-01-27 12:20:58 -08:00
|
|
|
libc::GetCurrentDirectoryW(sz, buf)
|
|
|
|
|
}, super::os2path)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 10:59:17 -08:00
|
|
|
pub fn chdir(p: &path::Path) -> io::Result<()> {
|
2015-01-27 12:20:58 -08:00
|
|
|
let mut p = p.as_os_str().encode_wide().collect::<Vec<_>>();
|
2014-11-24 16:21:39 -08:00
|
|
|
p.push(0);
|
|
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
match libc::SetCurrentDirectoryW(p.as_ptr()) != (0 as libc::BOOL) {
|
|
|
|
|
true => Ok(()),
|
2015-02-23 10:59:17 -08:00
|
|
|
false => Err(io::Error::last_os_error()),
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
pub fn getenv(k: &OsStr) -> Option<OsString> {
|
|
|
|
|
let k = super::to_utf16_os(k);
|
2015-02-23 10:59:17 -08:00
|
|
|
super::fill_utf16_buf_new(|buf, sz| unsafe {
|
2015-01-27 12:20:58 -08:00
|
|
|
libc::GetEnvironmentVariableW(k.as_ptr(), buf, sz)
|
|
|
|
|
}, |buf| {
|
|
|
|
|
OsStringExt::from_wide(buf)
|
|
|
|
|
}).ok()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn setenv(k: &OsStr, v: &OsStr) {
|
|
|
|
|
let k = super::to_utf16_os(k);
|
|
|
|
|
let v = super::to_utf16_os(v);
|
|
|
|
|
|
2014-11-24 16:21:39 -08:00
|
|
|
unsafe {
|
2015-01-27 12:20:58 -08:00
|
|
|
if libc::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) == 0 {
|
2015-03-11 15:24:14 -07:00
|
|
|
panic!("failed to set env: {}", io::Error::last_os_error());
|
2015-01-27 12:20:58 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-24 16:21:39 -08:00
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
pub fn unsetenv(n: &OsStr) {
|
|
|
|
|
let v = super::to_utf16_os(n);
|
|
|
|
|
unsafe {
|
|
|
|
|
if libc::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) == 0 {
|
2015-03-11 15:24:14 -07:00
|
|
|
panic!("failed to unset env: {}", io::Error::last_os_error());
|
2015-01-27 12:20:58 -08:00
|
|
|
}
|
2014-11-24 16:21:39 -08:00
|
|
|
}
|
|
|
|
|
}
|
std: Stabilize the std::str module
This commit starts out by consolidating all `str` extension traits into one
`StrExt` trait to be included in the prelude. This means that
`UnicodeStrPrelude`, `StrPrelude`, and `StrAllocating` have all been merged into
one `StrExt` exported by the standard library. Some functionality is currently
duplicated with the `StrExt` present in libcore.
This commit also currently avoids any methods which require any form of pattern
to operate. These functions will be stabilized via a separate RFC.
Next, stability of methods and structures are as follows:
Stable
* from_utf8_unchecked
* CowString - after moving to std::string
* StrExt::as_bytes
* StrExt::as_ptr
* StrExt::bytes/Bytes - also made a struct instead of a typedef
* StrExt::char_indices/CharIndices - CharOffsets was renamed
* StrExt::chars/Chars
* StrExt::is_empty
* StrExt::len
* StrExt::lines/Lines
* StrExt::lines_any/LinesAny
* StrExt::slice_unchecked
* StrExt::trim
* StrExt::trim_left
* StrExt::trim_right
* StrExt::words/Words - also made a struct instead of a typedef
Unstable
* from_utf8 - the error type was changed to a `Result`, but the error type has
yet to prove itself
* from_c_str - this function will be handled by the c_str RFC
* FromStr - this trait will have an associated error type eventually
* StrExt::escape_default - needs iterators at least, unsure if it should make
the cut
* StrExt::escape_unicode - needs iterators at least, unsure if it should make
the cut
* StrExt::slice_chars - this function has yet to prove itself
* StrExt::slice_shift_char - awaiting conventions about slicing and shifting
* StrExt::graphemes/Graphemes - this functionality may only be in libunicode
* StrExt::grapheme_indices/GraphemeIndices - this functionality may only be in
libunicode
* StrExt::width - this functionality may only be in libunicode
* StrExt::utf16_units - this functionality may only be in libunicode
* StrExt::nfd_chars - this functionality may only be in libunicode
* StrExt::nfkd_chars - this functionality may only be in libunicode
* StrExt::nfc_chars - this functionality may only be in libunicode
* StrExt::nfkc_chars - this functionality may only be in libunicode
* StrExt::is_char_boundary - naming is uncertain with container conventions
* StrExt::char_range_at - naming is uncertain with container conventions
* StrExt::char_range_at_reverse - naming is uncertain with container conventions
* StrExt::char_at - naming is uncertain with container conventions
* StrExt::char_at_reverse - naming is uncertain with container conventions
* StrVector::concat - this functionality may be replaced with iterators, but
it's not certain at this time
* StrVector::connect - as with concat, may be deprecated in favor of iterators
Deprecated
* StrAllocating and UnicodeStrPrelude have been merged into StrExit
* eq_slice - compiler implementation detail
* from_str - use the inherent parse() method
* is_utf8 - call from_utf8 instead
* replace - call the method instead
* truncate_utf16_at_nul - this is an implementation detail of windows and does
not need to be exposed.
* utf8_char_width - moved to libunicode
* utf16_items - moved to libunicode
* is_utf16 - moved to libunicode
* Utf16Items - moved to libunicode
* Utf16Item - moved to libunicode
* Utf16Encoder - moved to libunicode
* AnyLines - renamed to LinesAny and made a struct
* SendStr - use CowString<'static> instead
* str::raw - all functionality is deprecated
* StrExt::into_string - call to_string() instead
* StrExt::repeat - use iterators instead
* StrExt::char_len - use .chars().count() instead
* StrExt::is_alphanumeric - use .chars().all(..)
* StrExt::is_whitespace - use .chars().all(..)
Pending deprecation -- while slicing syntax is being worked out, these methods
are all #[unstable]
* Str - while currently used for generic programming, this trait will be
replaced with one of [], deref coercions, or a generic conversion trait.
* StrExt::slice - use slicing syntax instead
* StrExt::slice_to - use slicing syntax instead
* StrExt::slice_from - use slicing syntax instead
* StrExt::lev_distance - deprecated with no replacement
Awaiting stabilization due to patterns and/or matching
* StrExt::contains
* StrExt::contains_char
* StrExt::split
* StrExt::splitn
* StrExt::split_terminator
* StrExt::rsplitn
* StrExt::match_indices
* StrExt::split_str
* StrExt::starts_with
* StrExt::ends_with
* StrExt::trim_chars
* StrExt::trim_left_chars
* StrExt::trim_right_chars
* StrExt::find
* StrExt::rfind
* StrExt::find_str
* StrExt::subslice_offset
2014-12-10 09:02:31 -08:00
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
pub struct Args {
|
|
|
|
|
range: Range<isize>,
|
|
|
|
|
cur: *mut *mut u16,
|
|
|
|
|
}
|
std: Stabilize the std::str module
This commit starts out by consolidating all `str` extension traits into one
`StrExt` trait to be included in the prelude. This means that
`UnicodeStrPrelude`, `StrPrelude`, and `StrAllocating` have all been merged into
one `StrExt` exported by the standard library. Some functionality is currently
duplicated with the `StrExt` present in libcore.
This commit also currently avoids any methods which require any form of pattern
to operate. These functions will be stabilized via a separate RFC.
Next, stability of methods and structures are as follows:
Stable
* from_utf8_unchecked
* CowString - after moving to std::string
* StrExt::as_bytes
* StrExt::as_ptr
* StrExt::bytes/Bytes - also made a struct instead of a typedef
* StrExt::char_indices/CharIndices - CharOffsets was renamed
* StrExt::chars/Chars
* StrExt::is_empty
* StrExt::len
* StrExt::lines/Lines
* StrExt::lines_any/LinesAny
* StrExt::slice_unchecked
* StrExt::trim
* StrExt::trim_left
* StrExt::trim_right
* StrExt::words/Words - also made a struct instead of a typedef
Unstable
* from_utf8 - the error type was changed to a `Result`, but the error type has
yet to prove itself
* from_c_str - this function will be handled by the c_str RFC
* FromStr - this trait will have an associated error type eventually
* StrExt::escape_default - needs iterators at least, unsure if it should make
the cut
* StrExt::escape_unicode - needs iterators at least, unsure if it should make
the cut
* StrExt::slice_chars - this function has yet to prove itself
* StrExt::slice_shift_char - awaiting conventions about slicing and shifting
* StrExt::graphemes/Graphemes - this functionality may only be in libunicode
* StrExt::grapheme_indices/GraphemeIndices - this functionality may only be in
libunicode
* StrExt::width - this functionality may only be in libunicode
* StrExt::utf16_units - this functionality may only be in libunicode
* StrExt::nfd_chars - this functionality may only be in libunicode
* StrExt::nfkd_chars - this functionality may only be in libunicode
* StrExt::nfc_chars - this functionality may only be in libunicode
* StrExt::nfkc_chars - this functionality may only be in libunicode
* StrExt::is_char_boundary - naming is uncertain with container conventions
* StrExt::char_range_at - naming is uncertain with container conventions
* StrExt::char_range_at_reverse - naming is uncertain with container conventions
* StrExt::char_at - naming is uncertain with container conventions
* StrExt::char_at_reverse - naming is uncertain with container conventions
* StrVector::concat - this functionality may be replaced with iterators, but
it's not certain at this time
* StrVector::connect - as with concat, may be deprecated in favor of iterators
Deprecated
* StrAllocating and UnicodeStrPrelude have been merged into StrExit
* eq_slice - compiler implementation detail
* from_str - use the inherent parse() method
* is_utf8 - call from_utf8 instead
* replace - call the method instead
* truncate_utf16_at_nul - this is an implementation detail of windows and does
not need to be exposed.
* utf8_char_width - moved to libunicode
* utf16_items - moved to libunicode
* is_utf16 - moved to libunicode
* Utf16Items - moved to libunicode
* Utf16Item - moved to libunicode
* Utf16Encoder - moved to libunicode
* AnyLines - renamed to LinesAny and made a struct
* SendStr - use CowString<'static> instead
* str::raw - all functionality is deprecated
* StrExt::into_string - call to_string() instead
* StrExt::repeat - use iterators instead
* StrExt::char_len - use .chars().count() instead
* StrExt::is_alphanumeric - use .chars().all(..)
* StrExt::is_whitespace - use .chars().all(..)
Pending deprecation -- while slicing syntax is being worked out, these methods
are all #[unstable]
* Str - while currently used for generic programming, this trait will be
replaced with one of [], deref coercions, or a generic conversion trait.
* StrExt::slice - use slicing syntax instead
* StrExt::slice_to - use slicing syntax instead
* StrExt::slice_from - use slicing syntax instead
* StrExt::lev_distance - deprecated with no replacement
Awaiting stabilization due to patterns and/or matching
* StrExt::contains
* StrExt::contains_char
* StrExt::split
* StrExt::splitn
* StrExt::split_terminator
* StrExt::rsplitn
* StrExt::match_indices
* StrExt::split_str
* StrExt::starts_with
* StrExt::ends_with
* StrExt::trim_chars
* StrExt::trim_left_chars
* StrExt::trim_right_chars
* StrExt::find
* StrExt::rfind
* StrExt::find_str
* StrExt::subslice_offset
2014-12-10 09:02:31 -08:00
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
impl Iterator for Args {
|
|
|
|
|
type Item = OsString;
|
|
|
|
|
fn next(&mut self) -> Option<OsString> {
|
|
|
|
|
self.range.next().map(|i| unsafe {
|
|
|
|
|
let ptr = *self.cur.offset(i);
|
|
|
|
|
let mut len = 0;
|
|
|
|
|
while *ptr.offset(len) != 0 { len += 1; }
|
|
|
|
|
|
|
|
|
|
// Push it onto the list.
|
|
|
|
|
let ptr = ptr as *const u16;
|
2015-02-04 01:00:38 +02:00
|
|
|
let buf = slice::from_raw_parts(ptr, len as usize);
|
2015-01-27 12:20:58 -08:00
|
|
|
OsStringExt::from_wide(buf)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
fn size_hint(&self) -> (usize, Option<usize>) { self.range.size_hint() }
|
|
|
|
|
}
|
std: Stabilize the std::str module
This commit starts out by consolidating all `str` extension traits into one
`StrExt` trait to be included in the prelude. This means that
`UnicodeStrPrelude`, `StrPrelude`, and `StrAllocating` have all been merged into
one `StrExt` exported by the standard library. Some functionality is currently
duplicated with the `StrExt` present in libcore.
This commit also currently avoids any methods which require any form of pattern
to operate. These functions will be stabilized via a separate RFC.
Next, stability of methods and structures are as follows:
Stable
* from_utf8_unchecked
* CowString - after moving to std::string
* StrExt::as_bytes
* StrExt::as_ptr
* StrExt::bytes/Bytes - also made a struct instead of a typedef
* StrExt::char_indices/CharIndices - CharOffsets was renamed
* StrExt::chars/Chars
* StrExt::is_empty
* StrExt::len
* StrExt::lines/Lines
* StrExt::lines_any/LinesAny
* StrExt::slice_unchecked
* StrExt::trim
* StrExt::trim_left
* StrExt::trim_right
* StrExt::words/Words - also made a struct instead of a typedef
Unstable
* from_utf8 - the error type was changed to a `Result`, but the error type has
yet to prove itself
* from_c_str - this function will be handled by the c_str RFC
* FromStr - this trait will have an associated error type eventually
* StrExt::escape_default - needs iterators at least, unsure if it should make
the cut
* StrExt::escape_unicode - needs iterators at least, unsure if it should make
the cut
* StrExt::slice_chars - this function has yet to prove itself
* StrExt::slice_shift_char - awaiting conventions about slicing and shifting
* StrExt::graphemes/Graphemes - this functionality may only be in libunicode
* StrExt::grapheme_indices/GraphemeIndices - this functionality may only be in
libunicode
* StrExt::width - this functionality may only be in libunicode
* StrExt::utf16_units - this functionality may only be in libunicode
* StrExt::nfd_chars - this functionality may only be in libunicode
* StrExt::nfkd_chars - this functionality may only be in libunicode
* StrExt::nfc_chars - this functionality may only be in libunicode
* StrExt::nfkc_chars - this functionality may only be in libunicode
* StrExt::is_char_boundary - naming is uncertain with container conventions
* StrExt::char_range_at - naming is uncertain with container conventions
* StrExt::char_range_at_reverse - naming is uncertain with container conventions
* StrExt::char_at - naming is uncertain with container conventions
* StrExt::char_at_reverse - naming is uncertain with container conventions
* StrVector::concat - this functionality may be replaced with iterators, but
it's not certain at this time
* StrVector::connect - as with concat, may be deprecated in favor of iterators
Deprecated
* StrAllocating and UnicodeStrPrelude have been merged into StrExit
* eq_slice - compiler implementation detail
* from_str - use the inherent parse() method
* is_utf8 - call from_utf8 instead
* replace - call the method instead
* truncate_utf16_at_nul - this is an implementation detail of windows and does
not need to be exposed.
* utf8_char_width - moved to libunicode
* utf16_items - moved to libunicode
* is_utf16 - moved to libunicode
* Utf16Items - moved to libunicode
* Utf16Item - moved to libunicode
* Utf16Encoder - moved to libunicode
* AnyLines - renamed to LinesAny and made a struct
* SendStr - use CowString<'static> instead
* str::raw - all functionality is deprecated
* StrExt::into_string - call to_string() instead
* StrExt::repeat - use iterators instead
* StrExt::char_len - use .chars().count() instead
* StrExt::is_alphanumeric - use .chars().all(..)
* StrExt::is_whitespace - use .chars().all(..)
Pending deprecation -- while slicing syntax is being worked out, these methods
are all #[unstable]
* Str - while currently used for generic programming, this trait will be
replaced with one of [], deref coercions, or a generic conversion trait.
* StrExt::slice - use slicing syntax instead
* StrExt::slice_to - use slicing syntax instead
* StrExt::slice_from - use slicing syntax instead
* StrExt::lev_distance - deprecated with no replacement
Awaiting stabilization due to patterns and/or matching
* StrExt::contains
* StrExt::contains_char
* StrExt::split
* StrExt::splitn
* StrExt::split_terminator
* StrExt::rsplitn
* StrExt::match_indices
* StrExt::split_str
* StrExt::starts_with
* StrExt::ends_with
* StrExt::trim_chars
* StrExt::trim_left_chars
* StrExt::trim_right_chars
* StrExt::find
* StrExt::rfind
* StrExt::find_str
* StrExt::subslice_offset
2014-12-10 09:02:31 -08:00
|
|
|
|
2015-02-16 12:15:30 +02:00
|
|
|
impl ExactSizeIterator for Args {
|
|
|
|
|
fn len(&self) -> usize { self.range.len() }
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
impl Drop for Args {
|
|
|
|
|
fn drop(&mut self) {
|
|
|
|
|
unsafe { c::LocalFree(self.cur as *mut c_void); }
|
|
|
|
|
}
|
|
|
|
|
}
|
std: Stabilize the std::str module
This commit starts out by consolidating all `str` extension traits into one
`StrExt` trait to be included in the prelude. This means that
`UnicodeStrPrelude`, `StrPrelude`, and `StrAllocating` have all been merged into
one `StrExt` exported by the standard library. Some functionality is currently
duplicated with the `StrExt` present in libcore.
This commit also currently avoids any methods which require any form of pattern
to operate. These functions will be stabilized via a separate RFC.
Next, stability of methods and structures are as follows:
Stable
* from_utf8_unchecked
* CowString - after moving to std::string
* StrExt::as_bytes
* StrExt::as_ptr
* StrExt::bytes/Bytes - also made a struct instead of a typedef
* StrExt::char_indices/CharIndices - CharOffsets was renamed
* StrExt::chars/Chars
* StrExt::is_empty
* StrExt::len
* StrExt::lines/Lines
* StrExt::lines_any/LinesAny
* StrExt::slice_unchecked
* StrExt::trim
* StrExt::trim_left
* StrExt::trim_right
* StrExt::words/Words - also made a struct instead of a typedef
Unstable
* from_utf8 - the error type was changed to a `Result`, but the error type has
yet to prove itself
* from_c_str - this function will be handled by the c_str RFC
* FromStr - this trait will have an associated error type eventually
* StrExt::escape_default - needs iterators at least, unsure if it should make
the cut
* StrExt::escape_unicode - needs iterators at least, unsure if it should make
the cut
* StrExt::slice_chars - this function has yet to prove itself
* StrExt::slice_shift_char - awaiting conventions about slicing and shifting
* StrExt::graphemes/Graphemes - this functionality may only be in libunicode
* StrExt::grapheme_indices/GraphemeIndices - this functionality may only be in
libunicode
* StrExt::width - this functionality may only be in libunicode
* StrExt::utf16_units - this functionality may only be in libunicode
* StrExt::nfd_chars - this functionality may only be in libunicode
* StrExt::nfkd_chars - this functionality may only be in libunicode
* StrExt::nfc_chars - this functionality may only be in libunicode
* StrExt::nfkc_chars - this functionality may only be in libunicode
* StrExt::is_char_boundary - naming is uncertain with container conventions
* StrExt::char_range_at - naming is uncertain with container conventions
* StrExt::char_range_at_reverse - naming is uncertain with container conventions
* StrExt::char_at - naming is uncertain with container conventions
* StrExt::char_at_reverse - naming is uncertain with container conventions
* StrVector::concat - this functionality may be replaced with iterators, but
it's not certain at this time
* StrVector::connect - as with concat, may be deprecated in favor of iterators
Deprecated
* StrAllocating and UnicodeStrPrelude have been merged into StrExit
* eq_slice - compiler implementation detail
* from_str - use the inherent parse() method
* is_utf8 - call from_utf8 instead
* replace - call the method instead
* truncate_utf16_at_nul - this is an implementation detail of windows and does
not need to be exposed.
* utf8_char_width - moved to libunicode
* utf16_items - moved to libunicode
* is_utf16 - moved to libunicode
* Utf16Items - moved to libunicode
* Utf16Item - moved to libunicode
* Utf16Encoder - moved to libunicode
* AnyLines - renamed to LinesAny and made a struct
* SendStr - use CowString<'static> instead
* str::raw - all functionality is deprecated
* StrExt::into_string - call to_string() instead
* StrExt::repeat - use iterators instead
* StrExt::char_len - use .chars().count() instead
* StrExt::is_alphanumeric - use .chars().all(..)
* StrExt::is_whitespace - use .chars().all(..)
Pending deprecation -- while slicing syntax is being worked out, these methods
are all #[unstable]
* Str - while currently used for generic programming, this trait will be
replaced with one of [], deref coercions, or a generic conversion trait.
* StrExt::slice - use slicing syntax instead
* StrExt::slice_to - use slicing syntax instead
* StrExt::slice_from - use slicing syntax instead
* StrExt::lev_distance - deprecated with no replacement
Awaiting stabilization due to patterns and/or matching
* StrExt::contains
* StrExt::contains_char
* StrExt::split
* StrExt::splitn
* StrExt::split_terminator
* StrExt::rsplitn
* StrExt::match_indices
* StrExt::split_str
* StrExt::starts_with
* StrExt::ends_with
* StrExt::trim_chars
* StrExt::trim_left_chars
* StrExt::trim_right_chars
* StrExt::find
* StrExt::rfind
* StrExt::find_str
* StrExt::subslice_offset
2014-12-10 09:02:31 -08:00
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
pub fn args() -> Args {
|
|
|
|
|
unsafe {
|
|
|
|
|
let mut nArgs: c_int = 0;
|
|
|
|
|
let lpCmdLine = c::GetCommandLineW();
|
|
|
|
|
let szArgList = c::CommandLineToArgvW(lpCmdLine, &mut nArgs);
|
std: Stabilize the std::str module
This commit starts out by consolidating all `str` extension traits into one
`StrExt` trait to be included in the prelude. This means that
`UnicodeStrPrelude`, `StrPrelude`, and `StrAllocating` have all been merged into
one `StrExt` exported by the standard library. Some functionality is currently
duplicated with the `StrExt` present in libcore.
This commit also currently avoids any methods which require any form of pattern
to operate. These functions will be stabilized via a separate RFC.
Next, stability of methods and structures are as follows:
Stable
* from_utf8_unchecked
* CowString - after moving to std::string
* StrExt::as_bytes
* StrExt::as_ptr
* StrExt::bytes/Bytes - also made a struct instead of a typedef
* StrExt::char_indices/CharIndices - CharOffsets was renamed
* StrExt::chars/Chars
* StrExt::is_empty
* StrExt::len
* StrExt::lines/Lines
* StrExt::lines_any/LinesAny
* StrExt::slice_unchecked
* StrExt::trim
* StrExt::trim_left
* StrExt::trim_right
* StrExt::words/Words - also made a struct instead of a typedef
Unstable
* from_utf8 - the error type was changed to a `Result`, but the error type has
yet to prove itself
* from_c_str - this function will be handled by the c_str RFC
* FromStr - this trait will have an associated error type eventually
* StrExt::escape_default - needs iterators at least, unsure if it should make
the cut
* StrExt::escape_unicode - needs iterators at least, unsure if it should make
the cut
* StrExt::slice_chars - this function has yet to prove itself
* StrExt::slice_shift_char - awaiting conventions about slicing and shifting
* StrExt::graphemes/Graphemes - this functionality may only be in libunicode
* StrExt::grapheme_indices/GraphemeIndices - this functionality may only be in
libunicode
* StrExt::width - this functionality may only be in libunicode
* StrExt::utf16_units - this functionality may only be in libunicode
* StrExt::nfd_chars - this functionality may only be in libunicode
* StrExt::nfkd_chars - this functionality may only be in libunicode
* StrExt::nfc_chars - this functionality may only be in libunicode
* StrExt::nfkc_chars - this functionality may only be in libunicode
* StrExt::is_char_boundary - naming is uncertain with container conventions
* StrExt::char_range_at - naming is uncertain with container conventions
* StrExt::char_range_at_reverse - naming is uncertain with container conventions
* StrExt::char_at - naming is uncertain with container conventions
* StrExt::char_at_reverse - naming is uncertain with container conventions
* StrVector::concat - this functionality may be replaced with iterators, but
it's not certain at this time
* StrVector::connect - as with concat, may be deprecated in favor of iterators
Deprecated
* StrAllocating and UnicodeStrPrelude have been merged into StrExit
* eq_slice - compiler implementation detail
* from_str - use the inherent parse() method
* is_utf8 - call from_utf8 instead
* replace - call the method instead
* truncate_utf16_at_nul - this is an implementation detail of windows and does
not need to be exposed.
* utf8_char_width - moved to libunicode
* utf16_items - moved to libunicode
* is_utf16 - moved to libunicode
* Utf16Items - moved to libunicode
* Utf16Item - moved to libunicode
* Utf16Encoder - moved to libunicode
* AnyLines - renamed to LinesAny and made a struct
* SendStr - use CowString<'static> instead
* str::raw - all functionality is deprecated
* StrExt::into_string - call to_string() instead
* StrExt::repeat - use iterators instead
* StrExt::char_len - use .chars().count() instead
* StrExt::is_alphanumeric - use .chars().all(..)
* StrExt::is_whitespace - use .chars().all(..)
Pending deprecation -- while slicing syntax is being worked out, these methods
are all #[unstable]
* Str - while currently used for generic programming, this trait will be
replaced with one of [], deref coercions, or a generic conversion trait.
* StrExt::slice - use slicing syntax instead
* StrExt::slice_to - use slicing syntax instead
* StrExt::slice_from - use slicing syntax instead
* StrExt::lev_distance - deprecated with no replacement
Awaiting stabilization due to patterns and/or matching
* StrExt::contains
* StrExt::contains_char
* StrExt::split
* StrExt::splitn
* StrExt::split_terminator
* StrExt::rsplitn
* StrExt::match_indices
* StrExt::split_str
* StrExt::starts_with
* StrExt::ends_with
* StrExt::trim_chars
* StrExt::trim_left_chars
* StrExt::trim_right_chars
* StrExt::find
* StrExt::rfind
* StrExt::find_str
* StrExt::subslice_offset
2014-12-10 09:02:31 -08:00
|
|
|
|
2015-02-17 20:32:22 +05:30
|
|
|
Args { cur: szArgList, range: 0..(nArgs as isize) }
|
2015-01-27 12:20:58 -08:00
|
|
|
}
|
|
|
|
|
}
|
std: Stabilize the std::str module
This commit starts out by consolidating all `str` extension traits into one
`StrExt` trait to be included in the prelude. This means that
`UnicodeStrPrelude`, `StrPrelude`, and `StrAllocating` have all been merged into
one `StrExt` exported by the standard library. Some functionality is currently
duplicated with the `StrExt` present in libcore.
This commit also currently avoids any methods which require any form of pattern
to operate. These functions will be stabilized via a separate RFC.
Next, stability of methods and structures are as follows:
Stable
* from_utf8_unchecked
* CowString - after moving to std::string
* StrExt::as_bytes
* StrExt::as_ptr
* StrExt::bytes/Bytes - also made a struct instead of a typedef
* StrExt::char_indices/CharIndices - CharOffsets was renamed
* StrExt::chars/Chars
* StrExt::is_empty
* StrExt::len
* StrExt::lines/Lines
* StrExt::lines_any/LinesAny
* StrExt::slice_unchecked
* StrExt::trim
* StrExt::trim_left
* StrExt::trim_right
* StrExt::words/Words - also made a struct instead of a typedef
Unstable
* from_utf8 - the error type was changed to a `Result`, but the error type has
yet to prove itself
* from_c_str - this function will be handled by the c_str RFC
* FromStr - this trait will have an associated error type eventually
* StrExt::escape_default - needs iterators at least, unsure if it should make
the cut
* StrExt::escape_unicode - needs iterators at least, unsure if it should make
the cut
* StrExt::slice_chars - this function has yet to prove itself
* StrExt::slice_shift_char - awaiting conventions about slicing and shifting
* StrExt::graphemes/Graphemes - this functionality may only be in libunicode
* StrExt::grapheme_indices/GraphemeIndices - this functionality may only be in
libunicode
* StrExt::width - this functionality may only be in libunicode
* StrExt::utf16_units - this functionality may only be in libunicode
* StrExt::nfd_chars - this functionality may only be in libunicode
* StrExt::nfkd_chars - this functionality may only be in libunicode
* StrExt::nfc_chars - this functionality may only be in libunicode
* StrExt::nfkc_chars - this functionality may only be in libunicode
* StrExt::is_char_boundary - naming is uncertain with container conventions
* StrExt::char_range_at - naming is uncertain with container conventions
* StrExt::char_range_at_reverse - naming is uncertain with container conventions
* StrExt::char_at - naming is uncertain with container conventions
* StrExt::char_at_reverse - naming is uncertain with container conventions
* StrVector::concat - this functionality may be replaced with iterators, but
it's not certain at this time
* StrVector::connect - as with concat, may be deprecated in favor of iterators
Deprecated
* StrAllocating and UnicodeStrPrelude have been merged into StrExit
* eq_slice - compiler implementation detail
* from_str - use the inherent parse() method
* is_utf8 - call from_utf8 instead
* replace - call the method instead
* truncate_utf16_at_nul - this is an implementation detail of windows and does
not need to be exposed.
* utf8_char_width - moved to libunicode
* utf16_items - moved to libunicode
* is_utf16 - moved to libunicode
* Utf16Items - moved to libunicode
* Utf16Item - moved to libunicode
* Utf16Encoder - moved to libunicode
* AnyLines - renamed to LinesAny and made a struct
* SendStr - use CowString<'static> instead
* str::raw - all functionality is deprecated
* StrExt::into_string - call to_string() instead
* StrExt::repeat - use iterators instead
* StrExt::char_len - use .chars().count() instead
* StrExt::is_alphanumeric - use .chars().all(..)
* StrExt::is_whitespace - use .chars().all(..)
Pending deprecation -- while slicing syntax is being worked out, these methods
are all #[unstable]
* Str - while currently used for generic programming, this trait will be
replaced with one of [], deref coercions, or a generic conversion trait.
* StrExt::slice - use slicing syntax instead
* StrExt::slice_to - use slicing syntax instead
* StrExt::slice_from - use slicing syntax instead
* StrExt::lev_distance - deprecated with no replacement
Awaiting stabilization due to patterns and/or matching
* StrExt::contains
* StrExt::contains_char
* StrExt::split
* StrExt::splitn
* StrExt::split_terminator
* StrExt::rsplitn
* StrExt::match_indices
* StrExt::split_str
* StrExt::starts_with
* StrExt::ends_with
* StrExt::trim_chars
* StrExt::trim_left_chars
* StrExt::trim_right_chars
* StrExt::find
* StrExt::rfind
* StrExt::find_str
* StrExt::subslice_offset
2014-12-10 09:02:31 -08:00
|
|
|
|
2015-01-27 12:20:58 -08:00
|
|
|
pub fn page_size() -> usize {
|
|
|
|
|
unsafe {
|
|
|
|
|
let mut info = mem::zeroed();
|
|
|
|
|
libc::GetSystemInfo(&mut info);
|
|
|
|
|
return info.dwPageSize as usize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-11 15:24:14 -07:00
|
|
|
#[allow(deprecated)]
|
2015-01-27 12:20:58 -08:00
|
|
|
pub unsafe fn pipe() -> IoResult<(FileDesc, FileDesc)> {
|
|
|
|
|
// Windows pipes work subtly differently than unix pipes, and their
|
|
|
|
|
// inheritance has to be handled in a different way that I do not
|
|
|
|
|
// fully understand. Here we explicitly make the pipe non-inheritable,
|
|
|
|
|
// which means to pass it to a subprocess they need to be duplicated
|
|
|
|
|
// first, as in std::run.
|
|
|
|
|
let mut fds = [0; 2];
|
|
|
|
|
match libc::pipe(fds.as_mut_ptr(), 1024 as ::libc::c_uint,
|
|
|
|
|
(libc::O_BINARY | libc::O_NOINHERIT) as c_int) {
|
|
|
|
|
0 => {
|
|
|
|
|
assert!(fds[0] != -1 && fds[0] != 0);
|
|
|
|
|
assert!(fds[1] != -1 && fds[1] != 0);
|
|
|
|
|
Ok((FileDesc::new(fds[0], true), FileDesc::new(fds[1], true)))
|
|
|
|
|
}
|
|
|
|
|
_ => Err(IoError::last_error()),
|
std: Stabilize the std::str module
This commit starts out by consolidating all `str` extension traits into one
`StrExt` trait to be included in the prelude. This means that
`UnicodeStrPrelude`, `StrPrelude`, and `StrAllocating` have all been merged into
one `StrExt` exported by the standard library. Some functionality is currently
duplicated with the `StrExt` present in libcore.
This commit also currently avoids any methods which require any form of pattern
to operate. These functions will be stabilized via a separate RFC.
Next, stability of methods and structures are as follows:
Stable
* from_utf8_unchecked
* CowString - after moving to std::string
* StrExt::as_bytes
* StrExt::as_ptr
* StrExt::bytes/Bytes - also made a struct instead of a typedef
* StrExt::char_indices/CharIndices - CharOffsets was renamed
* StrExt::chars/Chars
* StrExt::is_empty
* StrExt::len
* StrExt::lines/Lines
* StrExt::lines_any/LinesAny
* StrExt::slice_unchecked
* StrExt::trim
* StrExt::trim_left
* StrExt::trim_right
* StrExt::words/Words - also made a struct instead of a typedef
Unstable
* from_utf8 - the error type was changed to a `Result`, but the error type has
yet to prove itself
* from_c_str - this function will be handled by the c_str RFC
* FromStr - this trait will have an associated error type eventually
* StrExt::escape_default - needs iterators at least, unsure if it should make
the cut
* StrExt::escape_unicode - needs iterators at least, unsure if it should make
the cut
* StrExt::slice_chars - this function has yet to prove itself
* StrExt::slice_shift_char - awaiting conventions about slicing and shifting
* StrExt::graphemes/Graphemes - this functionality may only be in libunicode
* StrExt::grapheme_indices/GraphemeIndices - this functionality may only be in
libunicode
* StrExt::width - this functionality may only be in libunicode
* StrExt::utf16_units - this functionality may only be in libunicode
* StrExt::nfd_chars - this functionality may only be in libunicode
* StrExt::nfkd_chars - this functionality may only be in libunicode
* StrExt::nfc_chars - this functionality may only be in libunicode
* StrExt::nfkc_chars - this functionality may only be in libunicode
* StrExt::is_char_boundary - naming is uncertain with container conventions
* StrExt::char_range_at - naming is uncertain with container conventions
* StrExt::char_range_at_reverse - naming is uncertain with container conventions
* StrExt::char_at - naming is uncertain with container conventions
* StrExt::char_at_reverse - naming is uncertain with container conventions
* StrVector::concat - this functionality may be replaced with iterators, but
it's not certain at this time
* StrVector::connect - as with concat, may be deprecated in favor of iterators
Deprecated
* StrAllocating and UnicodeStrPrelude have been merged into StrExit
* eq_slice - compiler implementation detail
* from_str - use the inherent parse() method
* is_utf8 - call from_utf8 instead
* replace - call the method instead
* truncate_utf16_at_nul - this is an implementation detail of windows and does
not need to be exposed.
* utf8_char_width - moved to libunicode
* utf16_items - moved to libunicode
* is_utf16 - moved to libunicode
* Utf16Items - moved to libunicode
* Utf16Item - moved to libunicode
* Utf16Encoder - moved to libunicode
* AnyLines - renamed to LinesAny and made a struct
* SendStr - use CowString<'static> instead
* str::raw - all functionality is deprecated
* StrExt::into_string - call to_string() instead
* StrExt::repeat - use iterators instead
* StrExt::char_len - use .chars().count() instead
* StrExt::is_alphanumeric - use .chars().all(..)
* StrExt::is_whitespace - use .chars().all(..)
Pending deprecation -- while slicing syntax is being worked out, these methods
are all #[unstable]
* Str - while currently used for generic programming, this trait will be
replaced with one of [], deref coercions, or a generic conversion trait.
* StrExt::slice - use slicing syntax instead
* StrExt::slice_to - use slicing syntax instead
* StrExt::slice_from - use slicing syntax instead
* StrExt::lev_distance - deprecated with no replacement
Awaiting stabilization due to patterns and/or matching
* StrExt::contains
* StrExt::contains_char
* StrExt::split
* StrExt::splitn
* StrExt::split_terminator
* StrExt::rsplitn
* StrExt::match_indices
* StrExt::split_str
* StrExt::starts_with
* StrExt::ends_with
* StrExt::trim_chars
* StrExt::trim_left_chars
* StrExt::trim_right_chars
* StrExt::find
* StrExt::rfind
* StrExt::find_str
* StrExt::subslice_offset
2014-12-10 09:02:31 -08:00
|
|
|
}
|
|
|
|
|
}
|
2015-01-27 12:20:58 -08:00
|
|
|
|
2015-02-23 10:59:17 -08:00
|
|
|
pub fn temp_dir() -> PathBuf {
|
|
|
|
|
super::fill_utf16_buf_new(|buf, sz| unsafe {
|
2015-01-27 12:20:58 -08:00
|
|
|
c::GetTempPathW(sz, buf)
|
|
|
|
|
}, super::os2path).unwrap()
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 10:59:17 -08:00
|
|
|
pub fn home_dir() -> Option<PathBuf> {
|
2015-01-27 12:20:58 -08:00
|
|
|
getenv("HOME".as_os_str()).or_else(|| {
|
|
|
|
|
getenv("USERPROFILE".as_os_str())
|
|
|
|
|
}).map(|os| {
|
2015-02-23 10:59:17 -08:00
|
|
|
// FIXME(#22751) should consume `os`
|
|
|
|
|
PathBuf::new(&os)
|
2015-01-27 12:20:58 -08:00
|
|
|
}).or_else(|| unsafe {
|
|
|
|
|
let me = c::GetCurrentProcess();
|
|
|
|
|
let mut token = ptr::null_mut();
|
|
|
|
|
if c::OpenProcessToken(me, c::TOKEN_READ, &mut token) == 0 {
|
|
|
|
|
return None
|
|
|
|
|
}
|
|
|
|
|
let _handle = RawHandle::new(token);
|
2015-02-23 10:59:17 -08:00
|
|
|
super::fill_utf16_buf_new(|buf, mut sz| {
|
2015-01-27 12:20:58 -08:00
|
|
|
match c::GetUserProfileDirectoryW(token, buf, &mut sz) {
|
|
|
|
|
0 if libc::GetLastError() != 0 => 0,
|
|
|
|
|
0 => sz,
|
|
|
|
|
n => n as libc::DWORD,
|
|
|
|
|
}
|
|
|
|
|
}, super::os2path).ok()
|
|
|
|
|
})
|
|
|
|
|
}
|