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