Struct java_string::JavaStr

source ·
pub struct JavaStr { /* private fields */ }

Implementations§

source§

impl JavaStr

source

pub fn from_modified_utf8(bytes: &[u8]) -> Result<Cow<'_, JavaStr>, Utf8Error>

Converts from Java’s modified UTF-8 format to a Cow<JavaStr>.


let result = JavaStr::from_modified_utf8("Hello World!".as_bytes()).unwrap();
assert!(matches!(result, Cow::Borrowed(_)));
assert_eq!(JavaStr::from_str("Hello World!"), result);

let result = JavaStr::from_modified_utf8(&[
    0x61, 0x62, 0x63, 0xc0, 0x80, 0xe2, 0x84, 0x9d, 0xed, 0xa0, 0xbd, 0xed, 0xb2, 0xa3, 0xed,
    0xa0, 0x80,
])
.unwrap();
assert!(matches!(result, Cow::Owned(_)));
let mut expected = JavaString::from("abc\0ℝ💣");
expected.push_java(JavaCodePoint::from_u32(0xd800).unwrap());
assert_eq!(expected, result);

let result = JavaStr::from_modified_utf8(&[0xed]);
assert!(result.is_err());
source

pub fn to_modified_utf8(&self) -> Cow<'_, [u8]>

Converts to Java’s modified UTF-8 format.


let result = JavaStr::from_str("Hello World!").to_modified_utf8();
assert!(matches!(result, Cow::Borrowed(_)));
assert_eq!(result, &b"Hello World!"[..]);

let mut str = JavaString::from("abc\0ℝ💣");
str.push_java(JavaCodePoint::from_u32(0xd800).unwrap());
let result = str.to_modified_utf8();
let expected = [
    0x61, 0x62, 0x63, 0xc0, 0x80, 0xe2, 0x84, 0x9d, 0xed, 0xa0, 0xbd, 0xed, 0xb2, 0xa3, 0xed,
    0xa0, 0x80,
];
assert!(matches!(result, Cow::Owned(_)));
assert_eq!(result, &expected[..]);
source§

impl JavaStr

source

pub const fn from_full_utf8(v: &[u8]) -> Result<&JavaStr, Utf8Error>

Converts v to a &JavaStr if it is fully-valid UTF-8, i.e. UTF-8 without surrogate code points. See std::str::from_utf8.

source

pub fn from_full_utf8_mut(v: &mut [u8]) -> Result<&mut JavaStr, Utf8Error>

Converts v to a &mut JavaStr if it is fully-valid UTF-8, i.e. UTF-8 without surrogate code points. See std::str::from_utf8_mut.

source

pub fn from_semi_utf8(v: &[u8]) -> Result<&JavaStr, Utf8Error>

Converts v to a &JavaStr if it is semi-valid UTF-8, i.e. UTF-8 with surrogate code points.

source

pub fn from_semi_utf8_mut(v: &mut [u8]) -> Result<&mut JavaStr, Utf8Error>

Converts v to a &mut JavaStr if it is semi-valid UTF-8, i.e. UTF-8 with surrogate code points.

source

pub const unsafe fn from_semi_utf8_unchecked(v: &[u8]) -> &JavaStr

Safety

The parameter must be in semi-valid UTF-8 format, that is, UTF-8 plus surrogate code points.

source

pub unsafe fn from_semi_utf8_unchecked_mut(v: &mut [u8]) -> &mut JavaStr

Safety

The parameter must be in semi-valid UTF-8 format, that is, UTF-8 plus surrogate code points.

source

pub const fn from_str(str: &str) -> &JavaStr

source

pub fn from_mut_str(str: &mut str) -> &mut JavaStr

source

pub fn from_boxed_str(v: Box<str>) -> Box<JavaStr>

source

pub unsafe fn from_boxed_semi_utf8_unchecked(v: Box<[u8]>) -> Box<JavaStr>

Safety

The parameter must be in semi-valid UTF-8 format, that is, UTF-8 plus surrogate code points.

source

pub const fn as_bytes(&self) -> &[u8]

source

pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8]

See str::as_bytes_mut.

Safety

The returned slice must not have invalid UTF-8 written to it, besides surrogate pairs.

source

pub fn as_mut_ptr(&mut self) -> *mut u8

source

