418 } |
418 } |
419 return originalStr.replace(oldStr, newStr); |
419 return originalStr.replace(oldStr, newStr); |
420 } |
420 } |
421 |
421 |
422 /** |
422 /** |
423 * Given a string, escape all special html characters and |
|
424 * return the result. |
|
425 * |
|
426 * @param s The string to check. |
|
427 * @return the original string with all of the HTML characters escaped. |
|
428 */ |
|
429 public static String escapeHtmlChars(String s) { |
|
430 for (int i = 0; i < s.length(); i++) { |
|
431 char ch = s.charAt(i); |
|
432 switch (ch) { |
|
433 // only start building a new string if we need to |
|
434 case '<': case '>': case '&': |
|
435 StringBuilder sb = new StringBuilder(s.substring(0, i)); |
|
436 for ( ; i < s.length(); i++) { |
|
437 ch = s.charAt(i); |
|
438 switch (ch) { |
|
439 case '<': sb.append("<"); break; |
|
440 case '>': sb.append(">"); break; |
|
441 case '&': sb.append("&"); break; |
|
442 default: sb.append(ch); break; |
|
443 } |
|
444 } |
|
445 return sb.toString(); |
|
446 } |
|
447 } |
|
448 return s; |
|
449 } |
|
450 |
|
451 /** |
|
452 * Escape all special html characters in a string buffer. |
|
453 * |
|
454 * @param sb The string buffer to update |
|
455 */ |
|
456 public static void escapeHtmlChars(StringBuilder sb) { |
|
457 // scan backwards, replacing characters as needed. |
|
458 for (int i = sb.length() - 1; i >= 0; i--) { |
|
459 switch (sb.charAt(i)) { |
|
460 case '<': sb.replace(i, i+1, "<"); break; |
|
461 case '>': sb.replace(i, i+1, ">"); break; |
|
462 case '&': sb.replace(i, i+1, "&"); break; |
|
463 } |
|
464 } |
|
465 } |
|
466 |
|
467 /** |
|
468 * Given a string, strips all html characters and |
|
469 * return the result. |
|
470 * |
|
471 * @param rawString The string to check. |
|
472 * @return the original string with all of the HTML characters |
|
473 * stripped. |
|
474 * |
|
475 */ |
|
476 public static String stripHtml(String rawString) { |
|
477 // remove HTML tags |
|
478 rawString = rawString.replaceAll("\\<.*?>", " "); |
|
479 // consolidate multiple spaces between a word to a single space |
|
480 rawString = rawString.replaceAll("\\b\\s{2,}\\b", " "); |
|
481 // remove extra whitespaces |
|
482 return rawString.trim(); |
|
483 } |
|
484 |
|
485 /** |
|
486 * Given an annotation, return true if it should be documented and false |
423 * Given an annotation, return true if it should be documented and false |
487 * otherwise. |
424 * otherwise. |
488 * |
425 * |
489 * @param annotationDoc the annotation to check. |
426 * @param annotationDoc the annotation to check. |
490 * |
427 * |