001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.commons.lang; 020 021 022public class CharSequenceImpl implements CharSequence { 023 024 private final char[] chars; 025 private final String str; 026 private final String lcStr; 027 028 /** 029 * Constructor of the class 030 * @param chars 031 */ 032 public CharSequenceImpl(char[] chars) { 033 this.str=new String(chars); 034 this.chars=chars; 035 036 char c; 037 for(int i=0;i<chars.length;i++) { 038 c=chars[i]; 039 if(!((c>='a' && c<='z') || (c>='0' && c<='9'))) { 040 lcStr=str.toLowerCase(); 041 return ; 042 } 043 } 044 lcStr=str; 045 } 046 047 /** 048 * Constructor of the class 049 * @param str 050 */ 051 public CharSequenceImpl(String str) { 052 this(str.toCharArray()); 053 } 054 055 @Override 056 public char charAt(int index) { 057 return chars[index]; 058 } 059 060 @Override 061 public int length() { 062 return chars.length; 063 } 064 065 @Override 066 public CharSequence subSequence(int start, int end) { 067 char[] dest = new char[end-start]; 068 System.arraycopy(chars, start, dest, 0, end-start); 069 return new CharSequenceImpl(dest); 070 } 071 072 @Override 073 public String toString() { 074 return str; 075 } 076 077 public String toLowerCaseString() { 078 return lcStr; 079 } 080}