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