001: /*
002: * Portions Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: /*
027: *******************************************************************************
028: * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved *
029: * *
030: * The original version of this source code and documentation is copyrighted *
031: * and owned by IBM, These materials are provided under terms of a License *
032: * Agreement between IBM and Sun. This technology is protected by multiple *
033: * US and International patents. This notice and attribution to IBM may not *
034: * to removed. *
035: *******************************************************************************
036: */
037:
038: package sun.text.normalizer;
039:
040: /**
041: * <code>ReplaceableString</code> is an adapter class that implements the
042: * <code>Replaceable</code> API around an ordinary <code>StringBuffer</code>.
043: *
044: * <p><em>Note:</em> This class does not support attributes and is not
045: * intended for general use. Most clients will need to implement
046: * {@link Replaceable} in their text representation class.
047: *
048: * <p>Copyright © IBM Corporation 1999. All rights reserved.
049: *
050: * @see Replaceable
051: * @author Alan Liu
052: * @stable ICU 2.0
053: */
054: public class ReplaceableString implements Replaceable {
055:
056: private StringBuffer buf;
057:
058: /**
059: * Construct a new object with the given initial contents.
060: * @param str initial contents
061: * @stable ICU 2.0
062: */
063: public ReplaceableString(String str) {
064: buf = new StringBuffer(str);
065: }
066:
067: //// for StringPrep
068: /**
069: * Construct a new object using <code>buf</code> for internal
070: * storage. The contents of <code>buf</code> at the time of
071: * construction are used as the initial contents. <em>Note!
072: * Modifications to <code>buf</code> will modify this object, and
073: * vice versa.</em>
074: * @param buf object to be used as internal storage
075: * @stable ICU 2.0
076: */
077: public ReplaceableString(StringBuffer buf) {
078: this .buf = buf;
079: }
080:
081: /**
082: * Return the number of characters contained in this object.
083: * <code>Replaceable</code> API.
084: * @stable ICU 2.0
085: */
086: public int length() {
087: return buf.length();
088: }
089:
090: /**
091: * Return the character at the given position in this object.
092: * <code>Replaceable</code> API.
093: * @param offset offset into the contents, from 0 to
094: * <code>length()</code> - 1
095: * @stable ICU 2.0
096: */
097: public char charAt(int offset) {
098: return buf.charAt(offset);
099: }
100:
101: //// for StringPrep
102: /**
103: * Copies characters from this object into the destination
104: * character array. The first character to be copied is at index
105: * <code>srcStart</code>; the last character to be copied is at
106: * index <code>srcLimit-1</code> (thus the total number of
107: * characters to be copied is <code>srcLimit-srcStart</code>). The
108: * characters are copied into the subarray of <code>dst</code>
109: * starting at index <code>dstStart</code> and ending at index
110: * <code>dstStart + (srcLimit-srcStart) - 1</code>.
111: *
112: * @param srcStart the beginning index to copy, inclusive; <code>0
113: * <= start <= limit</code>.
114: * @param srcLimit the ending index to copy, exclusive;
115: * <code>start <= limit <= length()</code>.
116: * @param dst the destination array.
117: * @param dstStart the start offset in the destination array.
118: * @stable ICU 2.0
119: */
120: public void getChars(int srcStart, int srcLimit, char dst[],
121: int dstStart) {
122: Utility.getChars(buf, srcStart, srcLimit, dst, dstStart);
123: }
124: }
|