SBS :: ByteArray# -> ShortByteString
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.
ShortByteStrings encoded as UTF16-LE, suitable for windows FFI calls.
Word16s are *always* in BE encoding (both input and output), so e.g. pack
takes a list of BE encoded [Word16] and produces a UTF16-LE encoded ShortByteString.
Likewise, unpack takes a UTF16-LE encoded ShortByteString and produces a list of BE encoded [Word16].
Indices and lengths are always in respect to Word16, not Word8.
All functions will error out if the input string is not a valid UTF16 stream (uneven number of bytes). So use this module with caution.
ShortByteString type and representationSBS :: ByteArray# -> ShortByteStringPrior to bytestring-0.12 SBS was a genuine constructor of ShortByteString,
but now it is a bundled pattern synonym, provided as a compatibility shim.
newtype ShortByteStringA 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.
ShortByteString :: ByteArray -> ShortByteStringunShortByteString :: ShortByteString -> ByteArrayShortByteStringsempty :: ShortByteStringO(1). The empty ShortByteString.
singleton :: Word16 -> ShortByteStringO(1) Convert a Word16 into a ShortByteString
pack :: [Word16] -> ShortByteStringO(n). Convert a list into a ShortByteString
unpack :: ShortByteString -> [Word16]O(n). Convert a ShortByteString into a list.
fromShort :: ShortByteString -> ByteStringO(n). Convert a ShortByteString into a ByteString.
toShort :: ByteString -> ShortByteStringO(n). Convert a ByteString into a ShortByteString.
This makes a copy, so does not retain the input string.
snoc :: ShortByteString -> Word16 -> ShortByteStringO(n) Append a Word16 to the end of a ShortByteString
Note: copies the entire byte array
cons :: Word16 -> ShortByteString -> ShortByteStringO(n) cons is analogous to (:) for lists.
Note: copies the entire byte array
append :: ShortByteString -> ShortByteString -> ShortByteStringlast :: HasCallStack => ShortByteString -> Word16O(1) Extract the last element of a ShortByteString, which must be finite and at least one Word16. An exception will be thrown in the case of an empty ShortByteString.
tail :: HasCallStack => ShortByteString -> ShortByteStringO(n) Extract the elements after the head of a ShortByteString, which must at least one Word16. An exception will be thrown in the case of an empty ShortByteString.
Note: copies the entire byte array
uncons :: ShortByteString -> Maybe (Word16, ShortByteString)O(n) Extract the head and tail of a ByteString, returning Nothing if it is empty.
uncons2 :: ShortByteString -> Maybe (Word16, Word16, ShortByteString)O(n) Extract first two elements and the rest of a ByteString, returning Nothing if it is shorter than two elements.
head :: HasCallStack => ShortByteString -> Word16O(1) Extract the first element of a ShortByteString, which must be at least one Word16. An exception will be thrown in the case of an empty ShortByteString.
init :: HasCallStack => ShortByteString -> ShortByteStringO(n) Return all the elements of a ShortByteString except the last one.
An exception will be thrown in the case of an empty ShortByteString.
Note: copies the entire byte array
unsnoc :: ShortByteString -> Maybe (ShortByteString, Word16)O(n) Extract the init and last of a ByteString, returning Nothing
if it is empty.
null :: ShortByteString -> BoolO(1) Test whether a ShortByteString is empty.
length :: ShortByteString -> IntO(1) The length of a ShortByteString.
numWord16 :: ShortByteString -> IntThis is like length, but the number of Word16, not Word8.
map :: (Word16 -> Word16) -> ShortByteString -> ShortByteStringO(n) map f xs is the ShortByteString obtained by applying f to each
element of xs.
reverse :: ShortByteString -> ShortByteStringO(n) reverse xs efficiently returns the elements of xs in reverse order.
intercalate :: ShortByteString -> [ShortByteString] -> ShortByteStringO(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.
ShortByteStrings (folds)foldl :: (a -> Word16 -> a) -> a -> ShortByteString -> afoldl, 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.
foldl' :: (a -> Word16 -> a) -> a -> ShortByteString -> afoldl' is like foldl, but strict in the accumulator.
foldl1 :: HasCallStack => (Word16 -> Word16 -> Word16) -> ShortByteString -> Word16foldl1 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.
foldl1' :: HasCallStack => (Word16 -> Word16 -> Word16) -> ShortByteString -> Word16foldl1' is like foldl1, but strict in the accumulator.
An exception will be thrown in the case of an empty ShortByteString.
foldr :: (Word16 -> a -> a) -> a -> ShortByteString -> afoldr, 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.
foldr' :: (Word16 -> a -> a) -> a -> ShortByteString -> afoldr' is like foldr, but strict in the accumulator.
foldr1 :: HasCallStack => (Word16 -> Word16 -> Word16) -> ShortByteString -> Word16foldr1 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.
foldr1' :: HasCallStack => (Word16 -> Word16 -> Word16) -> ShortByteString -> Word16foldr1' is a variant of foldr1, but is strict in the
accumulator.
all :: (Word16 -> Bool) -> ShortByteString -> BoolO(n) Applied to a predicate and a ShortByteString, all determines
if all elements of the ShortByteString satisfy the predicate.
any :: (Word16 -> Bool) -> ShortByteString -> BoolO(n) Applied to a predicate and a ByteString, any determines if
any element of the ByteString satisfies the predicate.
concat :: [ShortByteString] -> ShortByteStringreplicate :: Int -> Word16 -> ShortByteStringO(n) replicate n x is a ByteString of length n with x
the value of every element. The following holds:
replicate w c = unfoldr w (\u -> Just (u,u)) cunfoldr :: (a -> Maybe (Word16, a)) -> a -> ShortByteStringO(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 [Word16]
and run the generator until it returns `Nothing`, otherwise recurse infinitely,
then finally create a ShortByteString.
Examples:
unfoldr (\x -> if x <= 5 then Just (x, x + 1) else Nothing) 0
== pack [0, 1, 2, 3, 4, 5]unfoldrN :: forall a. Int -> (a -> Maybe (Word16, a)) -> a -> (ShortByteString, Maybe a)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)Intnumber of Word16
take :: Int -> ShortByteString -> ShortByteStringO(n) take n, applied to a ShortByteString xs, returns the prefix
of xs of length n, or xs itself if n > .length xs
Note: copies the entire byte array
Intnumber of Word16
takeEnd :: Int -> ShortByteString -> ShortByteStringO(1) is equivalent to takeEnd n xs.
Takes drop (length xs - n) xsn elements from end of bytestring.
>>> takeEnd 3 "a\NULb\NULc\NULd\NULe\NULf\NULg\NUL"
"e\NULf\NULg\NUL"
>>> takeEnd 0 "a\NULb\NULc\NULd\NULe\NULf\NULg\NUL"
""
>>> takeEnd 4 "a\NULb\NULc\NUL"
"a\NULb\NULc\NUL"Intnumber of Word16
takeWhileEnd :: (Word16 -> Bool) -> ShortByteString -> ShortByteStringReturns the longest (possibly empty) suffix of elements satisfying the predicate.
is equivalent to takeWhileEnd p.reverse . takeWhile p . reverse
takeWhile :: (Word16 -> Bool) -> ShortByteString -> ShortByteStringSimilar to takeWhile,
returns the longest (possibly empty) prefix of elements
satisfying the predicate.
drop :: Int -> ShortByteString -> ShortByteStringO(n) drop n xs returns the suffix of xs after the first n elements, or [] if n > .length xs
Note: copies the entire byte array
Intnumber of Word16
dropEnd :: Int -> ShortByteString -> ShortByteStringO(1) is equivalent to dropEnd n xs.
Drops take (length xs - n) xsn elements from end of bytestring.
>>> dropEnd 3 "a\NULb\NULc\NULd\NULe\NULf\NULg\NUL"
"a\NULb\NULc\NULd\NUL"
>>> dropEnd 0 "a\NULb\NULc\NULd\NULe\NULf\NULg\NUL"
"a\NULb\NULc\NULd\NULe\NULf\NULg\NUL"
>>> dropEnd 4 "a\NULb\NULc\NUL"
""Intnumber of Word16
dropWhile :: (Word16 -> Bool) -> ShortByteString -> ShortByteStringSimilar to dropWhile,
drops the longest (possibly empty) prefix of elements
satisfying the predicate and returns the remainder.
Note: copies the entire byte array
dropWhileEnd :: (Word16 -> Bool) -> ShortByteString -> ShortByteStringSimilar to dropWhileEnd,
drops the longest (possibly empty) suffix of elements
satisfying the predicate and returns the remainder.
is equivalent to dropWhileEnd p.reverse . dropWhile p . reverse
breakEnd :: (Word16 -> Bool) -> ShortByteString -> (ShortByteString, ShortByteString)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 and to spanEnd (not . p)(.takeWhileEnd (not . p) &&& dropWhileEnd (not . p))
break :: (Word16 -> Bool) -> ShortByteString -> (ShortByteString, ShortByteString)Similar to break,
returns the longest (possibly empty) prefix of elements which do not
satisfy the predicate and the remainder of the string.
break p is equivalent to and to span (not . p)(.takeWhile (not . p) &&& dropWhile (not . p))
span :: (Word16 -> Bool) -> ShortByteString -> (ShortByteString, ShortByteString)Similar to span,
returns the longest (possibly empty) prefix of elements
satisfying the predicate and the remainder of the string.
span p is equivalent to and to break (not . p)(.takeWhile p &&& dropWhile p)
spanEnd :: (Word16 -> Bool) -> ShortByteString -> (ShortByteString, ShortByteString)Returns the longest (possibly empty) suffix of elements satisfying the predicate and the remainder of the string.
spanEnd p is equivalent to and to breakEnd (not . p)(.takeWhileEnd p &&& dropWhileEnd p)
We have
spanEnd (not . isSpace) "x y z" == ("x y ", "z")and
spanEnd (not . isSpace) ps
==
let (x, y) = span (not . isSpace) (reverse ps) in (reverse y, reverse x)splitAt :: Int -> ShortByteString -> (ShortByteString, ShortByteString)O(n) splitAt n xs is equivalent to (.take n xs, drop n xs)
Note: copies the substrings
Intnumber of Word16
split :: Word16 -> ShortByteString -> [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
splitWith :: (Word16 -> Bool) -> ShortByteString -> [ShortByteString]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 [""]stripSuffix :: ShortByteString -> ShortByteString -> Maybe ShortByteStringO(n) The stripSuffix function takes two ShortByteStrings and returns Just
the remainder of the second iff the first is its suffix, and otherwise
Nothing.
stripPrefix :: ShortByteString -> ShortByteString -> Maybe ShortByteStringO(n) The stripPrefix function takes two ShortByteStrings and returns Just
the remainder of the second iff the first is its prefix, and otherwise
Nothing.
isInfixOf :: ShortByteString -> ShortByteString -> BoolCheck whether one string is a substring of another.
isPrefixOf :: ShortByteString -> ShortByteString -> BoolO(n) The isPrefixOf function takes two ShortByteStrings and returns True
iff the first is a prefix of the second.
isSuffixOf :: ShortByteString -> ShortByteString -> BoolO(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 ybreakSubstring :: ShortByteString -> ShortByteString -> (ShortByteString, ShortByteString)ShortByteStringString to search for
ShortByteStringString to search in
(ShortByteString, ShortByteString)Head and tail of string broken at substring
elem :: Word16 -> ShortByteString -> BoolO(n) elem is the ShortByteString membership predicate.
find :: (Word16 -> Bool) -> ShortByteString -> Maybe Word16O(n) The find function takes a predicate and a ByteString,
and returns the first element in matching the predicate, or Nothing
if there is no such element.
find f p = case findIndex f p of Just n -> Just (p ! n) ; _ -> Nothingfilter :: (Word16 -> Bool) -> ShortByteString -> ShortByteStringO(n) filter, applied to a predicate and a ByteString,
returns a ByteString containing those characters that satisfy the
predicate.
partition :: (Word16 -> Bool) -> ShortByteString -> (ShortByteString, ShortByteString)O(n) The partition function takes a predicate a ByteString and returns
the pair of ByteStrings with elements which do and do not satisfy the
predicate, respectively; i.e.,
partition p bs == (filter p xs, filter (not . p) xs)index :: HasCallStack => ShortByteString -> Int -> Word16O(1) ShortByteString index (subscript) operator, starting from 0.
Intnumber of Word16
indexMaybe :: ShortByteString -> Int -> Maybe Word16O(1) ShortByteString index, starting from 0, that returns Just if:
0 <= n < length bsIntnumber of Word16
(!?) :: ShortByteString -> Int -> Maybe Word16O(1) ShortByteString index, starting from 0, that returns Just if:
0 <= n < length bsIntnumber of Word16
elemIndex :: Word16 -> ShortByteString -> Maybe IntO(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.
number of Word16
elemIndices :: Word16 -> ShortByteString -> [Int]O(n) The elemIndices function extends elemIndex, by returning
the indices of all elements equal to the query element, in ascending order.
count :: Word16 -> ShortByteString -> Intcount returns the number of times its argument appears in the ShortByteString
findIndex :: (Word16 -> Bool) -> ShortByteString -> Maybe IntO(n) The findIndex function takes a predicate and a ShortByteString and
returns the index of the first element in the ByteString
satisfying the predicate.
findIndices :: (Word16 -> Bool) -> ShortByteString -> [Int]O(n) The findIndices function extends findIndex, by returning the
indices of all elements satisfying the predicate, in ascending order.
CStrings and pointerspackCWString :: Ptr Word16 -> IO ShortByteStringO(n). Construct a new ShortByteString from a CWString. The
resulting ShortByteString is an immutable copy of the original
CWString, and is managed on the Haskell heap. The original
CWString must be null terminated.
packCWStringLen :: (Ptr Word16, Int) -> IO ShortByteStringO(n). Construct a new ShortByteString from a CWStringLen. The
resulting ShortByteString is an immutable copy of the original CWStringLen.
The ShortByteString is a normal Haskell value and will be managed on the
Haskell heap.
newCWString :: ShortByteString -> IO (Ptr Word16)O(n) construction. Use a ShortByteString with a function requiring a CWStringLen.
As for useAsCWString this function makes a copy of the original ShortByteString.
It must not be stored or used after the subcomputation finishes.
CStringsuseAsCWString :: ShortByteString -> (Ptr Word16 -> IO a) -> IO aO(n) construction. Use a ShortByteString with a function requiring a
null-terminated CWString. The CWString is a copy and will be freed
automatically; it must not be stored or used after the
subcomputation finishes.
useAsCWStringLen :: ShortByteString -> ((Ptr Word16, Int) -> IO a) -> IO aO(n) construction. Use a ShortByteString with a function requiring a CWStringLen.
As for useAsCWString this function makes a copy of the original ShortByteString.
It must not be stored or used after the subcomputation finishes.
Community contribution. The service has not verified this documentation. The generator reported 4 diagnostics.
Target: Linux on x86-64. Some inferred types and resolved links are not available.
Generator: aihc-haddock-858b1951-web-1
Metadata snapshot: 467adfa4e90b59b0072712e32d97437632176e89f16e62151dd53a2e41646abb
Open the dependency plan · Download the documentation model