2 * Copyright 2004-2005 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.codehaus
.groovy
.grails
.web
.pages
;
18 * NOTE: Based on work done by on the GSP standalone project (https://gsp.dev.java.net/)
20 * Utility class to reverse a char sequence.
22 * @author Troy Heninger
26 class Reverse
implements CharSequence
{
27 private CharSequence text
;
28 private int start
, end
, anchor
;
30 Reverse(CharSequence text
) {
31 this(text
, 0, text
.length());
34 Reverse(CharSequence text
, int start
, int end
) {
40 public char charAt(int index
) {
41 return text
.charAt(anchor
- index
);
48 public CharSequence
subSequence(int start
, int end
) {
49 return new Reverse(text
, anchor
- end
, anchor
- start
);
52 public String
toString() {
54 StringBuffer buf
= new StringBuffer(len
);
55 for (int ix
= anchor
; ix
>= start
; ix
--) {
56 buf
.append(text
.charAt(ix
));
58 return buf
.toString();