Data.String.NonEmpty
- Package
- strings
- Repository
- purerl/purescript-strings
Re-exports from Data.String.NonEmpty.CodePoints
#uncons Source
uncons :: NonEmptyString -> { head :: CodePoint, tail :: Maybe NonEmptyString }
#takeWhile Source
takeWhile :: (CodePoint -> Boolean) -> NonEmptyString -> Maybe NonEmptyString
#take Source
take :: Int -> NonEmptyString -> Maybe NonEmptyString
#splitAt Source
splitAt :: Int -> NonEmptyString -> { after :: Maybe NonEmptyString, before :: Maybe NonEmptyString }
#singleton Source
singleton :: CodePoint -> NonEmptyString
#length Source
length :: NonEmptyString -> Int
#lastIndexOf' Source
lastIndexOf' :: Pattern -> Int -> NonEmptyString -> Maybe Int
#lastIndexOf Source
lastIndexOf :: Pattern -> NonEmptyString -> Maybe Int
#fromFoldable1 Source
fromFoldable1 :: forall f. Foldable1 f => f CodePoint -> NonEmptyString
#dropWhile Source
dropWhile :: (CodePoint -> Boolean) -> NonEmptyString -> Maybe NonEmptyString
#drop Source
drop :: Int -> NonEmptyString -> Maybe NonEmptyString
#countPrefix Source
countPrefix :: (CodePoint -> Boolean) -> NonEmptyString -> Int
#codePointAt Source
codePointAt :: Int -> NonEmptyString -> Maybe CodePoint
Re-exports from Data.String.NonEmpty.Internal
#NonEmptyString Source
newtype NonEmptyString
A string that is known not to be empty.
You can use this constructor to create a NonEmptyString
that isn't
non-empty, breaking the guarantee behind this newtype. It is
provided as an escape hatch mainly for the Data.NonEmpty.CodeUnits
and Data.NonEmpty.CodePoints
modules. Use this at your own risk
when you know what you are doing.
Instances
#NonEmptyReplacement Source
newtype NonEmptyReplacement
A newtype used in cases to specify a non-empty replacement for a pattern.
Constructors
Instances
#MakeNonEmpty Source
class MakeNonEmpty :: Symbol -> Constraint
class MakeNonEmpty (s :: Symbol) where
A helper class for defining non-empty string values at compile time.
something :: NonEmptyString
something = nes (Proxy :: Proxy "something")
Members
nes :: forall proxy. proxy s -> NonEmptyString
Instances
(Fail (Text "Cannot create an NonEmptyString from an empty Symbol")) => MakeNonEmpty ""
(IsSymbol s) => MakeNonEmpty s
#unsafeFromString Source
unsafeFromString :: Partial => String -> NonEmptyString
A partial version of fromString
.
#trim Source
trim :: NonEmptyString -> Maybe NonEmptyString
Removes whitespace from the beginning and end of a string, including whitespace characters and line terminators. If the string is entirely made up of whitespace the result will be Nothing.
trim (NonEmptyString " Hello \n World\n\t ") == Just (NonEmptyString "Hello \n World")
trim (NonEmptyString " \n") == Nothing
#toUpper Source
toUpper :: NonEmptyString -> NonEmptyString
Returns the argument converted to uppercase.
toUpper (NonEmptyString "Hello") == NonEmptyString "HELLO"
#toString Source
toString :: NonEmptyString -> String
Converts a NonEmptyString
back into a standard String
.
#toLower Source
toLower :: NonEmptyString -> NonEmptyString
Returns the argument converted to lowercase.
toLower (NonEmptyString "hElLo") == NonEmptyString "hello"
#stripSuffix Source
stripSuffix :: Pattern -> NonEmptyString -> Maybe NonEmptyString
If the string ends with the given suffix, return the portion of the
string left after removing it. If the suffix does not match or there is no
remainder, the result will be Nothing
.
stripSuffix (Pattern ".exe") (NonEmptyString "purs.exe") == Just (NonEmptyString "purs")
stripSuffix (Pattern ".exe") (NonEmptyString "purs") == Nothing
stripSuffix (Pattern "Hello!") (NonEmptyString "Hello!") == Nothing
#stripPrefix Source
stripPrefix :: Pattern -> NonEmptyString -> Maybe NonEmptyString
If the string starts with the given prefix, return the portion of the
string left after removing it. If the prefix does not match or there is no
remainder, the result will be Nothing
.
stripPrefix (Pattern "http:") (NonEmptyString "http://purescript.org") == Just (NonEmptyString "//purescript.org")
stripPrefix (Pattern "http:") (NonEmptyString "https://purescript.org") == Nothing
stripPrefix (Pattern "Hello!") (NonEmptyString "Hello!") == Nothing
#replaceAll Source
replaceAll :: Pattern -> NonEmptyReplacement -> NonEmptyString -> NonEmptyString
Replaces all occurences of the pattern with the replacement string.
replaceAll (Pattern "<=") (NonEmptyReplacement "≤") (NonEmptyString "a <= b <= c") == NonEmptyString "a ≤ b ≤ c"
#replace Source
replace :: Pattern -> NonEmptyReplacement -> NonEmptyString -> NonEmptyString
Replaces the first occurence of the pattern with the replacement string.
replace (Pattern "<=") (NonEmptyReplacement "≤") (NonEmptyString "a <= b <= c") == NonEmptyString "a ≤ b <= c"
#prependString Source
prependString :: String -> NonEmptyString -> NonEmptyString
Prepends a string to this non-empty string. Since one of the strings is non-empty we know the result will be too.
prependString "be" (NonEmptyString "fore") == NonEmptyString "before"
prependString "" (NonEmptyString "fore") == NonEmptyString "fore"
#localeCompare Source
localeCompare :: NonEmptyString -> NonEmptyString -> Ordering
Compare two strings in a locale-aware fashion. This is in contrast to
the Ord
instance on String
which treats strings as arrays of code
units:
NonEmptyString "ä" `localeCompare` NonEmptyString "b" == LT
NonEmptyString "ä" `compare` NonEmptyString "b" == GT
#joinWith1 Source
joinWith1 :: forall f. Foldable1 f => NonEmptyString -> f String -> NonEmptyString
Joins possibly empty strings in a non-empty container together as a new non-empty string, inserting a non-empty string as a separator between them. The result is guaranteed to be non-empty.
-- array syntax is used for demonstration here, it would need to be a real `Foldable1`
joinWith1 (NonEmptyString ", ") ["apple", "banana"] == NonEmptyString "apple, banana"
joinWith1 (NonEmptyString "/") ["a", "b", "", "c", ""] == NonEmptyString "a/b//c/"
#joinWith Source
joinWith :: forall f. Foldable f => String -> f NonEmptyString -> String
Joins the strings in a container together as a new string, inserting the first argument as separator between them. The result is not guaranteed to be non-empty.
joinWith ", " [NonEmptyString "apple", NonEmptyString "banana"] == "apple, banana"
joinWith ", " [] == ""
#join1With Source
join1With :: forall f. Foldable1 f => String -> f NonEmptyString -> NonEmptyString
Joins non-empty strings in a non-empty container together as a new non-empty string, inserting a possibly empty string as separator between them. The result is guaranteed to be non-empty.
-- array syntax is used for demonstration here, it would need to be a real `Foldable1`
join1With ", " [NonEmptyString "apple", NonEmptyString "banana"] == NonEmptyString "apple, banana"
join1With "" [NonEmptyString "apple", NonEmptyString "banana"] == NonEmptyString "applebanana"
#fromString Source
fromString :: String -> Maybe NonEmptyString
Creates a NonEmptyString
from a String
, returning Nothing
if the
input is empty.
fromString "" = Nothing
fromString "hello" = Just (NES.unsafeFromString "hello")
#contains Source
contains :: Pattern -> NonEmptyString -> Boolean
Checks whether the pattern appears in the given string.
contains (Pattern "needle") (NonEmptyString "haystack with needle") == true
contains (Pattern "needle") (NonEmptyString "haystack") == false
#appendString Source
appendString :: NonEmptyString -> String -> NonEmptyString
Appends a string to this non-empty string. Since one of the strings is non-empty we know the result will be too.
appendString (NonEmptyString "Hello") " world" == NonEmptyString "Hello world"
appendString (NonEmptyString "Hello") "" == NonEmptyString "Hello"
Re-exports from Data.String.Pattern
- Modules
- Data.
Char - Data.
Char. Gen - Data.
String - Data.
String. CaseInsensitive - Data.
String. CodePoints - Data.
String. CodeUnits - Data.
String. Common - Data.
String. Gen - Data.
String. NonEmpty - Data.
String. NonEmpty. CaseInsensitive - Data.
String. NonEmpty. CodePoints - Data.
String. NonEmpty. CodeUnits - Data.
String. NonEmpty. Internal - Data.
String. Pattern - Data.
String. Regex - Data.
String. Regex. Flags - Data.
String. Regex. Unsafe - Data.
String. Unsafe