<commit_before>//! # An rope.
//!
//! A rope is an efficient data structure for large mutable strings. It's
//! essentially a binary tree whose leaves are strings.
//!
//! For more information, see the following resources:
//!
//! + http://scienceblogs.com/goodmath/2009/01/26/ropes-twining-together-strings/
//! + https://www.ibm.com/developerworks/library/j-ropes/
//! + http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.14.9450&rep=rep1&type=pdf

#![cfg_attr( feature = "unstable"
           , feature( const_fn
                    , box_syntax, box_patterns
                    , conservative_impl_trait
                    , collections, collections_range
                    , inclusive_range_syntax
                    ))]
#![cfg_attr( all( test, feature = "unstable")
           , feature( test, insert_str) )]
#![cfg_attr( feature = "clippy", feature(plugin) )]
#![cfg_attr( feature = "clippy", plugin(clippy) )]

#[cfg(feature = "unstable")]
extern crate collections;
#[cfg(feature = "unstable")]
use collections::range::RangeArgument;

extern crate unicode_segmentation;


use std::borrow::Borrow;
use std::cmp;
use std::ops;
use std::convert;
use std::fmt;
use std::string;
use std::iter;

#[cfg(feature = "tendril")] extern crate tendril;
#[cfg(feature = "tendril")] use tendril::StrTendril;

#[cfg(test)] #[macro_use] extern crate quickcheck;
#[cfg(test)] mod test;
#[cfg(all( test, feature = "unstable"))] mod bench;

mod unicode;
mod metric;

use self::internals::Node;
pub use self::slice::{RopeSlice, RopeSliceMut};

/// A Rope
///
/// This Rope implementation aims to eventually function as a superset of
/// [`String`](https://doc.rust-lang.org/1.3.0/std/string/struct.String.html),
/// providing the same API plus additional methods. Therefore, code which uses
/// `String` can easily be ported to use `Rope`.
///
/// `Rope` provides two APIs for editing a `Rope`: a destructive,
/// append-in-place API whose methods match those of `String`, and a
/// non-destructive, persistant API. The persistant API's methods have names
/// prefixed with `with_`, such as `with_push()` and `with_append()`.
///
#[derive(Clone, Default)]
pub struct Rope {
    // can we get away with having these be of &str or will they need
    // to be string?
    root: Node
}

impl fmt::Debug for Rope {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Rope[\"{}\"] {:?}", self.root, self.root)
    }
}
 #[cfg(feature = "unstable")]
