View | Details | Raw Unified | Return to bug 53713
Collapse All | Expand All

(-)apache/jasper/compiler/JspReader.java (-17 / +70 lines)
Lines 191-196 Link Here
191
        }
191
        }
192
        return ch;
192
        return ch;
193
    }
193
    }
194
    
195
    /**
196
     * A better performance solution for calling {@link #mark()} & {@link #nextChar()}
197
     * Assume that the parameter mark should be used internal.
198
     * 
199
     * @param mark
200
     * @return
201
     * @throws JasperException
202
     */
203
    int nextChar(Mark mark) throws JasperException {
204
        if (!hasMoreInput())
205
            return -1;
206
        
207
        int ch = current.stream[current.cursor];
208
209
        if (singleFile) { //Simplified
210
        	mark.update(current);
211
        }
212
        else {
213
        	mark.init(current);
214
        }
215
        
216
        current.cursor++;
217
        
218
        if (ch == '\n') {
219
            current.line++;
220
            current.col = 0;
221
        } else {
222
            current.col++;
223
        }
224
        return ch;
225
    }
194
226
195
    /**
227
    /**
196
     * Back up the current cursor by one char, assumes current.cursor > 0,
228
     * Back up the current cursor by one char, assumes current.cursor > 0,
Lines 205-214 Link Here
205
        Mark oldstart = mark();
237
        Mark oldstart = mark();
206
        reset(start);
238
        reset(start);
207
        CharArrayWriter caw = new CharArrayWriter();
239
        CharArrayWriter caw = new CharArrayWriter();
208
        while (!stop.equals(mark()))
240
        while (!markEquals(stop))
209
            caw.write(nextChar());
241
            caw.write(nextChar());
210
        caw.close();
242
        caw.close();
211
        reset(oldstart);
243
        setCurrent(oldstart);
212
        return caw.toString();
244
        return caw.toString();
213
    }
245
    }
214
246
Lines 221-230 Link Here
221
    Mark mark() {
253
    Mark mark() {
222
        return new Mark(current);
254
        return new Mark(current);
223
    }
255
    }
256
    
257
    /**
258
     * This method can avoid to call {@link #mark()} when doing comparison.
259
     * It is used in {@link #getText(Mark, Mark)}
260
     * 
261
     * @param another
262
     * @return
263
     */
264
    boolean markEquals(Mark another) {
265
    	return another.equals(current);
266
    }
224
267
225
    void reset(Mark mark) {
268
    void reset(Mark mark) {
226
        current = new Mark(mark);
269
        current = new Mark(mark);
227
    }
270
    }
271
    
272
    /**
273
     * Similar with {@link #reset(Mark)}, however, no new Mark will be created.
274
     * So the parameter mark must NOT be used in other place.
275
     * 
276
     * @param mark
277
     */
278
    void setCurrent(Mark mark) {
279
    	current = mark;
280
    }
228
281
229
    /**
282
    /**
230
     * search the stream for a match to a string
283
     * search the stream for a match to a string
Lines 240-246 Link Here
240
        do {
293
        do {
241
            ch = nextChar();
294
            ch = nextChar();
242
            if (((char) ch) != string.charAt(i++)) {
295
            if (((char) ch) != string.charAt(i++)) {
243
                reset(mark);
296
            	setCurrent(mark);
244
                return false;
297
                return false;
245
            }
298
            }
246
        } while (i < string.length());
299
        } while (i < string.length());
Lines 256-262 Link Here
256
        if (nextChar() == '>')
309
        if (nextChar() == '>')
257
            return true;
310
            return true;
258
311
259
        reset(mark);
312
        setCurrent(mark);
260
        return false;
313
        return false;
261
    }
314
    }
262
315
Lines 271-277 Link Here
271
       if (nextChar() == '>')
324
       if (nextChar() == '>')
272
           return true;
325
           return true;
273
326
274
       reset(mark);
327
       setCurrent(mark);
275
       return false;
328
       return false;
276
    }
329
    }
277
330
Lines 290-296 Link Here
290
        skipSpaces();
343
        skipSpaces();
291
        boolean result = matches( s );
344
        boolean result = matches( s );
292
        if( !result ) {
345
        if( !result ) {
293
            reset( mark );
346
        	setCurrent( mark );
294
        }
347
        }
295
348
296
        return result;
349
        return result;
Lines 315-334 Link Here
315
     *         otherwise.
368
     *         otherwise.
316
     */
