Source Code Cross Referenced for ReplaceableString.java in  » Internationalization-Localization » icu4j » com » ibm » icu » text » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Internationalization Localization » icu4j » com.ibm.icu.text 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *******************************************************************************
003:         * Copyright (C) 1996-2004, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         */
007:        package com.ibm.icu.text;
008:
009:        import com.ibm.icu.impl.Utility;
010:
011:        /**
012:         * <code>ReplaceableString</code> is an adapter class that implements the
013:         * <code>Replaceable</code> API around an ordinary <code>StringBuffer</code>.
014:         *
015:         * <p><em>Note:</em> This class does not support attributes and is not
016:         * intended for general use.  Most clients will need to implement
017:         * {@link Replaceable} in their text representation class.
018:         *
019:         * <p>Copyright &copy; IBM Corporation 1999.  All rights reserved.
020:         *
021:         * @see Replaceable
022:         * @author Alan Liu
023:         * @stable ICU 2.0
024:         */
025:        public class ReplaceableString implements  Replaceable {
026:            private StringBuffer buf;
027:
028:            private static final String COPYRIGHT = "\u00A9 IBM Corporation 1999. All rights reserved.";
029:
030:            /**
031:             * Construct a new object with the given initial contents.
032:             * @param str initial contents
033:             * @stable ICU 2.0
034:             */
035:            public ReplaceableString(String str) {
036:                buf = new StringBuffer(str);
037:            }
038:
039:            /**
040:             * Construct a new object using <code>buf</code> for internal
041:             * storage.  The contents of <code>buf</code> at the time of
042:             * construction are used as the initial contents.  <em>Note!
043:             * Modifications to <code>buf</code> will modify this object, and
044:             * vice versa.</em>
045:             * @param buf object to be used as internal storage
046:             * @stable ICU 2.0
047:             */
048:            public ReplaceableString(StringBuffer buf) {
049:                this .buf = buf;
050:            }
051:
052:            /**
053:             * Construct a new empty object.
054:             * @stable ICU 2.0
055:             */
056:            public ReplaceableString() {
057:                buf = new StringBuffer();
058:            }
059:
060:            /**
061:             * Return the contents of this object as a <code>String</code>.
062:             * @return string contents of this object
063:             * @stable ICU 2.0
064:             */
065:            public String toString() {
066:                return buf.toString();
067:            }
068:
069:            /**
070:             * Return a substring of the given string.
071:             * @stable ICU 2.0
072:             */
073:            public String substring(int start, int limit) {
074:                return buf.substring(start, limit);
075:            }
076:
077:            /**
078:             * Return the number of characters contained in this object.
079:             * <code>Replaceable</code> API.
080:             * @stable ICU 2.0
081:             */
082:            public int length() {
083:                return buf.length();
084:            }
085:
086:            /**
087:             * Return the character at the given position in this object.
088:             * <code>Replaceable</code> API.
089:             * @param offset offset into the contents, from 0 to
090:             * <code>length()</code> - 1
091:             * @stable ICU 2.0
092:             */
093:            public char charAt(int offset) {
094:                return buf.charAt(offset);
095:            }
096:
097:            /**
098:             * Return the 32-bit code point at the given 16-bit offset into
099:             * the text.  This assumes the text is stored as 16-bit code units
100:             * with surrogate pairs intermixed.  If the offset of a leading or
101:             * trailing code unit of a surrogate pair is given, return the
102:             * code point of the surrogate pair.
103:             * @param offset an integer between 0 and <code>length()</code>-1
104:             * inclusive
105:             * @return 32-bit code point of text at given offset
106:             * @stable ICU 2.0
107:             */
108:            public int char32At(int offset) {
109:                return UTF16.charAt(buf, offset);
110:            }
111:
112:            /**
113:             * Copies characters from this object into the destination
114:             * character array.  The first character to be copied is at index
115:             * <code>srcStart</code>; the last character to be copied is at
116:             * index <code>srcLimit-1</code> (thus the total number of
117:             * characters to be copied is <code>srcLimit-srcStart</code>). The
118:             * characters are copied into the subarray of <code>dst</code>
119:             * starting at index <code>dstStart</code> and ending at index
120:             * <code>dstStart + (srcLimit-srcStart) - 1</code>.
121:             *
122:             * @param srcStart the beginning index to copy, inclusive; <code>0
123:             * <= start <= limit</code>.
124:             * @param srcLimit the ending index to copy, exclusive;
125:             * <code>start <= limit <= length()</code>.
126:             * @param dst the destination array.
127:             * @param dstStart the start offset in the destination array.
128:             * @stable ICU 2.0
129:             */
130:            public void getChars(int srcStart, int srcLimit, char dst[],
131:                    int dstStart) {
132:                Utility.getChars(buf, srcStart, srcLimit, dst, dstStart);
133:            }
134:
135:            /**
136:             * Replace zero or more characters with new characters.
137:             * <code>Replaceable</code> API.
138:             * @param start the beginning index, inclusive; <code>0 <= start
139:             * <= limit</code>.
140:             * @param limit the ending index, exclusive; <code>start <= limit
141:             * <= length()</code>.
142:             * @param text new text to replace characters <code>start</code> to
143:             * <code>limit - 1</code>
144:             * @stable ICU 2.0
145:             */
146:            public void replace(int start, int limit, String text) {
147:                buf.replace(start, limit, text);
148:            }
149:
150:            /**
151:             * Replace a substring of this object with the given text.
152:             * @param start the beginning index, inclusive; <code>0 <= start
153:             * <= limit</code>.
154:             * @param limit the ending index, exclusive; <code>start <= limit
155:             * <= length()</code>.
156:             * @param chars the text to replace characters <code>start</code>
157:             * to <code>limit - 1</code>
158:             * @param charsStart the beginning index into <code>chars</code>,
159:             * inclusive; <code>0 <= start <= limit</code>.
160:             * @param charsLen the number of characters of <code>chars</code>.
161:             * @stable ICU 2.0
162:             */
163:            public void replace(int start, int limit, char[] chars,
164:                    int charsStart, int charsLen) {
165:                buf.delete(start, limit);
166:                buf.insert(start, chars, charsStart, charsLen);
167:            }
168:
169:            /**
170:             * Copy a substring of this object, retaining attribute (out-of-band)
171:             * information.  This method is used to duplicate or reorder substrings.
172:             * The destination index must not overlap the source range.
173:             * 
174:             * @param start the beginning index, inclusive; <code>0 <= start <=
175:             * limit</code>.
176:             * @param limit the ending index, exclusive; <code>start <= limit <=
177:             * length()</code>.
178:             * @param dest the destination index.  The characters from
179:             * <code>start..limit-1</code> will be copied to <code>dest</code>.
180:             * Implementations of this method may assume that <code>dest <= start ||
181:             * dest >= limit</code>.
182:             * @stable ICU 2.0
183:             */
184:            public void copy(int start, int limit, int dest) {
185:                if (start == limit && start >= 0 && start <= buf.length()) {
186:                    return;
187:                }
188:                char[] text = new char[limit - start];
189:                getChars(start, limit, text, 0);
190:                replace(dest, dest, text, 0, limit - start);
191:            }
192:
193:            /**
194:             * Implements Replaceable
195:             * @stable ICU 2.0
196:             */
197:            public boolean hasMetaData() {
198:                return false;
199:            }
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.