Bug 1330824 - Add truncate for nsAString and nsACString. r=mystor

MozReview-Commit-ID: 2ND5ra3buxI
This commit is contained in:
Hiroyuki Ikezoe 2017-01-14 11:38:56 +09:00
parent b914d41d52
commit ce59a7e9ee

View file

@ -574,6 +574,12 @@ impl nsACString {
pub unsafe fn as_str_unchecked(&self) -> &str { pub unsafe fn as_str_unchecked(&self) -> &str {
str::from_utf8_unchecked(self) str::from_utf8_unchecked(self)
} }
pub fn truncate(&mut self) {
unsafe {
Gecko_TruncateCString(self);
}
}
} }
impl<'a> From<&'a str> for nsCString<'a> { impl<'a> From<&'a str> for nsCString<'a> {
@ -674,6 +680,12 @@ impl nsAString {
Gecko_AppendUTF8toString(self as *mut _, other as *const _); Gecko_AppendUTF8toString(self as *mut _, other as *const _);
} }
} }
pub fn truncate(&mut self) {
unsafe {
Gecko_TruncateString(self);
}
}
} }
// NOTE: The From impl for a string slice for nsString produces a <'static> // NOTE: The From impl for a string slice for nsString produces a <'static>
@ -727,10 +739,12 @@ extern "C" {
fn Gecko_FinalizeCString(this: *mut nsACString); fn Gecko_FinalizeCString(this: *mut nsACString);
fn Gecko_AssignCString(this: *mut nsACString, other: *const nsACString); fn Gecko_AssignCString(this: *mut nsACString, other: *const nsACString);
fn Gecko_AppendCString(this: *mut nsACString, other: *const nsACString); fn Gecko_AppendCString(this: *mut nsACString, other: *const nsACString);
fn Gecko_TruncateCString(this: *mut nsACString);
fn Gecko_FinalizeString(this: *mut nsAString); fn Gecko_FinalizeString(this: *mut nsAString);
fn Gecko_AssignString(this: *mut nsAString, other: *const nsAString); fn Gecko_AssignString(this: *mut nsAString, other: *const nsAString);
fn Gecko_AppendString(this: *mut nsAString, other: *const nsAString); fn Gecko_AppendString(this: *mut nsAString, other: *const nsAString);
fn Gecko_TruncateString(this: *mut nsAString);
// Gecko implementation in nsReadableUtils.cpp // Gecko implementation in nsReadableUtils.cpp
fn Gecko_AppendUTF16toCString(this: *mut nsACString, other: *const nsAString); fn Gecko_AppendUTF16toCString(this: *mut nsACString, other: *const nsAString);