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