35
35
import java .util .Set ;
36
36
import java .util .SortedSet ;
37
37
import java .util .TreeSet ;
38
+ import java .util .regex .Pattern ;
38
39
import org .opensolaris .opengrok .analysis .Definitions .Tag ;
39
40
import org .opensolaris .opengrok .analysis .Scopes .Scope ;
40
41
import org .opensolaris .opengrok .configuration .Project ;
@@ -217,8 +218,8 @@ protected void appendProject() throws IOException {
217
218
}
218
219
219
220
/**
220
- * Calls {@link #appendLink(java.lang.String, boolean)} with false to
221
- * disable {@code doPushback} handling .
221
+ * Calls {@link #appendLink(java.lang.String, boolean)} with {@code url}
222
+ * and false .
222
223
* @param url the URL to append
223
224
* @throws IOException if an error occurs while appending
224
225
*/
@@ -227,30 +228,64 @@ protected void appendLink(String url) throws IOException {
227
228
}
228
229
229
230
/**
230
- * Appends the {@code url} to the active {@link Writer}. If
231
- * {@code doPushback} is true, then any characters counted by
232
- * {@link StringUtils#countURIEndingPushback(java.lang.String)} are
233
- * handled by {@link #yypushback(int)} with {@code url} only partially
234
- * written.
235
- * <p>If the count is equal to the length of {@code url}, then it is
236
- * simply written, and nothing is pushed back.
231
+ * Calls
232
+ * {@link #appendLink(java.lang.String, boolean, java.util.regex.Pattern)}
233
+ * with {@code url}, {@code doEndingPushback}, and null.
237
234
* @param url the URL to append
238
- * @param doPushback a value indicating whether to test the {@code url}
239
- * with {@link StringUtils#countURIEndingPushback(java.lang.String)}.
235
+ * @param doEndingPushback a value indicating whether to test the
236
+ * {@code url} with
237
+ * {@link StringUtils#countURIEndingPushback(java.lang.String)}
240
238
* @throws IOException if an error occurs while appending
241
239
*/
242
- protected void appendLink (String url , boolean doPushback )
240
+ protected void appendLink (String url , boolean doEndingPushback )
243
241
throws IOException {
244
242
245
- if (doPushback ) {
246
- int n = StringUtils .countURIEndingPushback (url );
247
- // Push back if positive, but not if equal to the current length,
248
- // or else the pushback might cause a neverending loop.
249
- if (n > 0 && n < url .length ()) {
250
- yypushback (n );
251
- url = url .substring (0 , url .length () - n );
243
+ appendLink (url , doEndingPushback , null );
244
+ }
245
+
246
+ /**
247
+ * Appends the {@code url} to the active {@link Writer}.
248
+ * <p>If {@code doEndingPushback} is true, then
249
+ * {@link StringUtils#countURIEndingPushback(java.lang.String)} is enlisted
250
+ * for use with {@link #yypushback(int)} -- i.e., {@code url} is only
251
+ * partially written.
252
+ * <p>If {@code collateralCapture} is not null, then its match in
253
+ * {@code url} will alternatively mark the start of a count for pushback --
254
+ * i.e., everything at and beyond the first {@code collateralCapture} match
255
+ * will be considered not to belong to the URI.
256
+ * <p>If the pushback count is equal to the length of {@code url}, then it
257
+ * is simply written -- and nothing is pushed back -- in order to avoid a
258
+ * never-ending {@code yylex()} loop.
259
+ * @param url the URL to append
260
+ * @param doEndingPushback a value indicating whether to test the
261
+ * {@code url} with
262
+ * {@link StringUtils#countURIEndingPushback(java.lang.String)}
263
+ * @param collateralCapture optional pattern to indicate characters which
264
+ * may have been captured as valid URI characters but in a particular
265
+ * context should mark the start of a pushback
266
+ * @throws IOException if an error occurs while appending
267
+ */
268
+ protected void appendLink (String url , boolean doEndingPushback ,
269
+ Pattern collateralCapture )
270
+ throws IOException {
271
+
272
+ int n = 0 ;
273
+ if (doEndingPushback ) {
274
+ n = StringUtils .countURIEndingPushback (url );
275
+ }
276
+ if (collateralCapture != null ) {
277
+ int o = StringUtils .patindexOf (url , collateralCapture );
278
+ if (o > 0 ) {
279
+ int ccn = url .length () - o ;
280
+ if (ccn > n ) n = ccn ;
252
281
}
253
282
}
283
+ // Push back if positive, but not if equal to the current length.
284
+ if (n > 0 && n < url .length ()) {
285
+ yypushback (n );
286
+ url = url .substring (0 , url .length () - n );
287
+ }
288
+
254
289
out .write ("<a href=\" " );
255
290
out .write (Util .formQuoteEscape (url ));
256
291
out .write ("\" >" );
0 commit comments