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
|
- "u": calls str.upper
|
||||||
- "c": calls str.capitalize
|
- "c": calls str.capitalize
|
||||||
- "C": calls string.capwords
|
- "C": calls string.capwords
|
||||||
|
- "t": calls str.strip
|
||||||
- "U": calls urllib.parse.unquote
|
- "U": calls urllib.parse.unquote
|
||||||
- "S": calls util.to_string()
|
- "S": calls util.to_string()
|
||||||
- Example: {f!l} -> "example"; {f!u} -> "EXAMPLE"
|
- Example: {f!l} -> "example"; {f!u} -> "EXAMPLE"
|
||||||
@@ -525,6 +526,7 @@ class Formatter():
|
|||||||
"u": str.upper,
|
"u": str.upper,
|
||||||
"c": str.capitalize,
|
"c": str.capitalize,
|
||||||
"C": string.capwords,
|
"C": string.capwords,
|
||||||
|
"t": str.strip,
|
||||||
"U": urllib.parse.unquote,
|
"U": urllib.parse.unquote,
|
||||||
"S": to_string,
|
"S": to_string,
|
||||||
"s": str,
|
"s": str,
|
||||||
|
|||||||
@@ -265,6 +265,7 @@ class TestFormatter(unittest.TestCase):
|
|||||||
"d": {"a": "foo", "b": 0, "c": None},
|
"d": {"a": "foo", "b": 0, "c": None},
|
||||||
"l": ["a", "b", "c"],
|
"l": ["a", "b", "c"],
|
||||||
"n": None,
|
"n": None,
|
||||||
|
"s": " \n\r\tSPACE ",
|
||||||
"u": "%27%3C%20/%20%3E%27",
|
"u": "%27%3C%20/%20%3E%27",
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"title1": "Title",
|
"title1": "Title",
|
||||||
@@ -278,6 +279,7 @@ class TestFormatter(unittest.TestCase):
|
|||||||
self._run_test("{a!u}", "HELLO WORLD")
|
self._run_test("{a!u}", "HELLO WORLD")
|
||||||
self._run_test("{a!c}", "Hello world")
|
self._run_test("{a!c}", "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("{a!U}", self.kwdict["a"])
|
||||||
self._run_test("{u!U}", "'< / >'")
|
self._run_test("{u!U}", "'< / >'")
|
||||||
self._run_test("{a!s}", self.kwdict["a"])
|
self._run_test("{a!s}", self.kwdict["a"])
|
||||||
|
|||||||
Reference in New Issue
Block a user