O(n) Applied to a predicate and a ShortByteString, all determines if all elements of the ShortByteString satisfy the predicate.
Modulererebase-1.21.2Haskell2010
Data.ByteString.Short
- 1 type
- 72 values
- Packagererebase-1.21.2
- Exports74
- LanguageHaskell2010
- LicenceMIT
- SourceInternal.hs
O(n) Applied to a predicate and a ShortByteString, any determines if any element of the ShortByteString satisfies the predicate.
Similar to dropWhileEnd, drops the longest (possibly empty) suffix of elements satisfying the predicate and returns the remainder.
dropWhileEnd p is equivalent to reverse . dropWhile p . reverse.
O(n) The elemIndex function returns the index of the first element in the given ShortByteString which is equal to the query element, or Nothing if there is no such element.
O(n) The elemIndices function extends elemIndex, by returning the indices of all elements equal to the query element, in ascending order.
O(n) The findIndex function takes a predicate and a ShortByteString and returns the index of the first element in the ShortByteString satisfying the predicate.
O(n) The findIndices function extends findIndex, by returning the indices of all elements satisfying the predicate, in ascending order.
O(n) The intercalate function takes a ShortByteString and a list of ShortByteStrings and concatenates the list after interspersing the first argument between each element of the list.
Check whether one string is a substring of another.
O(n) The isPrefixOf function takes two ShortByteStrings and returns True iff the first is a prefix of the second.
O(n) The isSuffixOf function takes two ShortByteStrings and returns True iff the first is a suffix of the second.
The following holds:
isSuffixOf x y == reverse x `isPrefixOf` reverse yO(n) The partition function takes a predicate a ShortByteString and returns the pair of ShortByteStrings with elements which do and do not satisfy the predicate, respectively; i.e.,
partition p bs == (filter p sbs, filter (not . p) sbs)O(1) Convert a Word8 into a ShortByteString
O(n) The stripPrefix function takes two ShortByteStrings and returns Just the remainder of the second iff the first is its prefix, and otherwise Nothing.
O(n), where n is the length of the result. The unfoldr
function is analogous to the List 'unfoldr'. unfoldr builds a
ShortByteString from a seed value. The function takes the element and
returns Nothing if it is done producing the ShortByteString or returns
Just (a,b), in which case, a is the next byte in the string,
and b is the seed value for further production.
This function is not efficient/safe. It will build a list of [Word8]
and run the generator until it returns Nothing, otherwise recurse infinitely,
then finally create a ShortByteString.
If you know the maximum length, consider using unfoldrN.
Examples:
unfoldr (\x -> if x <= 5 then Just (x, x + 1) else Nothing) 0
== pack [0, 1, 2, 3, 4, 5]O(1) ShortByteString index, starting from 0, that returns Just if:
0 <= n < length bsSimilar to dropWhile, drops the longest (possibly empty) prefix of elements satisfying the predicate and returns the remainder.
Note: copies the entire byte array
O(1) Extract the first element of a ShortByteString, which must be non-empty. An exception will be thrown in the case of an empty ShortByteString.
This is a partial function, consider using uncons instead.
O(n) Return all the elements of a ShortByteString except the last one. An exception will be thrown in the case of an empty ShortByteString.
This is a partial function, consider using unsnoc instead.
Note: copies the entire byte array
O(1) Extract the last element of a ShortByteString, which must be finite and non-empty. An exception will be thrown in the case of an empty ShortByteString.
This is a partial function, consider using unsnoc instead.
O(n) replicate n x is a ShortByteString of length n with x
the value of every element. The following holds:
replicate w c = unfoldr w (\u -> Just (u,u)) cO(n) reverse xs efficiently returns the elements of xs in reverse order.
O(n) Extract the elements after the head of a ShortByteString, which must be non-empty. An exception will be thrown in the case of an empty ShortByteString.
This is a partial function, consider using uncons instead.
Note: copies the entire byte array
Similar to takeWhile, returns the longest (possibly empty) prefix of elements satisfying the predicate.
A compact representation of a Word8 vector.
It has a lower memory overhead than a ByteString and does not contribute to heap fragmentation. It can be converted to or from a ByteString (at the cost of copying the string data). It supports very few other operations.
Constructors
Instances16IsList, Eq, Data, Ord, Read, Show, …
IsList ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalEq ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalData ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalOrd ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalLexicographic order.
Read ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalShow ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalIsString ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalBeware: fromString truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�
Generic ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalSemigroup ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalMonoid ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalNFData ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalBinary ShortByteStringDefined in binary-0.8.9.3 · Data.Binary.ClassHashable ShortByteStringDefined in hashable-1.4.7.0 · Data.Hashable.ClassLift ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internaltype Rep ShortByteString = D1 ('MetaDataDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal"ShortByteString"
"Data.ByteString.Short.Internal"
"bytestring-0.12.2.0-e345"
'True) (C1 ('MetaCons"ShortByteString"
'PrefixI 'True) (S1 ('MetaSel ('Just"unShortByteString"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteArray)))type Item ShortByteString = Word8Defined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
Prior to bytestring-0.12 SBS was a genuine constructor of ShortByteString,
but now it is a bundled pattern synonym, provided as a compatibility shim.
O(1). The empty ShortByteString.
O(n) elem is the ShortByteString membership predicate.
foldl, applied to a binary operator, a starting value (typically the left-identity of the operator), and a ShortByteString, reduces the ShortByteString using the binary operator, from left to right.
foldl1 is a variant of foldl that has no starting value argument, and thus must be applied to non-empty ShortByteStrings. An exception will be thrown in the case of an empty ShortByteString.
foldr, applied to a binary operator, a starting value (typically the right-identity of the operator), and a ShortByteString, reduces the ShortByteString using the binary operator, from right to left.
foldr1 is a variant of foldr that has no starting value argument, and thus must be applied to non-empty ShortByteStrings An exception will be thrown in the case of an empty ShortByteString.
O(1) The length of a ShortByteString.
O(1) Test whether a ShortByteString is empty.
O(1) ShortByteString index (subscript) operator, starting from 0.
This is a partial function, consider using indexMaybe instead.
O(n) map f xs is the ShortByteString obtained by applying f to each
element of xs.
O(n) filter, applied to a predicate and a ShortByteString, returns a ShortByteString containing those characters that satisfy the predicate.
O(n). Convert a ShortByteString into a list.
O(n). Convert a list into a ShortByteString
O(n) Like unfoldr, unfoldrN builds a ShortByteString from a seed value. However, the length of the result is limited by the first argument to unfoldrN. This function is more efficient than unfoldr when the maximum length of the result is known.
The following equation relates unfoldrN and unfoldr:
fst (unfoldrN n f s) == take n (unfoldr f s)O(n) cons is analogous to (:) for lists.
Note: copies the entire byte array
O(n) Append a byte to the end of a ShortByteString
Note: copies the entire byte array
count returns the number of times its argument appears in the ShortByteString
O(n) Break a ShortByteString into pieces separated by the byte argument, consuming the delimiter. I.e.
split 10 "a\nb\nd\ne" == ["a","b","d","e"] -- fromEnum '\n' == 10
split 97 "aXaXaXa" == ["","X","X","X",""] -- fromEnum 'a' == 97
split 120 "x" == ["",""] -- fromEnum 'x' == 120
split undefined "" == [] -- and not [""]and
intercalate [c] . split c == id
split == splitWith . (==)Note: copies the substrings
O(n) The stripSuffix function takes two ShortByteStrings and returns Just the remainder of the second iff the first is its suffix, and otherwise Nothing.
Returns the longest (possibly empty) suffix of elements satisfying the predicate.
takeWhileEnd p is equivalent to reverse . takeWhile p . reverse.
Returns the longest (possibly empty) suffix of elements which do not satisfy the predicate and the remainder of the string.
breakEnd p is equivalent to spanEnd (not . p) and to (takeWhileEnd (not . p) &&& dropWhileEnd (not . p)).
breakSubstring :: ShortByteStringString to search for
-> ShortByteStringString to search in
-> (ShortByteString, ShortByteString)Head and tail of string broken at substring
Break a string on a substring, returning a pair of the part of the string prior to the match, and the rest of the string.
The following relationships hold:
break (== c) l == breakSubstring (singleton c) lFor example, to tokenise a string, dropping delimiters:
tokenise x y = h : if null t then [] else tokenise x (drop (length x) t)
where (h,t) = breakSubstring x yTo skip to the first occurrence of a string:
snd (breakSubstring x y)To take the parts of a string before a delimiter:
fst (breakSubstring x y)Note that calling `breakSubstring x` does some preprocessing work, so you should avoid unnecessarily duplicating breakSubstring calls with the same pattern.
O(n). Convert a ShortByteString into a ByteString.
O(1) ShortByteString index, starting from 0, that returns Just if:
0 <= n < length bsO(n) Check whether a ShortByteString represents valid UTF-8.
O(n). Construct a new ShortByteString from a CString. The
resulting ShortByteString is an immutable copy of the original
CString, and is managed on the Haskell heap. The original
CString must be null terminated.
O(n). Construct a new ShortByteString from a CStringLen. The
resulting ShortByteString is an immutable copy of the original CStringLen.
The ShortByteString is a normal Haskell value and will be managed on the
Haskell heap.
Returns the longest (possibly empty) suffix of elements satisfying the predicate and the remainder of the string.
spanEnd p is equivalent to breakEnd (not . p) and to (takeWhileEnd p &&& dropWhileEnd p).
We have
spanEnd (not . isSpace) "x y z" == ("x y ", "z")and
spanEnd (not . isSpace) sbs
==
let (x, y) = span (not . isSpace) (reverse sbs) in (reverse y, reverse x)O(n) Splits a ShortByteString into components delimited by separators, where the predicate returns True for a separator element. The resulting components do not contain the separators. Two adjacent separators result in an empty component in the output. eg.
splitWith (==97) "aabbaca" == ["","","bb","c",""] -- fromEnum 'a' == 97
splitWith undefined "" == [] -- and not [""]O(n). Convert a ByteString into a ShortByteString.
This makes a copy, so does not retain the input string.
O(n) construction. Use a ShortByteString with a function requiring a
null-terminated CString. The CString is a copy and will be freed
automatically; it must not be stored or used after the
subcomputation finishes.
O(n) construction. Use a ShortByteString with a function requiring a CStringLen.
As for useAsCString this function makes a copy of the original ShortByteString.
It must not be stored or used after the subcomputation finishes.
Beware that this function does not add a terminating NUL byte at the end of CStringLen.
If you need to construct a pointer to a null-terminated sequence, use useAsCString
(and measure length independently if desired).