summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-02-14 12:47:54 +0100
committerJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-02-14 12:47:54 +0100
commit47706b9d02b8a444e5b712d99c9b511ce91a7992 (patch)
tree2a6b165b1978969fd77eb76df06911bc4abe7565 /sqlparse
parent10afc2054a39ea5a5a07a20ab181b18b89feee9c (diff)
downloadsqlparse-47706b9d02b8a444e5b712d99c9b511ce91a7992.tar.gz
Added StripWhitespace filter
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/filters.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/sqlparse/filters.py b/sqlparse/filters.py
index 23d06e1..d54105e 100644
--- a/sqlparse/filters.py
+++ b/sqlparse/filters.py
@@ -75,6 +75,26 @@ class StripComments(Filter):
yield token_type, value
+def StripWhitespace(stream):
+ """Strip the whitespaces from a stream"""
+ last_type = None
+
+ for token_type, value in stream:
+ if last_type == None:
+ if token_type not in Whitespace + Punctuation:
+ yield token_type, value
+ last_type = token_type
+
+ else:
+ if token_type in Whitespace:
+ if last_type not in Whitespace:
+ yield token_type, ' '
+ else:
+ yield token_type, value
+
+ last_type = token_type
+
+
class IncludeStatement(Filter):
"""Filter that enable a INCLUDE statement"""