pub const fn as_ptr(&self) -> *const u8

source

pub const fn as_str(&self) -> Result<&str, Utf8Error>

Tries to convert this &JavaStr to a &str, returning an error if it is not fully valid UTF-8, i.e. has no surrogate code points.

source

pub const unsafe fn as_str_unchecked(&self) -> &str

Safety

This string must be fully valid UTF-8, i.e. have no surrogate code points.

source

pub fn as_str_lossy(&self) -> Cow<'_, str>

Converts this &JavaStr to a Cow<str>, replacing surrogate code points with the replacement character �.

let s = JavaStr::from_str("Hello 🦀 World!");
let result = s.as_str_lossy();
assert!(matches!(result, Cow::Borrowed(_)));
assert_eq!(result, "Hello 🦀 World!");

let s = JavaString::from("Hello ")
    + JavaString::from(JavaCodePoint::from_u32(0xd800).unwrap()).as_java_str()
    + JavaStr::from_str(" World!");
let result = s.as_str_lossy();
assert!(matches!(result, Cow::Owned(_)));
assert_eq!(result, "Hello � World!");
source

pub fn bytes(&self) -> Bytes<'_>

source

pub fn char_indices(&self) -> CharIndices<'_>

source

pub fn chars(&self) -> Chars<'_>

source

pub fn contains<P>(&self, pat: P) -> bool
where P: JavaStrPattern,

See str::contains.

let bananas = JavaStr::from_str("bananas");

assert!(bananas.contains("nana"));
assert!(!bananas.contains("apples"));
source

pub fn ends_with<P>(&self, pat: P) -> bool
where P: JavaStrPattern,

See str::ends_with.

let bananas = JavaStr::from_str("bananas");

assert!(bananas.ends_with("anas"));
assert!(!bananas.ends_with("nana"));
source

pub fn eq_ignore_ascii_case(&self, other: &str) -> bool

source

pub fn eq_java_ignore_ascii_case(&self, other: &JavaStr) -> bool

source

pub fn escape_debug(&self) -> EscapeDebug<'_>

See str::escape_debug.

assert_eq!(
    JavaStr::from_str("❤\n!").escape_debug().to_string(),
    "❤\\n!"
);
source

pub fn escape_default(&self) -> EscapeDefault<'_>

See str::escape_default.

assert_eq!(
    JavaStr::from_str("❤\n!").escape_default().to_string(),
    "\\u{2764}\\n!"
);
source

pub fn escape_unicode(&self) -> EscapeUnicode<'_>

See str::escape_unicode.

assert_eq!(
    JavaStr::from_str("❤\n!").escape_unicode().to_string(),
    "\\u{2764}\\u{a}\\u{21}"
);
source

pub fn find<P>(&self, pat: P) -> Option<usize>
where P: JavaStrPattern,

See str::find.

let s = "Löwe 老虎 Léopard Gepardi";

assert_eq!(s.find('L'), Some(0));
assert_eq!(s.find('é'), Some(14));
assert_eq!(s.find("pard"), Some(17));

let x: &[_] = &['1', '2'];
assert_eq!(s.find(x), None);
source

pub fn get<I>(&self, i: I) -> Option<&JavaStr>

See str::get.

let v = JavaString::from("🗻∈🌏");

assert_eq!(Some(JavaStr::from_str("🗻")), v.get(0..4));

// indices not on UTF-8 sequence boundaries
assert!(v.get(1..).is_none());
assert!(v.get(..8).is_none());

// out of bounds
assert!(v.get(..42).is_none());
source

pub fn get_mut<I>(&mut self, i: I) -> Option<&mut JavaStr>

source

pub unsafe fn get_unchecked<I>(&self, i: I) -> &JavaStr

See str::get_unchecked.

Safety
  • The starting index must not exceed the ending index
  • Indexes must be within bounds of the original slice
  • Indexes must lie on UTF-8 sequence boundaries
source

pub unsafe fn get_unchecked_mut<I>(&mut self, i: I) -> &mut JavaStr

See str::get_unchecked_mut.

Safety
  • The starting index must not exceed the ending index
  • Indexes must be within bounds of the original slice
  • Indexes must lie on UTF-8 sequence boundaries
source

pub fn into_boxed_bytes(self: Box<JavaStr>) -> Box<[u8]>

source

