MissingH API ManualContentsIndex
MissingH.Str
Portability portable
Stability provisional
Maintainer jgoerzen@complete.org
Contents
Whitespace Removal
Tests
Conversions
Description

This module provides various helpful utilities for dealing with strings.

Written by John Goerzen, jgoerzen@complete.org

Synopsis
strip :: String -> String
lstrip :: String -> String
rstrip :: String -> String
startswith :: Eq a => [a] -> [a] -> Bool
endswith :: Eq a => [a] -> [a] -> Bool
join :: [a] -> [[a]] -> [a]
split :: Eq a => [a] -> [a] -> [[a]]
splitRe :: Regex -> String -> [String]
replace :: Eq a => [a] -> [a] -> [a] -> [a]
subRe :: Regex -> String -> String -> String
Whitespace Removal
strip :: String -> String

Removes any whitespace characters that are present at the start or end of a string. Does not alter the internal contents of a string. If no whitespace characters are present at the start or end of a string, returns the original string unmodified. Safe to use on any string.

Note that this may differ from some other similar functions from other authors in that:

1. If multiple whitespace characters are present all in a row, they are all removed;

2. If no whitespace characters are present, nothing is done.

lstrip :: String -> String
Same as strip, but applies only to the left side of the string.
rstrip :: String -> String
Same as strip, but applies only to the right side of the string.
Tests
Note: These functions are aliases for functions in MissingH.List.
startswith :: Eq a => [a] -> [a] -> Bool

Returns true if the given list starts with the specified elements; false otherwise. (This is an alias for Data.List.isPrefixOf.)

Example:

 startswith "He" "Hello" -> True
endswith :: Eq a => [a] -> [a] -> Bool

Returns true if the given list ends with the specified elements; false otherwise. (This is an alias for Data.List.isSuffixOf.)

Example:

 endswith "lo" "Hello" -> True
Conversions
Note: Some of these functions are aliases for functions in MissingH.List.
join :: [a] -> [[a]] -> [a]

Given a delimiter and a list of items (or strings), join the items by using the delimiter.

Example:

 join "|" ["foo", "bar", "baz"] -> "foo|bar|baz"
split :: Eq a => [a] -> [a] -> [[a]]

Given a delimiter and a list (or string), split into components.

Example:

 split "," "foo,bar,,baz," -> ["foo", "bar", "", "baz", ""]
 split "ba" ",foo,bar,,baz," -> [",foo,","r,,","z,"]
splitRe :: Regex -> String -> [String]
Splits a string based on a regular expression. The regular expression should identify one delimiter.
replace :: Eq a => [a] -> [a] -> [a] -> [a]

Given a list and a replacement list, replaces each occurance of the search list with the replacement list in the operation list.

Example:

replace "," "." "127,0,0,1" -> "127.0.0.1"
subRe
:: RegexSearch pattern
-> StringInput string
-> StringReplacement text
-> StringOutput string

Replaces every occurance of the given regexp with the replacement string.

In the replacement string, "\1" refers to the first substring; "\2" to the second, etc; and "\0" to the entire match. "\\\\" will insert a literal backslash.

Produced by Haddock version 0.6