stringutils¶
A functional string utility library for Python 2 and 3. Closely inspired by implementations in Haskell and PHP.
For more documentation, please see http://stringutils.readthedocs.io.
Note
This package is still in an early development stage, and it is possible that the naming and API of some functions will change.
Features¶
The main design goal of this library is to provide helpful string functions which complement what can already be done with str, str.format and textwrap. As such, it includes:
- A selective set of additional string helper functions.
- Extended versions of existing str methods as functions where useful.
Usage¶
All functions are available directly off the stringutils
package. You may choose to import individual functions by name, or import all.
from stringutils import reverse, unwords, words
def reverse_words(string):
return unwords(map(reverse, words(string)))
Contribute¶
- Source code: https://github.com/huntie/stringutils
- Issue tracker: https://github.com/huntie/stringutils/issues
License¶
The project is licensed under the MIT license.
Function reference¶
Assertions¶
-
stringutils.
contains
(string, matches)[source]¶ Determine if a string contains any of the given values. matches may be a single string, or a list of strings.
Case conversion¶
All functions which convert to programming case formats accept strings in any of the other formats.
-
stringutils.
dashed_case
(string)[source]¶ Convert a string identifier to
dashed-case
. If the string is insnake_case
, capitalization of words will be preserved.
Lists¶
-
stringutils.
join
(strings, sep=', ', insertend=False)[source]¶ Concatenate a list of strings into a single string by a separating delimiter. If insertend is given and true, the delimiter is also included at the end of the string.
-
stringutils.
lines
(string, keepends=False)[source]¶ Split a string into a list of strings at newline characters. Unless keepends is given and true, the resulting strings do not have newlines included.
-
stringutils.
split_identifier
(string)[source]¶ Split a string identifier into a list of its subparts.
-
stringutils.
words
(string)[source]¶ Split a string into a list of words, which were delimited by one or more whitespace characters.