use std::ops;
use std::fmt;
#[derive(Clone, Eq, Ord)]
pub struct String2 {
inner: Vec<char>
}
impl String2 {
#[inline]
pub fn new() -> String2 {
String2 {
inner: Vec::new()
}
}
#[inline]
pub fn with_capacity(capacity: usize) -> String2 {
String2 {
inner: Vec::with_capacity(capacity)
}
}
#[inline]
pub fn capacity(&self) -> usize {
self.inner.capacity()
}
#[inline]
pub fn reserve(&mut self, additional: usize) {
self.inner.reserve(additional);
}
#[inline]
pub fn reserve_exact(&mut self, additional: usize) {
self.inner.reserve_exact(additional);
}
#[inline]
pub fn shrink_to_fit(&mut self) {
self.inner.shrink_to_fit();
}
#[inline]
pub fn as_ptr(&self) -> *const char {
self.inner.as_ptr()
}
#[inline]
pub unsafe fn from_raw_parts(buf: *mut char, length: usize, capacity: usize) -> String2 {
String2 {
inner: Vec::from_raw_parts(buf, length, capacity)
}
}
#[inline]
pub fn as_bytes(&self) -> Vec<u8> {
let s: String = self.clone().into();
s.into_bytes()
}
#[inline]
pub fn as_slice(&self) -> &[char] {
self.inner.as_slice()
}
#[inline]
pub fn as_mut_slice(&mut self) -> &mut [char] {
self.inner.as_mut_slice()
}
#[inline]
pub fn as_vec(self) -> Vec<char> {
self.inner
}
#[inline]
pub fn as_mut_vec(&mut self) -> &mut Vec<char> {
&mut self.inner
}
#[inline]
pub fn retain<F>(&mut self, f: F)
where F: FnMut(&char) -> bool
{
self.inner.retain(f)
}
#[inline]
pub fn get(&self, idx: usize) -> Option<&char> {
self.inner.get(idx)
}
#[inline]
pub fn get_mut(&mut self, idx: usize) -> Option<&mut char> {
self.inner.get_mut(idx)
}
#[inline]
pub fn truncate(&mut self, new_len: usize) {
self.inner.truncate(new_len);
}
#[inline]
pub fn push(&mut self, ch: char) {
self.inner.push(ch);
}
#[inline]
pub fn push_str(&mut self, string: &str) {
self.inner.extend(string.chars())
}
#[inline]
pub fn pop(&mut self) -> Option<char> {
self.inner.pop()
}
#[inline]
pub fn remove(&mut self, idx: usize) -> char {
self.inner.remove(idx)
}
#[inline]
pub fn insert(&mut self, idx: usize, ch: char) {
self.inner.insert(idx, ch);
}
#[inline]
pub fn insert_str(&mut self, _idx: usize, _string: &str) {
}
#[inline]
pub fn append(&mut self, other: &mut Self) {
self.inner.append(&mut other.inner)
}
#[inline]
pub fn len(&self) -> usize {
self.inner.len()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}
#[inline]
pub fn split_off(&mut self, at: usize) -> String2 {
let other = self.inner.split_off(at);
String2 {
inner: other
}
}
#[inline]
pub fn split_at(&self, mid: usize) -> (String2, String2) {
let (a, b) = self.inner.split_at(mid);
(String2 { inner: a.to_vec() }, String2 { inner: b.to_vec() })
}
#[inline]
pub fn clear(&mut self) {
self.inner.clear()
}
#[inline]
pub fn iter(self) -> StrIterator {
self.into_iter()
}
}
impl<'a> From<&'a str> for String2 {
#[inline]
fn from(string: &'a str) -> String2 {
String2 {
inner: string.chars().collect()
}
}
}
impl From<String> for String2 {
#[inline]
fn from(string: String) -> String2 {
String2 {
inner: string.chars().collect()
}
}
}
impl From<Vec<char>> for String2 {
#[inline]
fn from(s: Vec<char>) -> String2 {
String2 {
inner: s
}
}
}
impl<'a> From<&'a [char]> for String2 {
#[inline]
fn from(s: &'a [char]) -> String2 {
String2 {
inner: s.to_vec()
}
}
}
impl<'a> From<&'a mut [char]> for String2 {
#[inline]
fn from(s: &'a mut [char]) -> String2 {
String2 {
inner: s.to_vec()
}
}
}
impl Into<String> for String2 {
fn into(self) -> String {
self.inner.iter().map(|c| c.encode_utf8(&mut [0; 4]).to_string()).collect()
}
}
impl<'a> Into<String> for &'a String2 {
fn into(self) -> String {
self.inner.iter().map(|c| c.encode_utf8(&mut [0; 4]).to_string()).collect()
}
}
impl Default for String2 {
#[inline]
fn default() -> String2 {
String2::new()
}
}
impl IntoIterator for String2 {
type Item = char;
type IntoIter = StrIterator;
#[inline]
fn into_iter(self) -> Self::IntoIter {
StrIterator {
inner: self.inner.into_iter()
}
}
}
pub struct StrIterator {
inner: ::std::vec::IntoIter<char>
}
impl Iterator for StrIterator {
type Item = char;
#[inline]
fn next(&mut self) -> Option<char> {
self.inner.next()
}
}
impl AsRef<String2> for String2 {
#[inline]
fn as_ref(&self) -> &String2 {
self
}
}
impl AsMut<String2> for String2 {
#[inline]
fn as_mut(&mut self) -> &mut String2 {
self
}
}
impl AsRef<[char]> for String2 {
#[inline]
fn as_ref(&self) -> &[char] {
&self.inner
}
}
impl AsMut<[char]> for String2 {
#[inline]
fn as_mut(&mut self) -> &mut [char] {
&mut self.inner
}
}
impl ops::Add for String2 {
type Output = String2;
#[inline]
fn add(self, other: String2) -> String2 {
let mut self2 = self;
let mut other = other;
self2.inner.append(&mut other.inner);
self2
}
}
impl ops::Add<char> for String2 {
type Output = String2;
#[inline]
fn add(mut self, other: char) -> String2 {
self.push(other);
self
}
}
impl<'a> ops::Add<&'a str> for String2 {
type Output = String2;
#[inline]
fn add(mut self, other: &str) -> String2 {
self.push_str(other);
self
}
}
impl ops::AddAssign for String2 {
#[inline]
fn add_assign(&mut self, other: String2) {
let mut other = other;
self.inner.append(other.inner.as_mut())
}
}
impl ops::AddAssign<char> for String2 {
#[inline]
fn add_assign(&mut self, other: char) {
self.push(other)
}
}
impl<'a> ops::AddAssign<&'a str> for String2 {
#[inline]
fn add_assign(&mut self, other: &str) {
self.push_str(other)
}
}
impl PartialEq for String2 {
#[inline]
fn eq(&self, other: &String2) -> bool {
self.inner == other.inner
}
}
impl PartialOrd for String2 {
#[inline]
fn partial_cmp(&self, other: &String2) -> Option<::std::cmp::Ordering> {
PartialOrd::partial_cmp(&self.inner, &other.inner)
}
}
impl ops::Index<usize> for String2 {
type Output = char;
#[inline]
fn index(&self, idx: usize) -> &char {
&self.inner[idx]
}
}
impl ops::Index<ops::Range<usize>> for String2 {
type Output = [char];
#[inline]
fn index(&self, range: ops::Range<usize>) -> &[char] {
self.inner.index(range)
}
}
impl ops::Index<ops::RangeFrom<usize>> for String2 {
type Output = [char];
#[inline]
fn index(&self, range: ops::RangeFrom<usize>) -> &[char] {
self.inner.index(range)
}
}
impl ops::Index<ops::RangeTo<usize>> for String2 {
type Output = [char];
#[inline]
fn index(&self, range: ops::RangeTo<usize>) -> &[char] {
self.inner.index(range)
}
}
impl ops::Index<ops::RangeFull> for String2 {
type Output = [char];
#[inline]
fn index(&self, _range: ops::RangeFull) -> &[char] {
self.as_ref()
}
}
impl ops::IndexMut<usize> for String2 {
#[inline]
fn index_mut(&mut self, idx: usize) -> &mut char {
&mut self.inner[idx]
}
}
impl ops::IndexMut<ops::Range<usize>> for String2 {
#[inline]
fn index_mut(&mut self, range: ops::Range<usize>) -> &mut [char] {
self.inner.index_mut(range)
}
}
impl ops::IndexMut<ops::RangeFrom<usize>> for String2 {
#[inline]
fn index_mut(&mut self, range: ops::RangeFrom<usize>) -> &mut [char] {
self.inner.index_mut(range)
}
}
impl ops::IndexMut<ops::RangeTo<usize>> for String2 {
#[inline]
fn index_mut(&mut self, range: ops::RangeTo<usize>) -> &mut [char] {
self.inner.index_mut(range)
}
}
impl ops::IndexMut<ops::RangeFull> for String2 {
#[inline]
fn index_mut(&mut self, range: ops::RangeFull) -> &mut [char] {
self.inner.index_mut(range)
}
}
impl fmt::Display for String2 {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s: String = self.into();
fmt::Display::fmt(&s, f)
}
}
impl fmt::Debug for String2 {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s: String = self.into();
fmt::Debug::fmt(&s, f)
}
}