Skip to content

Commit

Permalink
Merge pull request beeware#733 from BPYap/master
Browse files Browse the repository at this point in the history
Modified Str.isCharPrintable to check for Unicode category
  • Loading branch information
freakboy3742 authored Mar 6, 2018
2 parents b1ad31c + 74b01ad commit 54680a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 11 additions & 8 deletions python/common/org/python/types/Str.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ public Str(org.python.Object[] args, java.util.Map<java.lang.String, org.python.
// }

private static boolean isCharPrintable(char c) {
// ASCII non-printable
if ((int) c <= 0x1f || (int) c >= 0x7f && (int) c <= 0xa0 || (int) c == 0xad) {
return false;
}
if ((int) c == 0x2029) {
return false;
}
if (Character.isISOControl(c)) {
// Characters except space ' ' in the following categories are
// not printable:
// 0 - UNASSIGNED
// 12 - SPACE_SEPARATOR
// 13 - LINE_SEPARATOR
// 14 - PARAGRAPH_SEPARATOR
// 15 - CONTROL
// 16 - FORMAT
// 17 - PRIVATE_USE
// 18 - SURROGATE
if ((Character.getType(c) == 0 || (Character.getType(c) >= 12 && Character.getType(c) <= 18)) && c != ' ') {
return false;
}
return true;
Expand Down
3 changes: 1 addition & 2 deletions tests/datatypes/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,9 @@ def test_isprintable(self):
print(str_.isprintable())
""")

@expectedFailure
def test_isprintable_missing_cases(self):
self.assertCodeExecution(r"""
tests = ['\u2028']:
tests = ['\u2028', '\u2029', '\u00A0']
for test in tests:
print(test.isprintable())
""")
Expand Down

0 comments on commit 54680a6

Please sign in to comment.