pub fn into_string(self: Box<JavaStr>) -> JavaString

source

pub fn is_ascii(&self) -> bool

source

pub fn is_char_boundary(&self, index: usize) -> bool

source

pub fn is_empty(&self) -> bool

source

pub fn len(&self) -> usize

See str::len.

source

pub fn lines(&self) -> Lines<'_>

source

pub fn make_ascii_lowercase(&mut self)

source

pub fn make_ascii_uppercase(&mut self)

source

pub fn match_indices<P>(&self, pat: P) -> MatchIndices<'_, P>
where P: JavaStrPattern,

See str::match_indices.

let v: Vec<_> = JavaStr::from_str("abcXXXabcYYYabc")
    .match_indices("abc")
    .collect();
assert_eq!(
    v,
    [
        (0, JavaStr::from_str("abc")),
        (6, JavaStr::from_str("abc")),
        (12, JavaStr::from_str("abc"))
    ]
);

let v: Vec<_> = JavaStr::from_str("1abcabc2").match_indices("abc").collect();
assert_eq!(
    v,
    [(1, JavaStr::from_str("abc")), (4, JavaStr::from_str("abc"))]
);

let v: Vec<_> = JavaStr::from_str("ababa").match_indices("aba").collect();
assert_eq!(v, [(0, JavaStr::from_str("aba"))]); // only the first `aba`
source

pub fn matches<P>(&self, pat: P) -> Matches<'_, P>
where P: JavaStrPattern,

See str::matches.

let v: Vec<&JavaStr> = JavaStr::from_str("abcXXXabcYYYabc")
    .matches("abc")
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("abc"),
        JavaStr::from_str("abc"),
        JavaStr::from_str("abc")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("1abc2abc3")
    .matches(JavaCodePoint::is_numeric)
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("1"),
        JavaStr::from_str("2"),
        JavaStr::from_str("3")
    ]
);
source

pub fn parse<F>(&self) -> Result<F, ParseError<<F as FromStr>::Err>>
where F: FromStr,

source

pub fn repeat(&self, n: usize) -> JavaString

source

pub fn replace<P>(&self, from: P, to: &str) -> JavaString
where P: JavaStrPattern,

See str::replace.

let s = JavaStr::from_str("this is old");

assert_eq!("this is new", s.replace("old", "new"));
assert_eq!("than an old", s.replace("is", "an"));
source

pub fn replace_java<P>(&self, from: P, to: &JavaStr) -> JavaString
where P: JavaStrPattern,

source

pub fn replacen<P>(&self, from: P, to: &str, count: usize) -> JavaString
where P: JavaStrPattern,

See str::replacen.

let s = JavaStr::from_str("foo foo 123 foo");
assert_eq!("new new 123 foo", s.replacen("foo", "new", 2));
assert_eq!("faa fao 123 foo", s.replacen('o', "a", 3));
assert_eq!(
    "foo foo new23 foo",
    s.replacen(JavaCodePoint::is_numeric, "new", 1)
);
source

pub fn replacen_java<P>( &self, from: P, to: &JavaStr, count: usize ) -> JavaString
where P: JavaStrPattern,

source

pub fn rfind<P>(&self, pat: P) -> Option<usize>
where P: JavaStrPattern,

See str::rfind.

let s = JavaStr::from_str("Löwe 老虎 Léopard Gepardi");

assert_eq!(s.rfind('L'), Some(13));
assert_eq!(s.rfind('é'), Some(14));
assert_eq!(s.rfind("pard"), Some(24));

let x: &[_] = &['1', '2'];
assert_eq!(s.rfind(x), None);
source

pub fn rmatch_indices<P>(&self, pat: P) -> RMatchIndices<'_, P>
where P: JavaStrPattern,

See str::rmatch_indices.

let v: Vec<_> = JavaStr::from_str("abcXXXabcYYYabc")
    .rmatch_indices("abc")
    .collect();
assert_eq!(
    v,
    [
        (12, JavaStr::from_str("abc")),
        (6, JavaStr::from_str("abc")),
        (0, JavaStr::from_str("abc"))
    ]
);

let v: Vec<_> = JavaStr::from_str("1abcabc2")
    .rmatch_indices("abc")
    .collect();
assert_eq!(
    v,
    [(4, JavaStr::from_str("abc")), (1, JavaStr::from_str("abc"))]
);

