GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / src / web / org / codehaus / groovy / grails / web / pages / Reverse.java
blobc1e4cf8d433c782b6b518a669bbbb7b1952d1aa3
1 /*
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;
17 /**
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
23 * Date: Jan 10, 2004
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) {
35 this.text = text;
36 this.start = start;
37 this.end = end;
38 anchor = end - 1;
40 public char charAt(int index) {
41 return text.charAt(anchor - index);
44 public int length() {
45 return end - start;
48 public CharSequence subSequence(int start, int end) {
49 return new Reverse(text, anchor - end, anchor - start);
52 public String toString() {
53 int len = length();
54 StringBuffer buf = new StringBuffer(len);
55 for (int ix = anchor; ix >= start; ix--) {
56 buf.append(text.charAt(ix));
58 return buf.toString();
60 } // Reverse