pub fn safesplit_once(s: &str, sep: char) -> Result<(&str, &str), SafesplitOnceError> {
    if s.is_empty() {
        return Err(SafesplitOnceError::SeparatorNotFound);
    }
    let mut level: i32 = 0;
    for (i, c) in s.char_indices() {
        if c == sep && level == 0 {
            return Ok((&s[..i], &s[i + sep.len_utf8()..]));
        } else if c == '{' {
            level += 1;
        } else if c == '}' {
            level -= 1;
        }
    }
    Err(SafesplitOnceError::SeparatorNotFound)
}
/// Splits string precisely once at the first occurence of the separation
/// characer that is not enclosed in curly braces.
///
/// # Errors
///
/// Returns `Err` if the separation character is not found.
///
/// # Examples
///
/// ```
/// assert_eq!(stringly::util::safesplit_once("a,b", ','), Ok(("a", "b")));
/// assert_eq!(stringly::util::safesplit_once("{a,b}", ','), Err(stringly::util::SafesplitOnceError::SeparatorNotFound));
/// ```
Splits string precisely once at the first occurence of the separation
characer that is not enclosed in curly braces.
Splits string precisely once at the first occurence of the separation characer that is not enclosed in curly braces .
pub fn safesplit_once(s: &str, sep: char) -> Result<(&str, &str), SafesplitOnceError> {
    if s.is_empty() {
        return Err(SafesplitOnceError::SeparatorNotFound);
    }
    let mut level: i32 = 0;
    for (i, c) in s.char_indices() {
        if c == sep && level == 0 {
            return Ok((&s[..i], &s[i + sep.len_utf8()..]));
        } else if c == '{' {
            level += 1;
        } else if c == '}' {
            level -= 1;
        }
    }
    Err(SafesplitOnceError::SeparatorNotFound)
}
pub fn safesplit_once ( s : & str , sep : char ) -> Result < ( & str , & str ) , SafesplitOnceError > { if s . is_empty ( ) { return Err ( SafesplitOnceError :: SeparatorNotFound ) ; } let mut level : i32 = 0 ; for ( i , c ) in s . char_indices ( ) { if c == sep && level == 0 { return Ok ( ( & s [ .. i ] , & s [ i + sep . len_utf8 ( ) .. ] ) ) ; } else if c == '{' { level += 1 ; } else if c == '}' { level -= 1 ; } } Err ( SafesplitOnceError :: SeparatorNotFound ) }
Splits string precisely once at the first occurence of the separation
characer that is not enclosed in curly braces.
Splits string precisely once at the first occurence of the separation characer that is not enclosed in curly braces .
s
&str
sep
char
s
&str
sep
char
errors
Returns `Err` if the separation character is not found.
Returns ` Err ` if the separation character is not found .
examples
```
assert_eq!(stringly::util::safesplit_once("a,b", ','), Ok(("a", "b")));
assert_eq!(stringly::util::safesplit_once("{a,b}", ','), Err(stringly::util::SafesplitOnceError::SeparatorNotFound));
```
` ` ` assert_eq! ( stringly :: util :: safesplit_once ( " a b " ' ' ) Ok (( " a " " b " ))) ; assert_eq! ( stringly :: util :: safesplit_once ( " { a b } " ' ' ) Err ( stringly :: util :: SafesplitOnceError :: SeparatorNotFound )) ; ` ` `