1 19 20 package org.netbeans.modules.tasklist.javaparser; 21 22 import org.netbeans.modules.tasklist.core.TLUtils; 23 24 28 public class JPUtils { 29 45 public static void replaceSymbol(StringBuffer sb, String text, int pos, String symbol, 46 String newSymbol, boolean bold, 47 int underlineBegin, int underlineEnd) { 48 if (pos > 0) { 50 pos--; 53 } 54 int from = 0; 55 int symLen = symbol.length(); 56 int texLen = text.length(); 57 while (true) { 58 int n = text.indexOf(symbol, pos); 59 if (n == -1) { 60 break; 61 } 62 if ((n+symLen < texLen-1) && 63 Character.isJavaIdentifierPart(text.charAt(n+symLen))) { 64 pos = n+symLen; 65 continue; 66 } 67 68 for (int i = from; i < n; i++) { 69 TLUtils.appendHTMLChar(sb, text.charAt(i)); 70 } 71 if (bold) { 72 sb.append("<b>"); } 74 if (underlineBegin != -1) { 75 for (int i = 0; i < underlineBegin; i++) { 76 TLUtils.appendHTMLChar(sb, newSymbol.charAt(i)); 77 } 78 sb.append("<u>"); for (int i = underlineBegin; i < underlineEnd; i++) { 80 TLUtils.appendHTMLChar(sb, newSymbol.charAt(i)); 81 } 82 sb.append("</u>"); int nl = newSymbol.length(); 84 for (int i = underlineEnd; i < nl; i++) { 85 TLUtils.appendHTMLChar(sb, newSymbol.charAt(i)); 86 } 87 } else { 88 TLUtils.appendHTMLString(sb, newSymbol); 89 } 90 if (bold) { 91 sb.append("</b>"); } 93 pos = n+symLen; 94 from = pos; 95 } 96 for (int i = from; i < texLen; i++) { 97 TLUtils.appendHTMLChar(sb, text.charAt(i)); 98 } 99 } 100 } 101 | Popular Tags |