# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/10_strs.ipynb.

# %% auto 0
__all__ = ['isallstr', 'isprivate', 'ismangled', 'issunder', 'isdunder', 'isnilstr', 'ispublic', 'isstar', 'iselps', 'ispipe',
           'ispunc', 'isupper', 'islower', 'isquote', 'ischar', 'ischars', 'isstrbytes', 'notstrbytes', 'isuniqchrs',
           'isdig', 'isdotstr', 'ispipestr']

# %% ../nbs/10_strs.ipynb 4
import string
from typing import TypeGuard

from typing import Union, Literal, Iterable

# %% ../nbs/10_strs.ipynb 5
from .core import isiter, isstr, isbytes

# %% ../nbs/10_strs.ipynb 7
def isallstr(x) -> TypeGuard[Iterable[str]]:
    '''Check if `x` is an `Iterable[str]`.'''
    return isiter(x) and all(isstr(e) for e in x)

# %% ../nbs/10_strs.ipynb 9
def isprivate(s: str) -> TypeGuard[str]:
    '''Check if `s` is a private variable name e.g. `'_{anything}'`.'''
    return isstr(s) and s.startswith('_') and len(s) > 1

def ismangled(s: str) -> TypeGuard[str]:
    '''Check if `s` is an mangled variable name e.g. `'__{anything}'`.'''
    return isstr(s) and s.startswith('__') and len(s) > 2

def issunder(s: str) -> TypeGuard[str]:
    '''Check if `s` is a sunder e.g. `'_{anything}_'`.'''
    return isstr(s) and s.startswith('_') and s.endswith('_') and len(s) > 2

def isdunder(s: str) -> TypeGuard[str]:
    '''Check if `s` is an dunder e.g. `'__{anything}__'`.'''
    return isstr(s) and s.startswith('__') and s.endswith('__') and len(s) > 4

def isnilstr(s: str) -> TypeGuard[Literal['']]:
    '''Check if `s` is the nil string `''`.'''
    return isstr(s) and len(s) == 0

def ispublic(s: str) -> TypeGuard[str]:
    '''Check if `s` is a public variable name e.g. `'{anything}'`.'''
    return isstr(s) and not isprivate(s) and not ismangled(s) and not issunder(s) and not isdunder(s)

# %% ../nbs/10_strs.ipynb 10
def isstar(s: str) -> TypeGuard[Literal['*']]:
    '''Check if `s` is an asterick string `'*'`.'''
    return isstr(s) and s == '*'

def iselps(s: str) -> TypeGuard[Literal['...']]:
    '''Check if `s` is an ellipse string `...''`.'''
    return isstr(s) and s == '...'


def ispipe(s: str) -> TypeGuard[Literal['|']]:
    '''Check if `s` is a pipe string `'|'`.'''
    return isstr(s) and s == '|'

# %% ../nbs/10_strs.ipynb 11
def ispunc(s: str) -> TypeGuard[str]:
    return isstr(s) and s in string.punctuation

def isupper(s: str) -> TypeGuard[str]:
    return isstr(s) and s in string.ascii_uppercase

def islower(s: str) -> TypeGuard[str]:
    return isstr(s) and s in string.ascii_lowercase

# %% ../nbs/10_strs.ipynb 12
def isquote(s: str) -> TypeGuard[Literal['"', "'"]]:
    '''Check if `s` is a single or double quote string `'` or `"`.'''
    return isstr(s) and ispunc(s) and s in {'"', "'"}

# %% ../nbs/10_strs.ipynb 13
def ischar(s: str, char: str = '') -> TypeGuard[str]:
    '''Checks if a `s` is `char`.'''
    return isstr(s) and isstr(char) and s == char

def ischars(s: str, chars: str = string.punctuation) -> TypeGuard[str]:
    '''Checks if a string only contains characters from a set of valid characters.'''
    return all(c in chars for c in s)

# %% ../nbs/10_strs.ipynb 14
def isstrbytes(s: str) -> TypeGuard[Union[str, bytes]]:
    '''Checks if a `s` is either `str` or `bytes`.'''
    return isstr(s) or isbytes(s)

def notstrbytes(s: str) -> TypeGuard[Union[str, bytes]]:
    '''Checks if a `s` is neither `str` or `bytes`.'''
    return not isstrbytes(s)

# %% ../nbs/10_strs.ipynb 15
def isuniqchrs(s: str) -> bool: # isuniq
    '''Checks if a string only contains unique characters.'''
    return len(set(s)) == len(s)

# %% ../nbs/10_strs.ipynb 16
def isdig(s: str) -> TypeGuard[str]:
    '''Check if `s` is a digit character'''
    return isstr(s) and str.isdigit(s)

def isdotstr(s: str) -> TypeGuard[str]:
    '''Check if `s` is a dot str e.g. `'3.10.12.410'`'''
    return isstr(s) and all(isdig(e) for e in s.split('.'))    

def ispipestr(s: str) -> TypeGuard[str]:
    '''Check if `s` contains a pipe.'''
    return isstr(s) and any(map(ispipe, s))
