1/* GENERATED SOURCE. DO NOT MODIFY. */
2// © 2016 and later: Unicode, Inc. and others.
3// License & terms of use: http://www.unicode.org/copyright.html#License
4/*
5 *******************************************************************************
6 * Copyright (C) 1996-2016, International Business Machines Corporation and    *
7 * others. All Rights Reserved.                                                *
8 *******************************************************************************
9 */
10package android.icu.text;
11
12/**
13 * <code>Replaceable</code> is an interface representing a
14 * string of characters that supports the replacement of a range of
15 * itself with a new string of characters.  It is used by APIs that
16 * change a piece of text while retaining metadata.  Metadata is data
17 * other than the Unicode characters returned by char32At().  One
18 * example of metadata is style attributes; another is an edit
19 * history, marking each character with an author and revision number.
20 *
21 * <p>An implicit aspect of the <code>Replaceable</code> API is that
22 * during a replace operation, new characters take on the metadata of
23 * the old characters.  For example, if the string "the <b>bold</b>
24 * font" has range (4, 8) replaced with "strong", then it becomes "the
25 * <b>strong</b> font".
26 *
27 * <p><code>Replaceable</code> specifies ranges using a start
28 * offset and a limit offset.  The range of characters thus specified
29 * includes the characters at offset start..limit-1.  That is, the
30 * start offset is inclusive, and the limit offset is exclusive.
31 *
32 * <p><code>Replaceable</code> also includes API to access characters
33 * in the string: <code>length()</code>, <code>charAt()</code>,
34 * <code>char32At()</code>, and <code>extractBetween()</code>.
35 *
36 * <p>For a subclass to support metadata, typical behavior of
37 * <code>replace()</code> is the following:
38 * <ul>
39 *   <li>Set the metadata of the new text to the metadata of the first
40 *   character replaced</li>
41 *   <li>If no characters are replaced, use the metadata of the
42 *   previous character</li>
43 *   <li>If there is no previous character (i.e. start == 0), use the
44 *   following character</li>
45 *   <li>If there is no following character (i.e. the replaceable was
46 *   empty), use default metadata<br>
47 *   <li>If the code point U+FFFF is seen, it should be interpreted as
48 *   a special marker having no metadata<li>
49 *   </li>
50 * </ul>
51 * If this is not the behavior, the subclass should document any differences.
52 *
53 * <p>Copyright &copy; IBM Corporation 1999.  All rights reserved.
54 *
55 * @author Alan Liu
56 */
57public interface Replaceable {
58    /**
59     * Returns the number of 16-bit code units in the text.
60     * @return number of 16-bit code units in text
61     */
62    int length();
63
64    /**
65     * Returns the 16-bit code unit at the given offset into the text.
66     * @param offset an integer between 0 and <code>length()</code>-1
67     * inclusive
68     * @return 16-bit code unit of text at given offset
69     */
70    char charAt(int offset);
71
72    /**
73     * Returns the 32-bit code point at the given 16-bit offset into
74     * the text.  This assumes the text is stored as 16-bit code units
75     * with surrogate pairs intermixed.  If the offset of a leading or
76     * trailing code unit of a surrogate pair is given, return the
77     * code point of the surrogate pair.
78     *
79     * <p>Most subclasses can return
80     * <code>android.icu.text.UTF16.charAt(this, offset)</code>.
81     * @param offset an integer between 0 and <code>length()</code>-1
82     * inclusive
83     * @return 32-bit code point of text at given offset
84     */
85    int char32At(int offset);
86
87    /**
88     * Copies characters from this object into the destination
89     * character array.  The first character to be copied is at index
90     * <code>srcStart</code>; the last character to be copied is at
91     * index <code>srcLimit-1</code> (thus the total number of
92     * characters to be copied is <code>srcLimit-srcStart</code>). The
93     * characters are copied into the subarray of <code>dst</code>
94     * starting at index <code>dstStart</code> and ending at index
95     * <code>dstStart + (srcLimit-srcStart) - 1</code>.
96     *
97     * @param srcStart the beginning index to copy, inclusive; <code>0
98     * &lt;= start &lt;= limit</code>.
99     * @param srcLimit the ending index to copy, exclusive;
100     * <code>start &lt;= limit &lt;= length()</code>.
101     * @param dst the destination array.
102     * @param dstStart the start offset in the destination array.
103     */
104    void getChars(int srcStart, int srcLimit, char dst[], int dstStart);
105
106    /**
107     * Replaces a substring of this object with the given text.
108     *
109     * <p>Subclasses must ensure that if the text between start and
110     * limit is equal to the replacement text, that replace has no
111     * effect. That is, any metadata
112     * should be unaffected. In addition, subclasses are encouraged to
113     * check for initial and trailing identical characters, and make a
114     * smaller replacement if possible. This will preserve as much
115     * metadata as possible.
116     * @param start the beginning index, inclusive; <code>0 &lt;= start
117     * &lt;= limit</code>.
118     * @param limit the ending index, exclusive; <code>start &lt;= limit
119     * &lt;= length()</code>.
120     * @param text the text to replace characters <code>start</code>
121     * to <code>limit - 1</code>
122     */
123    void replace(int start, int limit, String text);
124
125    /**
126     * Replaces a substring of this object with the given text.
127     *
128     * <p>Subclasses must ensure that if the text between start and
129     * limit is equal to the replacement text, that replace has no
130     * effect. That is, any metadata
131     * should be unaffected. In addition, subclasses are encouraged to
132     * check for initial and trailing identical characters, and make a
133     * smaller replacement if possible. This will preserve as much
134     * metadata as possible.
135     * @param start the beginning index, inclusive; <code>0 &lt;= start
136     * &lt;= limit</code>.
137     * @param limit the ending index, exclusive; <code>start &lt;= limit
138     * &lt;= length()</code>.
139     * @param chars the text to replace characters <code>start</code>
140     * to <code>limit - 1</code>
141     * @param charsStart the beginning index into <code>chars</code>,
142     * inclusive; <code>0 &lt;= start &lt;= limit</code>.
143     * @param charsLen the number of characters of <code>chars</code>.
144     */
145    void replace(int start, int limit, char[] chars,
146                 int charsStart, int charsLen);
147    // Note: We use length rather than limit to conform to StringBuffer
148    // and System.arraycopy.
149
150    /**
151     * Copies a substring of this object, retaining metadata.
152     * This method is used to duplicate or reorder substrings.
153     * The destination index must not overlap the source range.
154     * If <code>hasMetaData()</code> returns false, subclasses
155     * may use the naive implementation:
156     *
157     * <pre> char[] text = new char[limit - start];
158     * getChars(start, limit, text, 0);
159     * replace(dest, dest, text, 0, limit - start);</pre>
160     *
161     * @param start the beginning index, inclusive; <code>0 &lt;= start &lt;=
162     * limit</code>.
163     * @param limit the ending index, exclusive; <code>start &lt;= limit &lt;=
164     * length()</code>.
165     * @param dest the destination index.  The characters from
166     * <code>start..limit-1</code> will be copied to <code>dest</code>.
167     * Implementations of this method may assume that <code>dest &lt;= start ||
168     * dest &gt;= limit</code>.
169     */
170    void copy(int start, int limit, int dest);
171
172    /**R
173     * Returns true if this object contains metadata.  If a
174     * Replaceable object has metadata, calls to the Replaceable API
175     * must be made so as to preserve metadata.  If it does not, calls
176     * to the Replaceable API may be optimized to improve performance.
177     * @return true if this object contains metadata
178     */
179    boolean hasMetaData();
180}
181