- Timestamp:
- 2019-04-30T18:33:42+12:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/util/Misc.java
r32608 r33043 56 56 } 57 57 } 58 58 59 60 // Debugging function to print a string's non-basic chars in hex 61 // Based on https://stackoverflow.com/questions/923863/converting-a-string-to-hexadecimal-in-java 62 public static String stringToHex(String str) { 63 String result = ""; 64 for(int i = 0; i < str.length(); i++) { 65 int charCode = str.codePointAt(i); // unicode codepoint / ASCII code 66 67 // ASCII table: https://cdn.sparkfun.com/assets/home_page_posts/2/1/2/1/ascii_table_black.png 68 // 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 printable 70 result += str.charAt(i); 71 } else { 72 result += "x" + String.format("%04x", charCode); 73 } 74 } 75 76 return result; 77 } 78 79 59 80 public static void printHash(HashMap map) { 60 81 Set entries = map.entrySet();
Note:
See TracChangeset
for help on using the changeset viewer.