newtype WindowsString
Commonly used windows string as wide character bytes.
newtype WindowsStringCommonly used windows string as wide character bytes.
newtype WindowsCharThis represents a "wide char" on windows.
A better name would maybe have been WindowsWord, since
this is just Word16 in a UCS-2 sequence.
encodeUtf :: MonadThrow m => String -> m WindowsStringPartial unicode friendly encoding.
This encodes as UTF16-LE (strictly), which is a pretty good guess.
Throws an EncodingException if encoding fails. If the input does not
contain surrogate chars, you can use unsafeEncodeUtf.
unsafeEncodeUtf :: HasCallStack => String -> WindowsStringUnsafe unicode friendly encoding.
Like encodeUtf, except it crashes when the input contains
surrogate chars. For sanitized input, this can be useful.
encodeWith :: TextEncoding -> String -> Either EncodingException WindowsStringEncode a String with the specified encoding.
Note: We expect a "wide char" encoding (e.g. UCS-2 or UTF-16). Anything
that works with Word16 boundaries. Picking an incompatible encoding may crash
filepath operations.
TextEncodingtext encoding (wide char)
encodeFS :: String -> IO WindowsStringUse System.OsPath.Windows.encodeFS from filepath
This mimics the behavior of the base library when doing filesystem operations (usually filepaths), which does permissive UTF-16 encoding, where coding errors generate Chars in the surrogate range.
The reason this is in IO is because it unifies with the Posix counterpart,
which does require IO. This is safe to unsafePerformIO/unsafeDupablePerformIO.
encodeLE :: String -> IO WindowsStringThis mimics the behavior of the base library when doing string operations, which does permissive UTF-16 encoding, where coding errors generate Chars in the surrogate range.
The reason this is in IO is because it unifies with the Posix counterpart,
which does require IO. This is safe to unsafePerformIO/unsafeDupablePerformIO.
fromString :: String -> WindowsStringLike 'encodeLE but not in IO.
encodeLE was designed to have a symmetric type signature
on unix and windows, but morally the function has no IO effects on windows,
so we provide this variant without breaking existing API.
On windows, encodeLE is equivalent to encodeFS.
This function does not exist on unix.
fromBytes :: MonadThrow m => ByteString -> m WindowsStringConstructs a platform string from a ByteString.
This ensures valid UCS-2LE. Note that this doesn't expand Word8 to Word16 on windows, so you may get invalid UTF-16.
Throws EncodingException on invalid UCS-2LE (although unlikely).
fromShortBytes :: MonadThrow m => ShortByteString -> m WindowsStringConstructs a platform string from a ShortByteString.
This ensures valid UCS-2LE. Note that this doesn't expand Word8 to Word16 on windows, so you may get invalid UTF-16.
Throws EncodingException on invalid UCS-2LE (although unlikely).
pstr :: QuasiQuoterQuasiQuote a WindowsString. This accepts Unicode characters
and encodes as UTF-16LE on windows.
singleton :: WindowsChar -> WindowsStringempty :: WindowsStringpack :: [WindowsChar] -> WindowsStringPack a list of platform words to a platform string.
Note that using this in conjunction with unsafeFromChar to
convert from [Char] to platform string is probably not what
you want, because it will truncate unicode code points.
Additionally, a platform word is a byte (or wide char on windows) in an encoded byte sequence, so we're not operating on unicode code points or graphemes here.
decodeUtf :: MonadThrow m => WindowsString -> m StringPartial unicode friendly decoding.
This decodes as UTF16-LE (strictly), which is a pretty good.
Throws a EncodingException if decoding fails.
decodeWith :: TextEncoding -> WindowsString -> Either EncodingException StringDecode a WindowsString with the specified encoding.
The String is forced into memory to catch all exceptions.
decodeFS :: WindowsString -> IO StringUse System.OsPath.Windows.decodeFS from filepath
Like decodeUtf, except this mimics the behavior of the base library when doing filesystem
operations (usually filepaths), which does permissive UTF-16 encoding, where coding errors generate
Chars in the surrogate range.
The reason this is in IO is because it unifies with the Posix counterpart,
which does require IO. unsafePerformIO/unsafeDupablePerformIO are safe, however.
decodeLE :: WindowsString -> IO StringLike decodeUtf, except this mimics the behavior of the base library when doing filesystem
operations, which does permissive UTF-16 encoding, where coding errors generate
Chars in the surrogate range.
The reason this is in IO is because it unifies with the Posix counterpart,
which does require IO. unsafePerformIO/unsafeDupablePerformIO are safe, however.
unpack :: WindowsString -> [WindowsChar]Unpack a platform string to a list of platform words.
unsafeFromChar :: Char -> WindowsCharTruncates to 2 octets.
Note that WindowsChar is a "wide char" in a UCS-2 encoded byte sequence
and is not morally a unicode code point by any means, so
this conversion is rarely what you want.
Consider using fromWord instead.
fromWord :: Word16 -> WindowsCharConvert from Word16.
toChar :: WindowsChar -> CharConverts back to a unicode codepoint (total).
snoc :: WindowsString -> WindowsChar -> WindowsStringO(n) Append a byte to the end of a OsString
cons :: WindowsChar -> WindowsString -> WindowsStringO(n) cons is analogous to (:) for lists.
last :: HasCallStack => WindowsString -> WindowsCharO(1) Extract the last element of a OsString, which must be finite and non-empty. An exception will be thrown in the case of an empty OsString.
This is a partial function, consider using unsnoc instead.
tail :: HasCallStack => WindowsString -> WindowsStringO(n) Extract the elements after the head of a OsString, which must be non-empty. An exception will be thrown in the case of an empty OsString.
This is a partial function, consider using uncons instead.
uncons :: WindowsString -> Maybe (WindowsChar, WindowsString)O(n) Extract the head and tail of a OsString, returning Nothing
if it is empty.
head :: HasCallStack => WindowsString -> WindowsCharO(1) Extract the first element of a OsString, which must be non-empty. An exception will be thrown in the case of an empty OsString.
This is a partial function, consider using uncons instead.
init :: HasCallStack => WindowsString -> WindowsStringO(n) Return all the elements of a OsString except the last one.
An exception will be thrown in the case of an empty OsString.
This is a partial function, consider using unsnoc instead.
unsnoc :: WindowsString -> Maybe (WindowsString, WindowsChar)O(n) Extract the init and last of a OsString, returning Nothing
if it is empty.
null :: WindowsString -> BoolO(1). The empty OsString.
length :: WindowsString -> IntO(1) The length of a OsString.
This returns the number of code units
(Word8 on unix and Word16 on windows), not
bytes.
>>> length "abc"
3map :: (WindowsChar -> WindowsChar) -> WindowsString -> WindowsStringO(n) map f xs is the OsString obtained by applying f to each
element of xs.
reverse :: WindowsString -> WindowsStringO(n) reverse xs efficiently returns the elements of xs in reverse order.
intercalate :: WindowsString -> [WindowsString] -> WindowsStringO(n) The intercalate function takes a OsString and a list of
OsStrings and concatenates the list after interspersing the first
argument between each element of the list.
foldl :: forall a. (a -> WindowsChar -> a) -> a -> WindowsString -> afoldl, applied to a binary operator, a starting value (typically
the left-identity of the operator), and a OsString, reduces the
OsString using the binary operator, from left to right.
foldl' :: forall a. (a -> WindowsChar -> a) -> a -> WindowsString -> afoldl' is like foldl, but strict in the accumulator.
foldl1 :: (WindowsChar -> WindowsChar -> WindowsChar) -> WindowsString -> WindowsCharfoldl1 is a variant of foldl that has no starting value
argument, and thus must be applied to non-empty OsStrings.
An exception will be thrown in the case of an empty OsString.
foldl1' :: (WindowsChar -> WindowsChar -> WindowsChar) -> WindowsString -> WindowsCharfoldl1' is like foldl1, but strict in the accumulator.
An exception will be thrown in the case of an empty OsString.
foldr :: forall a. (WindowsChar -> a -> a) -> a -> WindowsString -> afoldr, applied to a binary operator, a starting value
(typically the right-identity of the operator), and a OsString,
reduces the OsString using the binary operator, from right to left.
foldr' :: forall a. (WindowsChar -> a -> a) -> a -> WindowsString -> afoldr' is like foldr, but strict in the accumulator.
foldr1 :: (WindowsChar -> WindowsChar -> WindowsChar) -> WindowsString -> WindowsCharfoldr1 is a variant of foldr that has no starting value argument,
and thus must be applied to non-empty OsStrings
An exception will be thrown in the case of an empty OsString.
foldr1' :: (WindowsChar -> WindowsChar -> WindowsChar) -> WindowsString -> WindowsCharfoldr1' is a variant of foldr1, but is strict in the
accumulator.
all :: (WindowsChar -> Bool) -> WindowsString -> BoolO(n) Applied to a predicate and a OsString, all determines
if all elements of the OsString satisfy the predicate.
any :: (WindowsChar -> Bool) -> WindowsString -> BoolO(n) Applied to a predicate and a OsString, any determines if
any element of the OsString satisfies the predicate.
concat :: [WindowsString] -> WindowsStringreplicate :: Int -> WindowsChar -> WindowsStringO(n) replicate n x is a OsString of length n with x
the value of every element. The following holds:
replicate w c = unfoldr w (\u -> Just (u,u)) cunfoldr :: forall a. (a -> Maybe (WindowsChar, a)) -> a -> WindowsStringO(n), where n is the length of the result. The unfoldr
function is analogous to the List 'unfoldr'. unfoldr builds a
OsString from a seed value. The function takes the element and
returns Nothing if it is done producing the OsString 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 OsString.
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]unfoldrN :: forall a. Int -> (a -> Maybe (WindowsChar, a)) -> a -> (WindowsString, Maybe a)O(n) Like unfoldr, unfoldrN builds a OsString 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)take :: Int -> WindowsString -> WindowsStringO(n) take n, applied to a OsString xs, returns the prefix
of xs of length n, or xs itself if n > .length xs
takeEnd :: Int -> WindowsString -> WindowsStringO(n) is equivalent to takeEnd n xs.
Takes drop (length xs - n) xsn elements from end of bytestring.
>>> takeEnd 3 "abcdefg"
"efg"
>>> takeEnd 0 "abcdefg"
""
>>> takeEnd 4 "abc"
"abc"takeWhileEnd :: (WindowsChar -> Bool) -> WindowsString -> WindowsStringReturns the longest (possibly empty) suffix of elements satisfying the predicate.
is equivalent to takeWhileEnd p.reverse . takeWhile p . reverse
takeWhile :: (WindowsChar -> Bool) -> WindowsString -> WindowsStringSimilar to takeWhile,
returns the longest (possibly empty) prefix of elements
satisfying the predicate.
drop :: Int -> WindowsString -> WindowsStringO(n) drop n xs returns the suffix of xs after the first n elements, or empty if n > .length xs
dropEnd :: Int -> WindowsString -> WindowsStringO(n) is equivalent to dropEnd n xs.
Drops take (length xs - n) xsn elements from end of bytestring.
>>> dropEnd 3 "abcdefg"
"abcd"
>>> dropEnd 0 "abcdefg"
"abcdefg"
>>> dropEnd 4 "abc"
""dropWhileEnd :: (WindowsChar -> Bool) -> WindowsString -> WindowsStringSimilar 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
dropWhile :: (WindowsChar -> Bool) -> WindowsString -> WindowsStringSimilar to dropWhile,
drops the longest (possibly empty) prefix of elements
satisfying the predicate and returns the remainder.
break :: (WindowsChar -> Bool) -> WindowsString -> (WindowsString, WindowsString)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))
breakEnd :: (WindowsChar -> Bool) -> WindowsString -> (WindowsString, WindowsString)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))
span :: (WindowsChar -> Bool) -> WindowsString -> (WindowsString, WindowsString)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 :: (WindowsChar -> Bool) -> WindowsString -> (WindowsString, WindowsString)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) sbs
==
let (x, y) = span (not . isSpace) (reverse sbs) in (reverse y, reverse x)splitAt :: Int -> WindowsString -> (WindowsString, WindowsString)O(n) splitAt n sbs is equivalent to (.take n sbs, drop n sbs)
split :: WindowsChar -> WindowsString -> [WindowsString]O(n) Break a OsString 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 . (==)splitWith :: (WindowsChar -> Bool) -> WindowsString -> [WindowsString]O(n) Splits a OsString 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 :: WindowsString -> WindowsString -> Maybe WindowsStringO(n) The stripSuffix function takes two OsStrings and returns Just
the remainder of the second iff the first is its suffix, and otherwise
Nothing.
stripPrefix :: WindowsString -> WindowsString -> Maybe WindowsStringO(n) The stripPrefix function takes two OsStrings and returns Just
the remainder of the second iff the first is its prefix, and otherwise
Nothing.
isInfixOf :: WindowsString -> WindowsString -> BoolCheck whether one string is a substring of another.
isPrefixOf :: WindowsString -> WindowsString -> BoolO(n) The isPrefixOf function takes two OsStrings and returns True
isSuffixOf :: WindowsString -> WindowsString -> BoolO(n) The isSuffixOf function takes two OsStrings and returns True
iff the first is a suffix of the second.
The following holds:
isSuffixOf x y == reverse x `isPrefixOf` reverse ybreakSubstring :: WindowsString -> WindowsString -> (WindowsString, WindowsString)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.
elem :: WindowsChar -> WindowsString -> BoolO(n) elem is the OsString membership predicate.
find :: (WindowsChar -> Bool) -> WindowsString -> Maybe WindowsCharO(n) The find function takes a predicate and a OsString,
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 :: (WindowsChar -> Bool) -> WindowsString -> WindowsStringO(n) filter, applied to a predicate and a OsString,
returns a OsString containing those characters that satisfy the
predicate.
partition :: (WindowsChar -> Bool) -> WindowsString -> (WindowsString, WindowsString)O(n) The partition function takes a predicate a OsString and returns
the pair of OsStrings with elements which do and do not satisfy the
predicate, respectively; i.e.,
partition p bs == (filter p sbs, filter (not . p) sbs)index :: HasCallStack => WindowsString -> Int -> WindowsCharO(1) OsString index (subscript) operator, starting from 0.
indexMaybe :: WindowsString -> Int -> Maybe WindowsCharO(1) OsString index, starting from 0, that returns Just if:
0 <= n < length bs(!?) :: WindowsString -> Int -> Maybe WindowsCharO(1) OsString index, starting from 0, that returns Just if:
0 <= n < length bselemIndex :: WindowsChar -> WindowsString -> Maybe IntO(n) The elemIndex function returns the index of the first
element in the given OsString which is equal to the query
element, or Nothing if there is no such element.
elemIndices :: WindowsChar -> WindowsString -> [Int]O(n) The elemIndices function extends elemIndex, by returning
the indices of all elements equal to the query element, in ascending order.
count :: WindowsChar -> WindowsString -> Intcount returns the number of times its argument appears in the OsString
findIndex :: (WindowsChar -> Bool) -> WindowsString -> Maybe IntO(n) The findIndex function takes a predicate and a OsString and
returns the index of the first element in the OsString
satisfying the predicate.
findIndices :: (WindowsChar -> Bool) -> WindowsString -> [Int]O(n) The findIndices function extends findIndex, by returning the
indices of all elements satisfying the predicate, in ascending order.
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