369
     */
317
    Mark skipUntil(String limit) throws JasperException {
370
    Mark skipUntil(String limit) throws JasperException {
318
        Mark ret = null;
371
        Mark ret = mark();
319
        int limlen = limit.length();
372
        int limlen = limit.length();
320
        int ch;
373
        int ch;
321
374
375
        char firstChar = limit.charAt(0);
322
    skip:
376
    skip:
323
        for (ret = mark(), ch = nextChar() ; ch != -1 ;
377
        for (ch = nextChar(ret) ; ch != -1 ;ch = nextChar(ret)) {
324
                 ret = mark(), ch = nextChar()) {
378
            if (ch == firstChar) {
325
            if (ch == limit.charAt(0)) {
326
                Mark restart = mark();
379
                Mark restart = mark();
327
                for (int i = 1 ; i < limlen ; i++) {
380
                for (int i = 1 ; i < limlen ; i++) {
328
                    if (peekChar() == limit.charAt(i))
381
                    if (peekChar() == limit.charAt(i))
329
                        nextChar();
382
                        nextChar();
330
                    else {
383
                    else {
331
                        reset(restart);
384
                    	setCurrent(restart);
332
                        continue skip;
385
                        continue skip;
333
                    }
386
                    }
334
                }
387
                }
Lines 349-366 Link Here
349
     *         otherwise.
402
     *         otherwise.
350
     */
403
     */
351
    Mark skipUntilIgnoreEsc(String limit) throws JasperException {
404
    Mark skipUntilIgnoreEsc(String limit) throws JasperException {
352
        Mark ret = null;
405
        Mark ret = mark();
353
        int limlen = limit.length();
406
        int limlen = limit.length();
354
        int ch;
407
        int ch;
355
        int prev = 'x';        // Doesn't matter
408
        int prev = 'x';        // Doesn't matter
356
        
409
        
410
        char firstChar = limit.charAt(0);
357
    skip:
411
    skip:
358
        for (ret = mark(), ch = nextChar() ; ch != -1 ;
412
        for (ch = nextChar(ret) ; ch != -1 ; prev = ch, ch = nextChar(ret)) {            
359
                 ret = mark(), prev = ch, ch = nextChar()) {            
360
            if (ch == '\\' && prev == '\\') {
413
            if (ch == '\\' && prev == '\\') {
361
                ch = 0;                // Double \ is not an escape char anymore
414
                ch = 0;                // Double \ is not an escape char anymore
362
            }
415
            }
363
            else if (ch == limit.charAt(0) && prev != '\\') {
416
            else if (ch == firstChar && prev != '\\') {
364
                for (int i = 1 ; i < limlen ; i++) {
417
                for (int i = 1 ; i < limlen ; i++) {
365
                    if (peekChar() == limit.charAt(i))
418
                    if (peekChar() == limit.charAt(i))
366
                        nextChar();
419
                        nextChar();
Lines 477-486 Link Here
477
                Mark mark = mark();
530
                Mark mark = mark();
478
                if (((ch = nextChar()) == '>')
531
                if (((ch = nextChar()) == '>')
479
                        || ((ch == '-') && (nextChar() == '>'))) {
532
                        || ((ch == '-') && (nextChar() == '>'))) {
480
                    reset(mark);
533
                	setCurrent(mark);
481
                    return true;
534
                    return true;
482
                } else {
535
                } else {
483
                    reset(mark);
536
                	setCurrent(mark);
484
                    return false;
537
                    return false;
485
                }
538
                }
486
            }
539
            }

Return to bug 53713