servo: Merge #4890 - Remove our copy of Utf16Encoder in favor of the built-in equivalent (fixes #4725) (from servo:Utf16Encoder); r=Ms2ger

Source-Repo: https://github.com/servo/servo
Source-Revision: 395323cd70cad05f43617e9ef95f4db71df05d71
This commit is contained in:
hgentry 2015-02-12 09:18:46 -07:00
Родитель da87abc762
Коммит f27db51a13
3 изменённых файлов: 3 добавлений и 34 удалений

Просмотреть файл

@ -23,6 +23,7 @@ extern crate js;
extern crate layers;
extern crate png;
extern crate script;
extern crate unicode;
extern crate net;
extern crate msg;

Просмотреть файл

@ -11,7 +11,7 @@ use eutil::Downcast;
use interfaces::CefBrowser;
use render_handler::CefRenderHandlerExtensions;
use types::{cef_cursor_handle_t, cef_rect_t};
use wrappers::Utf16Encoder;
use unicode::str::Utf16Encoder;
use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver};
use compositing::windowing::{WindowEvent, WindowMethods};

Просмотреть файл

@ -29,6 +29,7 @@ use types::{cef_termination_status_t, cef_text_input_context_t, cef_thread_id_t}
use types::{cef_time_t, cef_transition_type_t, cef_urlrequest_status_t};
use types::{cef_v8_accesscontrol_t, cef_v8_propertyattribute_t, cef_value_type_t};
use types::{cef_window_info_t, cef_xml_encoding_type_t, cef_xml_node_type_t};
use unicode::str::Utf16Encoder;
use libc::{self, c_char, c_int, c_ushort, c_void};
use std::collections::HashMap;
@ -271,39 +272,6 @@ extern "C" fn free_utf16_buffer(buffer: *mut c_ushort) {
}
}
// TODO(pcwalton): Post Rust-upgrade, remove this and use `collections::str::Utf16Encoder`.
pub struct Utf16Encoder<I> {
chars: I,
extra: u16,
}
impl<I> Utf16Encoder<I> {
pub fn new(chars: I) -> Utf16Encoder<I> where I: Iterator<Item=char> {
Utf16Encoder {
chars: chars,
extra: 0,
}
}
}
impl<I> Iterator for Utf16Encoder<I> where I: Iterator<Item=char> {
type Item = u16;
fn next(&mut self) -> Option<u16> {
if self.extra != 0 {
return Some(mem::replace(&mut self.extra, 0))
}
let mut buf = [0u16; 2];
self.chars.next().map(|ch| {
let n = ch.encode_utf16(buf.as_mut_slice()).unwrap_or(0);
if n == 2 {
self.extra = buf[1]
}
buf[0]
})
}
}
impl<'a> CefWrap<cef_string_t> for &'a mut String {
fn to_c(_: &'a mut String) -> cef_string_t {
panic!("unimplemented CEF type conversion: &'a mut String");