remove nonprintable chars

This commit is contained in:
chrys 2016-11-04 21:25:54 +01:00
parent d161275465
commit f540b9658d
2 changed files with 8 additions and 0 deletions

View File

@ -96,6 +96,7 @@ class driver():
self.env['screenData']['newCursor']['y'] = int( self.env['screenData']['newContentBytes'][3])
# analyze content
self.env['screenData']['newContentText'] = self.env['screenData']['newContentBytes'][4:][::2].decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
self.env['screenData']['newContentText'] = screen_utils.removeNonprintable(self.env['screenData']['newContentText'])
self.env['screenData']['newContentAttrib'] = self.env['screenData']['newContentBytes'][5:][::2]
self.env['screenData']['newContentText'] = screen_utils.insertNewlines(self.env['screenData']['newContentText'], self.env['screenData']['columns'])

View File

@ -6,6 +6,13 @@
from core import debug
from collections import Counter
import string
def removeNonprintable(text):
# Get the difference of all ASCII characters from the set of printable characters
nonprintable = set([chr(i) for i in range(128)]).difference(string.printable)
# Use translate to remove all non-printable characters
return text.translate({ord(character):None for character in nonprintable})
def insertNewlines(string, every=64):
return '\n'.join(string[i:i+every] for i in range(0, len(string), every))