let v: Vec<_> = JavaStr::from_str("ababa").rmatch_indices("aba").collect();
assert_eq!(v, [(2, JavaStr::from_str("aba"))]); // only the last `aba`
source

pub fn rmatches<P>(&self, pat: P) -> RMatches<'_, P>
where P: JavaStrPattern,

See str::rmatches.

let v: Vec<&JavaStr> = JavaStr::from_str("abcXXXabcYYYabc")
    .rmatches("abc")
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("abc"),
        JavaStr::from_str("abc"),
        JavaStr::from_str("abc")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("1abc2abc3")
    .rmatches(JavaCodePoint::is_numeric)
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("3"),
        JavaStr::from_str("2"),
        JavaStr::from_str("1")
    ]
);
source

pub fn rsplit<P>(&self, pat: P) -> RSplit<'_, P>
where P: JavaStrPattern,

See str::rsplit.

let v: Vec<&JavaStr> = JavaStr::from_str("Mary had a little lamb")
    .rsplit(' ')
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("lamb"),
        JavaStr::from_str("little"),
        JavaStr::from_str("a"),
        JavaStr::from_str("had"),
        JavaStr::from_str("Mary")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("").rsplit('X').collect();
assert_eq!(v, [JavaStr::from_str("")]);

let v: Vec<&JavaStr> = JavaStr::from_str("lionXXtigerXleopard")
    .rsplit('X')
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("leopard"),
        JavaStr::from_str("tiger"),
        JavaStr::from_str(""),
        JavaStr::from_str("lion")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("lion::tiger::leopard")
    .rsplit("::")
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("leopard"),
        JavaStr::from_str("tiger"),
        JavaStr::from_str("lion")
    ]
);
source

pub fn rsplit_once<P>(&self, delimiter: P) -> Option<(&JavaStr, &JavaStr)>
where P: JavaStrPattern,

See str::rsplit_once.

assert_eq!(JavaStr::from_str("cfg").rsplit_once('='), None);
assert_eq!(
    JavaStr::from_str("cfg=foo").rsplit_once('='),
    Some((JavaStr::from_str("cfg"), JavaStr::from_str("foo")))
);
assert_eq!(
    JavaStr::from_str("cfg=foo=bar").rsplit_once('='),
    Some((JavaStr::from_str("cfg=foo"), JavaStr::from_str("bar")))
);
source

pub fn rsplit_terminator<P>(&self, pat: P) -> RSplitTerminator<'_, P>
where P: JavaStrPattern,

See str::rsplit_terminator.

let v: Vec<&JavaStr> = JavaStr::from_str("A.B.").rsplit_terminator('.').collect();
assert_eq!(v, [JavaStr::from_str("B"), JavaStr::from_str("A")]);

let v: Vec<&JavaStr> = JavaStr::from_str("A..B..").rsplit_terminator(".").collect();
assert_eq!(
    v,
    [
        JavaStr::from_str(""),
        JavaStr::from_str("B"),
        JavaStr::from_str(""),
        JavaStr::from_str("A")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("A.B:C.D")
    .rsplit_terminator(&['.', ':'][..])
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("D"),
        JavaStr::from_str("C"),
        JavaStr::from_str("B"),
        JavaStr::from_str("A")
    ]
);
source

pub fn rsplitn<P>(&self, n: usize, pat: P) -> RSplitN<'_, P>
where P: JavaStrPattern,

See str::rsplitn.

let v: Vec<&JavaStr> = JavaStr::from_str("Mary had a little lamb")
    .rsplitn(3, ' ')
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("lamb"),
        JavaStr::from_str("little"),
        JavaStr::from_str("Mary had a")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("lionXXtigerXleopard")
    .rsplitn(3, 'X')
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("leopard"),
        JavaStr::from_str("tiger"),
        JavaStr::from_str("lionX")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("lion::tiger::leopard")
    .rsplitn(2, "::")
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("leopard"),
        JavaStr::from_str("lion::tiger")
    ]
);
source

pub fn split<P>(&self, pat: P) -> Split<'_, P>
where P: JavaStrPattern,

See str::split.

