Guest User

Untitled

a guest
Oct 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4.  
  5. filter_chars = [' ', 't', 'n', 'r']
  6.  
  7.  
  8. def is_filtered_char(c):
  9. return c in filter_chars
  10.  
  11.  
  12. def is_filtered_eol_char(c):
  13. return c in ['n', 'r']
  14.  
  15. inside_double_quoted_string = inside_single_quoted_string = False
  16. some_chars = sys.stdin.read()
  17. for c in some_chars:
  18. if c == '"':
  19. if not inside_double_quoted_string:
  20. inside_double_quoted_string = True
  21. else:
  22. inside_double_quoted_string = False
  23. if c == "'":
  24. if not inside_single_quoted_string:
  25. inside_single_quoted_string = True
  26. else:
  27. inside_single_quoted_string = False
  28.  
  29. if not inside_double_quoted_string and not inside_single_quoted_string and not is_filtered_char(c):
  30. sys.stdout.write(c)
  31. elif (inside_double_quoted_string or inside_single_quoted_string) and not is_filtered_eol_char(c):
  32. sys.stdout.write(c)
Add Comment
Please, Sign In to add comment