1 19 20 package org.netbeans.modules.properties; 21 22 36 public class UtilConvert { 37 38 private UtilConvert() { 39 } 40 41 44 public static final String keyValueSeparators = "=: \t\r\n\f"; 45 46 public static final String strictKeyValueSeparators = "=:"; 47 48 49 private static final String specialSaveChars = "=:\t\r\n\f#!"; 50 51 public static final String whiteSpaceChars = " \t\r\n\f"; 52 53 54 59 public static String escapePropertiesSpecialChars (String source) { 60 return source; } 78 79 80 private static boolean onlySpaces(String s){ 81 for (int i = 0; i<s.length(); i++){ 82 if (s.charAt(i) != ' ') return false; 83 } 84 return true; 85 } 86 87 88 public static String escapeOutsideSpaces(String source){ 89 return source; } 111 112 116 public static String escapeLineContinuationChar(String source) { 117 return source; } 125 126 130 public static String escapeJavaSpecialChars(String source) { 131 return source; } 158 159 160 164 public static String unicodesToChars (String theString) { 165 return theString; } 211 212 217 public static String escapeComment(String commentString) { 218 return charsToUnicodes(commentString, true); 219 } 220 221 225 public static String charsToUnicodes(String s){ 226 return charsToUnicodes(s, false); 227 } 228 229 230 234 public static String charsToUnicodes(String theString, boolean skipWhiteSpaces) { 235 return theString; } 263 264 265 269 public static String loadConvert (String theString) { 270 char aChar; 271 final int len = theString.length(); 272 StringBuffer outBuffer = new StringBuffer (len); 273 274 main: 275 for(int x=0; x<len; ) { 276 aChar = theString.charAt(x++); 277 if (aChar == '\\' && x != len) { 278 aChar = theString.charAt(x++); 279 if(aChar == 'u') { 280 if (x > len - 4) { 281 outBuffer.append('\\').append('u'); 282 continue main; 283 } 284 int value=0; 286 for (int i=0; i<4; i++) { 287 aChar = theString.charAt(x++); 288 switch (aChar) { 289 case '0': case '1': case '2': case '3': case '4': 290 case '5': case '6': case '7': case '8': case '9': 291 value = (value << 4) + aChar - '0'; 292 break; 293 case 'a': case 'b': case 'c': 294 case 'd': case 'e': case 'f': 295 value = (value << 4) + 10 + aChar - 'a'; 296 break; 297 case 'A': case 'B': case 'C': 298 case 'D': case 'E': case 'F': 299 value = (value << 4) + 10 + aChar - 'A'; 300 break; 301 default: 302 309 outBuffer.append('\\').append('u'); 310 311 312 x -= i + 1; 313 314 315 continue main; 316 } 317 } 318 outBuffer.append((char)value); 319 } else { 320 if (aChar == 't') aChar = '\t'; 321 else if (aChar == 'r') aChar = '\r'; 322 else if (aChar == 'n') aChar = '\n'; 323 else if (aChar == 'f') aChar = '\f'; 324 outBuffer.append(aChar); 325 } 326 } else 327 outBuffer.append(aChar); 328 } 329 return outBuffer.toString(); 330 } 331 332 338 public static String saveConvert(String theString) { 339 return saveConvert(theString, false); 340 } 341 342 public static String saveConvert(String theString, boolean escapeSpace) { 343 char aChar; 344 int len = theString.length(); 345 StringBuffer outBuffer = new StringBuffer (len*2); 346 347 for(int x=0; x<len; ) { 348 aChar = theString.charAt(x++); 349 switch(aChar) { 350 case '\\':outBuffer.append('\\'); outBuffer.append('\\'); 351 continue; 352 case '\t':outBuffer.append('\\'); outBuffer.append('t'); 353 continue; 354 case '\n':outBuffer.append('\\'); outBuffer.append('n'); 355 continue; 356 case '\r':outBuffer.append('\\'); outBuffer.append('r'); 357 continue; 358 case '\f':outBuffer.append('\\'); outBuffer.append('f'); 359 continue; 360 default: 361 if ((aChar < 20) || (aChar > 127)) { 362 outBuffer.append('\\'); 363 outBuffer.append('u'); 364 outBuffer.append(toHex((aChar >> 12) & 0xF)); 365 outBuffer.append(toHex((aChar >> 8) & 0xF)); 366 outBuffer.append(toHex((aChar >> 4) & 0xF)); 367 outBuffer.append(toHex((aChar >> 0) & 0xF)); 368 } else if (escapeSpace && (aChar == ' ')) { 369 outBuffer.append('\\').append(' '); 370 } else { 371 if (specialSaveChars.indexOf(aChar) != -1) 372 outBuffer.append('\\'); 373 outBuffer.append(aChar); 374 } 375 } 376 } 377 return outBuffer.toString(); 378 } 379 380 384 private static char toHex(int nibble) { 385 return hexDigit[(nibble & 0xF)]; 386 } 387 388 389 private static final char[] hexDigit = { 390 '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' 391 }; 392 } 393 | Popular Tags |