let v: Vec<&JavaStr> = JavaStr::from_str("Mary had a little lamb")
    .split(' ')
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("Mary"),
        JavaStr::from_str("had"),
        JavaStr::from_str("a"),
        JavaStr::from_str("little"),
        JavaStr::from_str("lamb")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("").split('X').collect();
assert_eq!(v, [JavaStr::from_str("")]);

let v: Vec<&JavaStr> = JavaStr::from_str("lionXXtigerXleopard")
    .split('X')
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("lion"),
        JavaStr::from_str(""),
        JavaStr::from_str("tiger"),
        JavaStr::from_str("leopard")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("lion::tiger::leopard")
    .split("::")
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("lion"),
        JavaStr::from_str("tiger"),
        JavaStr::from_str("leopard")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("abc1def2ghi")
    .split(JavaCodePoint::is_numeric)
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("abc"),
        JavaStr::from_str("def"),
        JavaStr::from_str("ghi")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("lionXtigerXleopard")
    .split(JavaCodePoint::is_uppercase)
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("lion"),
        JavaStr::from_str("tiger"),
        JavaStr::from_str("leopard")
    ]
);
source

pub fn split_ascii_whitespace(&self) -> SplitAsciiWhitespace<'_>

See str::split_ascii_whitespace.

let mut iter = JavaStr::from_str(" Mary   had\ta little  \n\t lamb").split_ascii_whitespace();
assert_eq!(Some(JavaStr::from_str("Mary")), iter.next());
assert_eq!(Some(JavaStr::from_str("had")), iter.next());
assert_eq!(Some(JavaStr::from_str("a")), iter.next());
assert_eq!(Some(JavaStr::from_str("little")), iter.next());
assert_eq!(Some(JavaStr::from_str("lamb")), iter.next());

assert_eq!(None, iter.next());
source

pub fn split_at(&self, mid: usize) -> (&JavaStr, &JavaStr)

See str::split_at.

let s = JavaStr::from_str("Per Martin-Löf");

let (first, last) = s.split_at(3);

assert_eq!("Per", first);
assert_eq!(" Martin-Löf", last);
let s = JavaStr::from_str("Per Martin-Löf");
// Should panic
let _ = s.split_at(13);
source

pub fn split_at_mut(&mut self, mid: usize) -> (&mut JavaStr, &mut JavaStr)

See str::split_at_mut.

let mut s = JavaString::from("Per Martin-Löf");
let s = s.as_mut_java_str();

let (first, last) = s.split_at_mut(3);

assert_eq!("Per", first);
assert_eq!(" Martin-Löf", last);
let mut s = JavaString::from("Per Martin-Löf");
let s = s.as_mut_java_str();
// Should panic
let _ = s.split_at(13);
source

pub fn split_inclusive<P>(&self, pat: P) -> SplitInclusive<'_, P>
where P: JavaStrPattern,

See str::split_inclusive.

let v: Vec<&JavaStr> = JavaStr::from_str("Mary had a little lamb\nlittle lamb\nlittle lamb.\n")
    .split_inclusive('\n')
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("Mary had a little lamb\n"),
        JavaStr::from_str("little lamb\n"),
        JavaStr::from_str("little lamb.\n")
    ]
);
source

pub fn split_once<P>(&self, delimiter: P) -> Option<(&JavaStr, &JavaStr)>
where P: JavaStrPattern,

See str::split_once.

assert_eq!(JavaStr::from_str("cfg").split_once('='), None);
assert_eq!(
    JavaStr::from_str("cfg=").split_once('='),
    Some((JavaStr::from_str("cfg"), JavaStr::from_str("")))
);
assert_eq!(
    JavaStr::from_str("cfg=foo").split_once('='),
    Some((JavaStr::from_str("cfg"), JavaStr::from_str("foo")))
);
assert_eq!(
    JavaStr::from_str("cfg=foo=bar").split_once('='),
    Some((JavaStr::from_str("cfg"), JavaStr::from_str("foo=bar")))
);
source

pub fn split_terminator<P>(&self, pat: P) -> SplitTerminator<'_, P>
where P: JavaStrPattern,

See str::split_terminator.

let v: Vec<&JavaStr> = JavaStr::from_str("A.B.").split_terminator('.').collect();
assert_eq!(v, [JavaStr::from_str("A"), JavaStr::from_str("B")]);

