Path: blob/master/src/java.base/share/classes/jdk/internal/icu/text/ReplaceableString.java
41161 views
/*1* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26*******************************************************************************27* Copyright (C) 1996-2009, International Business Machines Corporation and *28* others. All Rights Reserved. *29*******************************************************************************30*/3132package jdk.internal.icu.text;3334/**35* <code>ReplaceableString</code> is an adapter class that implements the36* <code>Replaceable</code> API around an ordinary <code>StringBuffer</code>.37*38* <p><em>Note:</em> This class does not support attributes and is not39* intended for general use. Most clients will need to implement40* {@link Replaceable} in their text representation class.41*42* <p>Copyright © IBM Corporation 1999. All rights reserved.43*44* @see Replaceable45* @author Alan Liu46* @stable ICU 2.047*/48public class ReplaceableString implements Replaceable {4950private StringBuffer buf;5152/**53* Construct a new object with the given initial contents.54* @param str initial contents55* @stable ICU 2.056*/57public ReplaceableString(String str) {58buf = new StringBuffer(str);59}6061/**62* Construct a new object using <code>buf</code> for internal63* storage. The contents of <code>buf</code> at the time of64* construction are used as the initial contents. <em>Note!65* Modifications to <code>buf</code> will modify this object, and66* vice versa.</em>67* @param buf object to be used as internal storage68* @stable ICU 2.069*/70public ReplaceableString(StringBuffer buf) {71this.buf = buf;72}7374/**75* Return the number of characters contained in this object.76* <code>Replaceable</code> API.77* @stable ICU 2.078*/79public int length() {80return buf.length();81}8283/**84* Return the character at the given position in this object.85* <code>Replaceable</code> API.86* @param offset offset into the contents, from 0 to87* <code>length()</code> - 188* @stable ICU 2.089*/90public char charAt(int offset) {91return buf.charAt(offset);92}9394/**95* Copies characters from this object into the destination96* character array. The first character to be copied is at index97* <code>srcStart</code>; the last character to be copied is at98* index <code>srcLimit-1</code> (thus the total number of99* characters to be copied is <code>srcLimit-srcStart</code>). The100* characters are copied into the subarray of <code>dst</code>101* starting at index <code>dstStart</code> and ending at index102* <code>dstStart + (srcLimit-srcStart) - 1</code>.103*104* @param srcStart the beginning index to copy, inclusive;105* {@code 0 <= start <= limit}.106* @param srcLimit the ending index to copy, exclusive;107* {@code start <= limit <= length()}.108* @param dst the destination array.109* @param dstStart the start offset in the destination array.110* @stable ICU 2.0111*/112public void getChars(int srcStart, int srcLimit, char dst[], int dstStart) {113if (srcStart != srcLimit) {114buf.getChars(srcStart, srcLimit, dst, dstStart);115}116}117}118119120