- Timestamp:
- 2019-04-30T18:33:42+12:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js
r32893 r33043 11 11 { 12 12 return $("#" + id.replace(/\./g, "\\.").replace(/:/g,"\\:")); 13 } 14 15 // Debugging function to print a string's non-basic chars in hex 16 // Based on https://stackoverflow.com/questions/36637146/javascript-encode-string-to-hex/36637293 17 // https://stackoverflow.com/questions/21647928/javascript-unicode-string-to-hex 18 gs.functions.string2hex = function(str) { 19 var hex, i; 20 21 var result = ""; 22 for (i=0; i<str.length; i++) { 23 charcode = str.charCodeAt(i); 24 // ASCII table: https://cdn.sparkfun.com/assets/home_page_posts/2/1/2/1/ascii_table_black.png 25 // 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) 26 if(charcode < 20 || charcode > 126) { //doesn't work: if(str.charAt(i) < ' ' || str.charAt(i) > '~') { 27 hex = charcode.toString(16); 28 result += "x" + ("000"+hex).slice(-4); 29 } 30 else { 31 result += str.charAt(i); 32 } 33 } 34 35 return result; 13 36 } 14 37
Note:
See TracChangeset
for help on using the changeset viewer.