let v: Vec<&JavaStr> = JavaStr::from_str("A..B..").split_terminator(".").collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("A"),
        JavaStr::from_str(""),
        JavaStr::from_str("B"),
        JavaStr::from_str("")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("A.B:C.D")
    .split_terminator(&['.', ':'][..])
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("A"),
        JavaStr::from_str("B"),
        JavaStr::from_str("C"),
        JavaStr::from_str("D")
    ]
);
source

pub fn split_whitespace(&self) -> SplitWhitespace<'_>

source

pub fn splitn<P>(&self, n: usize, pat: P) -> SplitN<'_, P>
where P: JavaStrPattern,

See str::splitn.

let v: Vec<&JavaStr> = JavaStr::from_str("Mary had a little lambda")
    .splitn(3, ' ')
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("Mary"),
        JavaStr::from_str("had"),
        JavaStr::from_str("a little lambda")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("lionXXtigerXleopard")
    .splitn(3, "X")
    .collect();
assert_eq!(
    v,
    [
        JavaStr::from_str("lion"),
        JavaStr::from_str(""),
        JavaStr::from_str("tigerXleopard")
    ]
);

let v: Vec<&JavaStr> = JavaStr::from_str("abcXdef").splitn(1, 'X').collect();
assert_eq!(v, [JavaStr::from_str("abcXdef")]);

let v: Vec<&JavaStr> = JavaStr::from_str("").splitn(1, 'X').collect();
assert_eq!(v, [JavaStr::from_str("")]);
source

pub fn starts_with<P>(&self, pat: P) -> bool
where P: JavaStrPattern,

See str::starts_with.

let bananas = JavaStr::from_str("bananas");

assert!(bananas.starts_with("bana"));
assert!(!bananas.starts_with("nana"));
source

pub fn strip_prefix<P>(&self, prefix: P) -> Option<&JavaStr>
where P: JavaStrPattern,

See str::strip_prefix.

assert_eq!(
    JavaStr::from_str("foo:bar").strip_prefix("foo:"),
    Some(JavaStr::from_str("bar"))
);
assert_eq!(JavaStr::from_str("foo:bar").strip_prefix("bar"), None);
assert_eq!(
    JavaStr::from_str("foofoo").strip_prefix("foo"),
    Some(JavaStr::from_str("foo"))
);
source

pub fn strip_suffix<P>(&self, suffix: P) -> Option<&JavaStr>
where P: JavaStrPattern,

See str::strip_suffix.

assert_eq!(
    JavaStr::from_str("bar:foo").strip_suffix(":foo"),
    Some(JavaStr::from_str("bar"))
);
assert_eq!(JavaStr::from_str("bar:foo").strip_suffix("bar"), None);
assert_eq!(
    JavaStr::from_str("foofoo").strip_suffix("foo"),
    Some(JavaStr::from_str("foo"))
);
source

pub fn to_ascii_lowercase(&self) -> JavaString

source

pub fn to_ascii_uppercase(&self) -> JavaString

source

pub fn to_lowercase(&self) -> JavaString

See str::to_lowercase.

let s = JavaStr::from_str("HELLO");
assert_eq!("hello", s.to_lowercase());

let odysseus = JavaStr::from_str("ὈΔΥΣΣΕΎΣ");
assert_eq!("ὀδυσσεύς", odysseus.to_lowercase());

let s = JavaString::from("Hello ")
    + JavaString::from(JavaCodePoint::from_u32(0xd800).unwrap()).as_java_str()
    + JavaStr::from_str(" World!");
let expected = JavaString::from("hello ")
    + JavaString::from(JavaCodePoint::from_u32(0xd800).unwrap()).as_java_str()
    + JavaStr::from_str(" world!");
assert_eq!(expected, s.to_lowercase());
source

pub fn to_uppercase(&self) -> JavaString

See str::to_uppercase.

let s = JavaStr::from_str("hello");
assert_eq!("HELLO", s.to_uppercase());

let s = JavaStr::from_str("tschüß");
assert_eq!("TSCHÜSS", s.to_uppercase());

let s = JavaString::from("Hello ")
    + JavaString::from(JavaCodePoint::from_u32(0xd800).unwrap()).as_java_str()
    + JavaStr::from_str(" World!");
let expected = JavaString::from("HELLO ")
    + JavaString::from(JavaCodePoint::from_u32(0xd800).unwrap()).as_java_str()
    + JavaStr::from_str(" WORLD!");
