Replace >\> with >> in s. Replace \>> unless prefix of \>>> with >>. Do NOT replace if it's <\\>
(String s)
| 140 | */ |
| 141 | |
| 142 | public static String replaceEscapedRightAngle(String s) { |
| 143 | StringBuilder buf = new StringBuilder(); |
| 144 | int i = 0; |
| 145 | while ( i < s.length() ) { |
| 146 | char c = s.charAt(i); |
| 147 | if ( c=='<' && s.substring(i).startsWith("<\\\\>") ) { |
| 148 | buf.append("<\\\\>"); |
| 149 | i += "<\\\\>".length(); |
| 150 | continue; |
| 151 | } |
| 152 | |
| 153 | if ( c=='>' && s.substring(i).startsWith(">\\>") ) { |
| 154 | buf.append(">>"); |
| 155 | i += ">\\>".length(); |
| 156 | continue; |
| 157 | } |
| 158 | |
| 159 | if ( c=='\\' && s.substring(i).startsWith("\\>>") && !s.substring(i).startsWith("\\>>>") ) { |
| 160 | buf.append(">>"); |
| 161 | i += "\\>>".length(); |
| 162 | continue; |
| 163 | } |
| 164 | buf.append(c); |
| 165 | i++; |
| 166 | } |
| 167 | return buf.toString(); |
| 168 | } |
| 169 | |
| 170 | public static boolean urlExists(URL url) { |
| 171 | try { |