add 't' format string conversion (closes #1065)
to Trim whitespace from the beginning and end of strings.
Example: '{field!t}' becomes 'foo' for 'field' == " \nfoo\t\r"
This commit is contained in:
@@ -495,6 +495,7 @@ class Formatter():
|
||||
- "u": calls str.upper
|
||||
- "c": calls str.capitalize
|
||||
- "C": calls string.capwords
|
||||
- "t": calls str.strip
|
||||
- "U": calls urllib.parse.unquote
|
||||
- "S": calls util.to_string()
|
||||
- Example: {f!l} -> "example"; {f!u} -> "EXAMPLE"
|
||||
@@ -525,6 +526,7 @@ class Formatter():
|
||||
"u": str.upper,
|
||||
"c": str.capitalize,
|
||||
"C": string.capwords,
|
||||
"t": str.strip,
|
||||
"U": urllib.parse.unquote,
|
||||
"S": to_string,
|
||||
"s": str,
|
||||
|
||||
@@ -265,6 +265,7 @@ class TestFormatter(unittest.TestCase):
|
||||
"d": {"a": "foo", "b": 0, "c": None},
|
||||
"l": ["a", "b", "c"],
|
||||
"n": None,
|
||||
"s": " \n\r\tSPACE ",
|
||||
"u": "%27%3C%20/%20%3E%27",
|
||||
"name": "Name",
|
||||
"title1": "Title",
|
||||
@@ -278,6 +279,7 @@ class TestFormatter(unittest.TestCase):
|
||||
self._run_test("{a!u}", "HELLO WORLD")
|
||||
self._run_test("{a!c}", "Hello world")
|
||||
self._run_test("{a!C}", "Hello World")
|
||||
self._run_test("{s!t}", "SPACE")
|
||||
self._run_test("{a!U}", self.kwdict["a"])
|
||||
self._run_test("{u!U}", "'< / >'")
|
||||
self._run_test("{a!s}", self.kwdict["a"])
|
||||
|
||||
Reference in New Issue
Block a user