- Timestamp:
- 2019-05-03T21:46:42+12:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/util/Misc.java
r33043 r33045 58 58 59 59 60 // Debugging function to print a string's non-basic chars in hex 60 // Debugging function to print a string's non-basic chars in hex, so stringToHex on all non-basic and non-printable ASCII 61 // Dr Bainbridge said that printing anything with charCode over 128 in hex is okay, but I'd already made extra allowances for non-printable ASCII 61 62 // Based on https://stackoverflow.com/questions/923863/converting-a-string-to-hexadecimal-in-java 62 public static String stringToHex(String str) {63 public static String debugUnicodeString(String str) { 63 64 String result = ""; 64 65 for(int i = 0; i < str.length(); i++) { … … 67 68 // ASCII table: https://cdn.sparkfun.com/assets/home_page_posts/2/1/2/1/ascii_table_black.png 68 69 // If the unicode character code pt is less than the ASCII code for space and greater than for tilda, let's display the char in hex (x0000 format) 69 if((charCode >= 20 && charCode <= 126) || charCode == 9 || charCode == 10 || charCode == 13) { // space to tilda, TAB, LF, CR are printable70 if((charCode >= 20 && charCode <= 126) || charCode == 9 || charCode == 10 || charCode == 13) { // space, tilda, TAB, LF, CR are printable, leave them in for XML element printing 70 71 result += str.charAt(i); 71 72 } else { 72 result += "x " + String.format("%04x", charCode);73 result += "x{" + String.format("%04x", charCode) + "}"; // looks like: x{4-char-codepoint} 73 74 } 74 75 }
Note:
See TracChangeset
for help on using the changeset viewer.