assert_eq!(expected, s.to_uppercase());
source

pub fn trim(&self) -> &JavaStr

See str::trim.

source

pub fn trim_end(&self) -> &JavaStr

source

pub fn trim_end_matches<P>(&self, pat: P) -> &JavaStr
where P: JavaStrPattern,

See str::trim_end_matches.

assert_eq!(
    JavaStr::from_str("11foo1bar11").trim_end_matches('1'),
    "11foo1bar"
);
assert_eq!(
    JavaStr::from_str("123foo1bar123").trim_end_matches(JavaCodePoint::is_numeric),
    "123foo1bar"
);

let x: &[_] = &['1', '2'];
assert_eq!(
    JavaStr::from_str("12foo1bar12").trim_end_matches(x),
    "12foo1bar"
);
source

pub fn trim_matches<P>(&self, pat: P) -> &JavaStr
where P: JavaStrPattern,

See str::trim_matches.

assert_eq!(
    JavaStr::from_str("11foo1bar11").trim_matches('1'),
    "foo1bar"
);
assert_eq!(
    JavaStr::from_str("123foo1bar123").trim_matches(JavaCodePoint::is_numeric),
    "foo1bar"
);

let x: &[_] = &['1', '2'];
assert_eq!(JavaStr::from_str("12foo1bar12").trim_matches(x), "foo1bar");
source

pub fn trim_start(&self) -> &JavaStr

source

pub fn trim_start_matches<P>(&self, pat: P) -> &JavaStr
where P: JavaStrPattern,

See str::trim_start_matches.

assert_eq!(
    JavaStr::from_str("11foo1bar11").trim_start_matches('1'),
    "foo1bar11"
);
assert_eq!(
    JavaStr::from_str("123foo1bar123").trim_start_matches(JavaCodePoint::is_numeric),
    "foo1bar123"
);

let x: &[_] = &['1', '2'];
assert_eq!(
    JavaStr::from_str("12foo1bar12").trim_start_matches(x),
    "foo1bar12"
);

Trait Implementations§

source§

impl<'a> Add<&JavaStr> for Cow<'a, JavaStr>

§

type Output = Cow<'a, JavaStr>

The resulting type after applying the + operator.
source§

fn add(self, rhs: &JavaStr) -> Self::Output

Performs the + operation. Read more
source§

impl Add<&JavaStr> for JavaString

§

type Output = JavaString

The resulting type after applying the + operator.
source§

fn add(self, rhs: &JavaStr) -> Self::Output

Performs the + operation. Read more
source§

impl<'a> AddAssign<&JavaStr> for Cow<'a, JavaStr>

source§

fn add_assign(&mut self, rhs: &JavaStr)

Performs the += operation. Read more
source§

impl AddAssign<&JavaStr> for JavaString

source§

fn add_assign(&mut self, rhs: &JavaStr)

Performs the += operation. Read more
source§

impl AsMut<JavaStr> for JavaString

source§

fn as_mut(&mut self) -> &mut JavaStr

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<[u8]> for JavaStr

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<JavaStr> for Drain<'_>

source§

fn as_ref(&self) -> &JavaStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<JavaStr> for JavaString

source§

fn as_ref(&self) -> &JavaStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<JavaStr> for String

source§

fn as_ref(&self) -> &JavaStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<JavaStr> for str

source§

fn as_ref(&self) -> &JavaStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<JavaStr> for JavaString

source§

fn borrow(&self) -> &JavaStr

Immutably borrows from an owned value. Read more
source§

impl BorrowMut<JavaStr> for JavaString

source§

fn borrow_mut(&mut self) -> &mut JavaStr

Mutably borrows from an owned value. Read more
source§

impl Clone for Box<JavaStr>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for JavaStr

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for &JavaStr

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Default for Box<JavaStr>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for JavaStr

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Extend<&'a JavaStr> for JavaString

source§

fn extend<T: IntoIterator<Item = &'a JavaStr>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl From<&JavaStr> for Arc<JavaStr>

source§

fn from(value: &JavaStr) -> Self

Converts to this type from the input type.
source§

impl From<&JavaStr> for Box<JavaStr>

source§

fn from(value: &JavaStr) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a JavaStr> for Cow<'a, JavaStr>