macro_rules! unstable_iters {
    ( $($(#[$attr:meta])*
     pub fn $name:ident$(<$lf:tt>)*(&'a $sel:ident) -> $ty:ty {
         $body:expr
     })+ ) => { $(
         $(#[$attr])*
         pub fn $name$(<$lf>)*(&'a $sel) -> $ty {
             $body
         }
    )+ };
    ( $($(#[$attr:meta])*
    pub fn $name:ident$(<$lf:tt>)*(&'a mut $sel:ident) -> $ty:ty {
         $body:expr
     })+ ) => { $(
         $(#[$attr])*
         #[cfg(feature = "unstable")]
         pub fn $name$(<$lf>)*(&'a mut $sel) -> $ty {
             $body
         }
    )+ };
}

#[cfg(not(feature = "unstable"))]
macro_rules! unstable_iters {
    ( $($(#[$attr:meta])*
    pub fn $name:ident$(<$lf:tt>)*(&'a $sel:ident) -> impl Iterator<Item=$ty:ty> + 'a {
         $body:expr
     })+ ) => ($(
         $(#[$attr])*
         #[cfg(not(feature = "unstable"))]
         pub fn $name$(<$lf>)*(&'a $sel) -> Box<Iterator<Item=$ty> + 'a> {
             Box::new($body)
         }
     )+);
    ( $( $(#[$attr:meta])*
    pub fn $name:ident$(<$lf:tt>)*(&'a mut $sel:ident) - impl Iterator<Item=$ty:ty> + 'a {
         $body:expr
     })+ ) => { $({
         $(#[$attr])*
         #[cfg(not(feature = "unstable"))]
         pub fn $name$(<$lf>)*(&'a mut $sel) -> Box<Iterator<Item=$ty> + 'a> {<commit_msg>chore(Rope): fix incorrect clippy lifetime lint in macros<commit_after>//! # An rope.
//!
//! A rope is an efficient data structure for large mutable strings. It's
//! essentially a binary tree whose leaves are strings.
//!
//! For more information, see the following resources:
//!
//! + http://scienceblogs.com/goodmath/2009/01/26/ropes-twining-together-strings/
//! + https://www.ibm.com/developerworks/library/j-ropes/
//! + http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.14.9450&rep=rep1&type=pdf

#![cfg_attr( feature = "unstable"
           , feature( const_fn
                    , box_syntax, box_patterns
                    , conservative_impl_trait
                    , collections, collections_range
                    , inclusive_range_syntax
                    ))]
#![cfg_attr( all( test, feature = "unstable")
           , feature( test, insert_str) )]
#![cfg_attr( feature = "clippy", feature(plugin) )]
#![cfg_attr( feature = "clippy", plugin(clippy) )]

#[cfg(feature = "unstable")]
extern crate collections;
#[cfg(feature = "unstable")]
use collections::range::RangeArgument;

extern crate unicode_segmentation;


use std::borrow::Borrow;
use std::cmp;
use std::ops;
use std::convert;
use std::fmt;
use std::string;
use std::iter;

#[cfg(feature = "tendril")] extern crate tendril;
#[cfg(feature = "tendril")] use tendril::StrTendril;

#[cfg(test)] #[macro_use] extern crate quickcheck;
#[cfg(test)] mod test;
#[cfg(all( test, feature = "unstable"))] mod bench;

mod unicode;
mod metric;

use self::internals::Node;
pub use self::slice::{RopeSlice, RopeSliceMut};

/// A Rope
///
/// This Rope implementation aims to eventually function as a superset of
/// [`String`](https://doc.rust-lang.org/1.3.0/std/string/struct.String.html),
/// providing the same API plus additional methods. Therefore, code which uses
/// `String` can easily be ported to use `Rope`.
///
/// `Rope` provides two APIs for editing a `Rope`: a destructive,
/// append-in-place API whose methods match those of `String`, and a
/// non-destructive, persistant API. The persistant API's methods have names
/// prefixed with `with_`, such as `with_push()` and `with_append()`.
///
#[derive(Clone, Default)]
pub struct Rope {
    // can we get away with having these be of &str or will they need
    // to be string?
    root: Node
}

impl fmt::Debug for Rope {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Rope[\"{}\"] {:?}", self.root, self.root)
    }
}
 #[cfg(feature = "unstable")]
macro_rules! unstable_iters {
    ( $($(#[$attr:meta])*
     pub fn $name:ident$(<$lf:tt>)*(&'a $sel:ident) -> $ty:ty {
         $body:expr
     })+ ) => { $(
         $(#[$attr])*
         #[cfg_attr(feature = "clippy", allow(needless_lifetimes))]
         pub fn $name$(<$lf>)*(&'a $sel) -> $ty {
             $body
         }
    )+ };
    ( $($(#[$attr:meta])*
    pub fn $name:ident$(<$lf:tt>)*(&'a mut $sel:ident) -> $ty:ty {
         $body:expr
     })+ ) => { $(
         $(#[$attr])*
         #[cfg(feature = "unstable")]
         #[cfg_attr(feature = "clippy", allow(needless_lifetimes))]
         pub fn $name$(<$lf>)*(&'a mut $sel) -> $ty {
             $body
         }
    )+ };
}

#[cfg(not(feature = "unstable"))]
macro_rules! unstable_iters {
    ( $($(#[$attr:meta])*
    pub fn $name:ident$(<$lf:tt>)*(&'a $sel:ident) -> impl Iterator<Item=$ty:ty> + 'a {
         $body:expr
     })+ ) => ($(
         $(#[$attr])*
         #[cfg(not(feature = "unstable"))]
         #[cfg_attr(feature = "clippy", allow(needless_lifetimes))]
         pub fn $name$(<$lf>)*(&'a $sel) -> Box<Iterator<Item=$ty> + 'a> {
             Box::new($body)
         }
     )+);
    ( $( $(#[$attr:meta])*
    pub fn $name:ident$(<$lf:tt>)*(&'a mut $sel:ident) - impl Iterator<Item=$ty:ty> + 'a {
         $body:expr
     })+ ) => { $({
         $(#[$attr])*
         #[cfg(not(feature = "unstable"))]
         #[cfg_attr(feature = "clippy", allow(needless_lifetimes))]
         pub fn $name$(<$lf>)*(&'a mut $sel) -> Box<Iterator<Item=$ty> + 'a> {
{'fraction_non_alphanumeric': 0.2031009738595592, 'fraction_numerical': 0.005638134290107637, 'mean_word_length': 2.875372393247269, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 55, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '701015', 'n_tokens_mistral': 2776, 'n_tokens_neox': 2654, 'n_words': 631}