source§

fn from(value: &'a JavaStr) -> Self

Converts to this type from the input type.
source§

impl From<&JavaStr> for JavaString

source§

fn from(value: &JavaStr) -> Self

Converts to this type from the input type.
source§

impl From<&JavaStr> for Rc<JavaStr>

source§

fn from(value: &JavaStr) -> Self

Converts to this type from the input type.
source§

impl From<&JavaStr> for Vec<u8>

source§

fn from(value: &JavaStr) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a String> for &'a JavaStr

source§

fn from(value: &'a String) -> Self

Converts to this type from the input type.
source§

impl From<&mut JavaStr> for JavaString

source§

fn from(value: &mut JavaStr) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for &'a JavaStr

source§

fn from(value: &'a str) -> Self

Converts to this type from the input type.
source§

impl From<Cow<'_, JavaStr>> for Box<JavaStr>

source§

fn from(value: Cow<'_, JavaStr>) -> Self

Converts to this type from the input type.
source§

impl From<JavaString> for Box<JavaStr>

source§

fn from(value: JavaString) -> Self

Converts to this type from the input type.
source§

impl Hash for JavaStr

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
source§

impl<I> Index<I> for JavaStr

§

type Output = JavaStr

The returned type after indexing.
source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<I> IndexMut<I> for JavaStr

source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl JavaStrPattern for &JavaStr

source§

fn prefix_len_in(&mut self, haystack: &JavaStr) -> Option<usize>

source§

fn suffix_len_in(&mut self, haystack: &JavaStr) -> Option<usize>

source§

fn find_in(&mut self, haystack: &JavaStr) -> Option<(usize, usize)>

source§

fn rfind_in(&mut self, haystack: &JavaStr) -> Option<(usize, usize)>

source§

impl Ord for JavaStr

source§

fn cmp(&self, other: &JavaStr) -> Ordering

This method returns an Ordering between self and other. Read more
source§

impl<'a, 'b> PartialEq<&'b JavaStr> for Cow<'a, JavaStr>

source§

fn eq(&self, other: &&'b JavaStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<&'b JavaStr> for Cow<'a, str>

source§

fn eq(&self, other: &&'b JavaStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<&'a JavaStr> for JavaStr

source§

fn eq(&self, other: &&'a JavaStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<&'a JavaStr> for JavaString

source§

fn eq(&self, other: &&'a JavaStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<&'a str> for JavaStr

source§

fn eq(&self, other: &&'a str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<Cow<'a, JavaStr>> for &'b JavaStr

source§

fn eq(&self, other: &Cow<'a, JavaStr>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<Cow<'a, JavaStr>> for JavaStr

source§

fn eq(&self, other: &Cow<'a, JavaStr>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<Cow<'a, str>> for &'b JavaStr

source§

fn eq(&self, other: &Cow<'a, str>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<Cow<'a, str>> for JavaStr

source§

fn eq(&self, other: &Cow<'a, str>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<JavaStr> for &'a JavaStr

source§

fn eq(&self, other: &JavaStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<JavaStr> for &'a str

source§

fn eq(&self, other: &JavaStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<JavaStr> for Cow<'a, JavaStr>

source§

fn eq(&self, other: &JavaStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<JavaStr> for Cow<'a, str>

source§

fn eq(&self, other: &JavaStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<JavaStr> for JavaString

source§

fn eq(&self, other: &JavaStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<JavaStr> for String

source§

fn eq(&self, other: &JavaStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<JavaStr> for str

source§

fn eq(&self, other: &JavaStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<JavaString> for &'a JavaStr

source§

fn eq(&self, other: &JavaString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<JavaString> for JavaStr

source§

fn eq(&self, other: &JavaString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<String> for &'a JavaStr

source§

fn eq(&self, other: &String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<String> for JavaStr

source§

fn eq(&self, other: &String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<str> for JavaStr

source§

fn eq(&self, other: &str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for JavaStr

source§

fn eq(&self, other: &JavaStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for JavaStr

source§

fn partial_cmp(&self, other: &JavaStr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl ToOwned for JavaStr

§

type Owned = JavaString

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl Eq for JavaStr

source§

impl StructuralEq for JavaStr

source§

impl StructuralPartialEq for JavaStr

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more