cd6d4007aa
libjava/ChangeLog: 2008-10-21 Andrew John Hughes <gnu_andrew@member.fsf.org> * sources.am, Makfile.in: Regenerate. 2008-10-17 Matthias Klose <doko@ubuntu.com> * configure.ac: Fix bashisms. * configure: Regenerate. 2008-10-15 Matthias Klose <doko@ubuntu.com> * configure.ac: Disable build of gjdoc, if configured without --with-antlr-jar or if no antlr.jar found. * configure: Regenerate. 2008-10-09 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/configure.ac, * classpath/m4/ac_prog_antlr.m4, * classpath/m4/ac_prog_java.m4, * classpath/tools/Makefile.am: Ported --regen-gjdoc-parser patch and cantlr support from GNU Classpath. 2008-10-06 Andrew Haley <aph@redhat.com> * java/lang/Thread.java (Thread): Always create the ThreadLocalMap when creating a thread. (getThreadLocals) Don't lazily create the ThreadLocalMap. 2008-09-28 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/java/lang/ThreadLocalMap.java, * java/lang/ThreadLocalMap$Entry.h, * java/lang/ThreadLocalMap.h, * lib/java/lang/ThreadLocalMap.class, * lib/java/lang/ThreadLocalMap$Entry.class: Add the new files for the ThreadLocal patch. 2008-09-28 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/ChangeLog, * classpath/java/lang/InheritableThreadLocal.java, * classpath/java/lang/Thread.java, * classpath/java/lang/ThreadLocal.java: Merge Daniel Frampton's ThreadLocal patch. * gcj/javaprims.h: Updated. * java/lang/Thread.h: Regenerated. * java/lang/Thread.java: Replace WeakIdentityHashMap with ThreadLocalMap. (getThreadLocals()): Likewise. * java/lang/ThreadLocal.h: Regenerated. * java/lang/ThreadLocal.java: (computeNextHash()): New method. (ThreadLocal()): Initialise fastHash. (internalGet()): Updated to match Classpath's get(). (internalSet(Object)): Likewise for set(Object). (internalRemove()): Likewise for remove(). 2008-09-25 Andrew John Hughes <gnu_andrew@member.fsf.org> * classpath/configure, * classpath/configure.ac: Resynchronise with Classpath's configure. * classpath/examples/Makefile.in: Add equivalent support for building as in tools/Makefile.in. * classpath/java/nio/Buffer.java, * classpath/java/nio/ByteBuffer.java, * classpath/java/nio/ByteBufferImpl.java, * classpath/java/nio/CharBuffer.java, * classpath/java/nio/CharBufferImpl.java, * classpath/java/nio/CharSequenceBuffer.java, * classpath/java/nio/CharViewBufferImpl.java, * classpath/java/nio/DirectByteBufferImpl.java, * classpath/java/nio/DoubleBuffer.java, * classpath/java/nio/DoubleBufferImpl.java, * classpath/java/nio/DoubleViewBufferImpl.java, * classpath/java/nio/FloatBuffer.java, * classpath/java/nio/FloatBufferImpl.java, * classpath/java/nio/FloatViewBufferImpl.java, * classpath/java/nio/IntBuffer.java, * classpath/java/nio/IntBufferImpl.java, * classpath/java/nio/IntViewBufferImpl.java, * classpath/java/nio/LongBuffer.java, * classpath/java/nio/LongBufferImpl.java, * classpath/java/nio/LongViewBufferImpl.java, * classpath/java/nio/MappedByteBuffer.java, * classpath/java/nio/MappedByteBufferImpl.java, * classpath/java/nio/ShortBuffer.java, * classpath/java/nio/ShortBufferImpl.java, * classpath/java/nio/ShortViewBufferImpl.java: Replace use of gnu.classpath.Pointer with gnu.gcj.RawData, and fix some formatting issues. * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaLexer.java, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaLexer.smap, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaRecognizer.java, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaRecognizer.smap, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaTokenTypes.java, * classpath/tools/gnu/classpath/tools/gjdoc/expr/JavaTokenTypes.txt: Regenerated (later version of antlr). * java/nio/Buffer.h: Regenerated. * java/nio/Buffer.java: Ported changes from Classpath. * java/nio/ByteBuffer.h, * java/nio/CharBuffer.h: Regenerated. * java/nio/DirectByteBufferImpl.java: Ported changes from Classpath. * java/nio/DoubleBuffer.h, * java/nio/FloatBuffer.h, * java/nio/IntBuffer.h, * java/nio/LongBuffer.h, * java/nio/MappedByteBuffer.h, * java/nio/MappedByteBufferImpl.h: Regenerated. * java/nio/MappedByteBufferImpl.java: Ported changes from Classpath. * java/nio/ShortBuffer.h: Regenerated. 2008-09-24 Matthias Klose <doko@ubuntu.com> * configure.ac: Search for antlr.jar, if not configured. * configure: Regenerate. 2008-09-24 Matthias Klose <doko@ubuntu.com> * Makefile.am: Build a gjdoc binary, if enabled. * configure.ac: Add options --disable-gjdoc, --with-antlr-jar=file. * Makefile.in, */Makefile.in, configure: Regenerate. 2008-09-22 Andrew Haley <aph@redhat.com> * java/lang/String.java (toString(char[], int, int)): New method. 2008-09-14 Matthias Klose <doko@ubuntu.com> Import GNU Classpath (libgcj-import-20080914). * Regenerate class and header files. * Regenerate auto* files. * configure.ac: Don't pass --disable-gjdoc to classpath. * sources.am: Regenerated. * HACKING: Mention to build gjdoc in maintainer builds. * gnu/classpath/Configuration.java: Update classpath version. * gcj/javaprims.h: Update. 2008-09-08 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.am: Replace natStringBuffer.cc and natStringBuilder.cc with natAbstractStringBuffer.cc. * Makefile.in: Regenerated. * java/lang/AbstractStringBuffer.java: (append(int)): Made native. (regionMatches(int,String)): Likewise. * java/lang/StringBuffer.h: Regenerated. * java/lang/StringBuffer.java: Remerged with GNU Classpath. * java/lang/StringBuilder.h: Regenerated. * java/lang/StringBuilder.java: Remerged with GNU Classpath. * java/lang/natAbstractStringBuffer.cc: Provide common native methods for StringBuffer and StringBuilder. * java/lang/natStringBuffer.cc, * java/lang/natStringBuilder.cc: Removed. 2008-09-04 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.in, * classpath/configure: Regenerated. * gnu/gcj/util/natDebug.cc, * gnu/gcj/xlib/natColormap.cc, * gnu/gcj/xlib/natDisplay.cc, * gnu/gcj/xlib/natDrawable.cc, * gnu/gcj/xlib/natFont.cc, * gnu/gcj/xlib/natWMSizeHints.cc, * gnu/gcj/xlib/natWindow.cc, * gnu/gcj/xlib/natXImage.cc: Add :: prefix to namespaces. * java/io/CharArrayWriter.h, * java/lang/StringBuffer.h: Regenerated using patched gjavah. * java/lang/natStringBuffer.cc: Fix naming of append(jint). * java/sql/Timestamp.h: Regenerated using patched gjavah. * jni.cc: Rename p to functions to match change in GNU Classpath. * scripts/makemake.tcl: Switch gnu.java.math to BC compilation. * sources.am: Regenerated. 2008-08-21 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.in: Updated location of Configuration.java. * classpath/lib/gnu/java/locale/LocaleData.class: Regenerated. 2008-08-18 Andrew John Hughes <gnu_andrew@member.fsf.org> * Makefile.in: Updated with new Java files. * classpath/configure: Regenerated. * classpath/tools/Makefile.am: Add missing use of GJDOC_EX so --disable-gjdoc works. * classpath/tools/Makefile.in: Regenerated. 2008-08-15 Matthias Klose <doko@ubuntu.com> Import GNU Classpath (libgcj-import-20080811). * Regenerate class and header files. * Regenerate auto* files. * configure.ac: Don't pass --with-fastjar to classpath, substitute new dummy value in classpath/gnu/classpath/Configuration.java.in, pass --disable-gjdoc to classpath. * scripts/makemake.tcl: * sources.am: Regenerated. * java/lang/AbstractStringBuffer.java, gnu/java/lang/VMCPStringBuilder.java: New, copied from classpath, use System instead of VMSystem. * java/lang/StringBuffer.java: Merge from classpath. * java/lang/ClassLoader.java: Merge from classpath. * gcj/javaprims.h: Update class definitions, remove _Jv_jobjectRefType, jobjectRefType definitions. libjava/classpath/ChangeLog.gcj: 2008-10-21 Matthias Klose <doko@ubuntu.com> * classpath/tools/gnu/classpath/tools/gjdoc/expr/Java*: Move from ... * classpath/tools/generated/gnu/classpath/tools/gjdoc/expr/ ... here. * Update .class files. 2008-10-21 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/Makefile.am: Always generate parser in the srcdir. 2008-10-21 Matthias Klose <doko@ubuntu.com> * doc/Makefile.am (MAINTAINERCLEANFILES): Add gjdoc.1. * doc/Makefile.in: Regenerate. 2008-10-20 Matthias Klose <doko@ubuntu.com> * configure.ac: Don't check for working java, if not configured with --enable-java-maintainer-mode. * configure: Regenerate. 2008-10-19 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_java.m4: Revert previous change. * m4/ac_prog_javac.m4: Apply it here. * configure: Regenerate. 2008-10-19 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_javac.m4: Don't check for working javac, if not configured with --enable-java-maintainer-mode. * configure: Regenerate. * Makefile.in, */Makefile.in: Regenerate. 2008-09-30 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_antlr.m4: Check for cantlr binary as well. 2008-09-29 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_antlr.m4: Check for antlr binary as well. 2008-09-28 Matthias Klose <doko@ubuntu.com> * PR libgcj/37636. Revert: 2008-02-20 Matthias Klose <doko@ubuntu.com> * tools/Makefile.am ($(TOOLS_ZIP)): Revert part of previous change, Do copy resource files in JAVA_MAINTAINER_MODE only. * tools/Makefile.in: Regenerate. 2008-09-14 Matthias Klose <doko@ubuntu.com> * m4/ac_prog_javac_works.m4, m4/ac_prog_javac.m4, m4/acinclude.m4: Revert local changes. * m4/ac_prog_antlr.m4: Check for an runantlr binary. * tools/Makefile.am, lib/Makefile.am: Revert local changes (JCOMPILER). * tools/Makefile.am: Remove USE_JAVAC_FLAGS, pass ANTLR_JAR in GLIBJ_CLASSPATH. 2008-09-14 Matthias Klose <doko@ubuntu.com> Revert: Daniel Frampton <zyridium at zyridium.net> * AUTHORS: Added. * java/lang/InheritableThreadLocal.java, * java/lang/Thread.java, * java/lang/ThreadLocal.java: Modified to use java.lang.ThreadLocalMap. * java/lang/ThreadLocalMap.java: New cheaper ThreadLocal-specific WeakHashMap. 2008-08-15 Matthias Klose <doko@ubuntu.com> * m4/acinclude.m4 (CLASSPATH_JAVAC_MEM_CHECK): Remove unknown args for javac. libjava/classpath/ChangeLog: 2008-10-20 Andrew John Hughes <gnu_andrew@member.fsf.org> * m4/ac_prog_antlr.m4: Remove redundant checks. * tools/Makefile.am: Use gjdoc_gendir when calling antlr. 2008-10-15 Andrew John Hughes <gnu_andrew@member.fsf.org> * configure.ac: Remove superfluous AC_PROG_JAVA call. 2008-10-06 Andrew John Hughes <gnu_andrew@member.fsf.org> * m4/ac_prog_antlr: Check for cantlr as well. * tools/Makefile.am: Only build GJDoc parser when both CREATE_GJDOC and CREATE_GJDOC_PARSER are on. 2008-10-02 Andrew John Hughes <gnu_andrew@member.fsf.org> * configure.ac: Add regen-gjdoc-parser option, and separate antlr tests. * m4/ac_prog_antlr.m4: Turn single test into AC_LIB_ANTLR and AC_PROG_ANTLR. * m4/ac_prog_java.m4: Quote tests. * tools/Makefile.am: Support CREATE_GJDOC_PARSER option. 2008-09-14 Andrew John Hughes <gnu_andrew@member.fsf.org> * examples/Makefile.am: Check lib directly as well as glibj.zip for boot classes. * m4/acinclude.m4: Only require the class files to be built to allow the tools and examples to be built, not the installation of glibj.zip. * tools/Makefile.am: Check lib directly as well as glibj.zip for boot classes. 2008-09-13 Andrew John Hughes <gnu_andrew@member.fsf.org> * examples/Makefile.am, * lib/Makefile.am: Add GCJ rules. * m4/ac_prog_javac.m4: Check whether JAVAC is gcj. * m4/ac_prog_javac_works.m4: Add GCJ rules. * m4/acinclude.m4: Don't bother checking for -J if using GCJ. * tools/Makefile.am: Add GCJ rules. 2007-08-23 Daniel Frampton <zyridium@zyridium.net> * AUTHORS: Added. * java/lang/InheritableThreadLocal.java, * java/lang/Thread.java, * java/lang/ThreadLocal.java: Modified to use java.lang.ThreadLocalMap. * java/lang/ThreadLocalMap.java: New cheaper ThreadLocal-specific WeakHashMap. 2008-02-07 Ian Rogers <ian.rogers@manchester.ac.uk> * java/util/zip/ZipEntry.java: Use byte fields instead of integer fields, store the time as well as the DOS time and don't retain a global Calendar instance. (setDOSTime(int)): Set KNOWN_DOSTIME instead of KNOWN_TIME, and unset KNOWN_TIME. (getDOSTime()): Compute DOS time from UNIX time only when needed. (clone()): Provide cloning via the ZipEntry constructor where possible. (setTime(long)): Don't compute DOS time at this point. (getCalendar()): Removed. 2008-09-09 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/gnu/classpath/tools/getopt/Parser.java: (setHeader(String)): Make synchronized. (setFooter(String)): Likewise. * tools/gnu/classpath/tools/rmic/SourceGiopRmicCompiler.java, (reset()): Make synchronized. (name(Class)): Likewise. 2008-09-04 Robert Schuster <robertschuster@fsfe.org> * gnu/java/nio/charset/ByteDecodeLoopHelper: (arrayDecodeLoop): Added new break label, escape to that label. * gnu/java/nio/charset/ByteEncodeLoopHelper: (arrayDecodeLoop): Added new break label, escape to that label. 2008-09-04 Robert Schuster <robertschuster@fsfe.org> * java/text/DecimalFormat.java: (scanFix): Use 'i + 1' when looking at following character. (scanNegativePattern): Dito. 2008-09-02 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/gnu/classpath/tools/javah/ClassWrapper.java: (makeVtable()): Populate methodNameMap. (printMethods(CniPrintStream)): Always use pre-populated methodNameMap for bridge targets. 2008-09-01 Mario Torre <neugens@aicas.com> * gnu/java/awt/peer/x/XImage.java (XImageProducer): remove @Override annotation to allow compilation on javac < 1.6 and ecj < 3.4. 2008-09-01 Mario Torre <neugens@aicas.com> * gnu/java/awt/peer/x/XGraphicsDevice.java (getDisplay): fix to support new Escher API. * gnu/java/awt/peer/x/XImage.java (getSource): method implemented. * gnu/java/awt/peer/x/XImage.java (XImageProducer): implement ImageProducer for getSource. 2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/java/util/regex/BacktrackStack.java, * gnu/java/util/regex/CharIndexed.java, * gnu/java/util/regex/CharIndexedCharArray.java, * gnu/java/util/regex/CharIndexedCharSequence.java, * gnu/java/util/regex/CharIndexedInputStream.java, * gnu/java/util/regex/CharIndexedString.java, * gnu/java/util/regex/CharIndexedStringBuffer.java, * gnu/java/util/regex/RE.java, * gnu/java/util/regex/REException.java, * gnu/java/util/regex/REFilterInputStream.java, * gnu/java/util/regex/REMatch.java, * gnu/java/util/regex/REMatchEnumeration.java, * gnu/java/util/regex/RESyntax.java, * gnu/java/util/regex/REToken.java, * gnu/java/util/regex/RETokenAny.java, * gnu/java/util/regex/RETokenBackRef.java, * gnu/java/util/regex/RETokenChar.java, * gnu/java/util/regex/RETokenEnd.java, * gnu/java/util/regex/RETokenEndOfPreviousMatch.java, * gnu/java/util/regex/RETokenEndSub.java, * gnu/java/util/regex/RETokenIndependent.java, * gnu/java/util/regex/RETokenLookAhead.java, * gnu/java/util/regex/RETokenLookBehind.java, * gnu/java/util/regex/RETokenNamedProperty.java, * gnu/java/util/regex/RETokenOneOf.java, * gnu/java/util/regex/RETokenPOSIX.java, * gnu/java/util/regex/RETokenRange.java, * gnu/java/util/regex/RETokenRepeated.java, * gnu/java/util/regex/RETokenStart.java, * gnu/java/util/regex/RETokenWordBoundary.java, * gnu/java/util/regex/UncheckedRE.java: Fix indentation. 2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/java/util/regex/RETokenStart.java: (getMaximumLength()): Add Override annotation. (matchThis(CharIndexed, REMatch)): Likewise. (returnsFixedLengthMatches()): Renamed from returnsFixedLengthmatches and added Override annotation. (findFixedLengthMatches(CharIndexed,REMatch,int)): Add Override annotation. (dump(CPStringBuilder)): Likewise. * gnu/javax/print/ipp/IppRequest.java: (RequestWriter.writeOperationAttributes(AttributeSet)): Throw exception, don't just create and drop it. * javax/management/MBeanServerPermission.java: (MBeanServerPermissionCollection.add(Permission)): Compare against individual Strings not the entire array, and store the result of replace. * javax/swing/text/html/StyleSheet.java: (setBaseFontSize(size)): Store result of trim(). 2008-09-01 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/tools/FileObject.java: (openReader(boolean)): Document new parameter. 2008-03-27 Michael Franz <mvfranz@gmail.com> PR classpath/35690: * javax/tools/FileObject.java: (toUri()): Fix case from toURI. (openReader(boolean)): Add missing boolean argument. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/35487: * gnu/javax/management/Server.java: (beans): Change to ConcurrentHashMap. (defaultDomain): Make final. (outer): Likewise. (LazyListenersHolder): Added to wrap listeners, also now a ConcurrentHashMap, providing lazy initialisation safely. (sequenceNumber): Documented. (getBean(ObjectName)): Remove redundant cast. (addNotificationListener(ObjectName,NotificationListener, NotificationFilter,Object)): Remove map initialisation and use holder. (getObjectInstance(ObjectName)): Remove redundant cast. (registerMBean(Object,ObjectName)): Add bean atomically. (removeNotificationListener(ObjectName,NotificationListener)): Simplified. (removeNotificationListener(ObjectName,NotificationListener, NotificationFilter,Object)): Likewise. (notify(ObjectName,String)): Documented. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/management/Server.java: Genericised. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/management/Translator.java: Genericised. 2008-08-26 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/management/DefaultLoaderRepository.java, * javax/management/JMX.java, * javax/management/MBeanAttributeInfo.java, * javax/management/MBeanConstructorInfo.java, * javax/management/MBeanOperationInfo.java, * javax/management/MBeanServerDelegate.java: Fix warnings due to generics. 2008-08-25 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/management/MBeanPermission.java, * javax/management/MBeanServerDelegate.java, * javax/management/MBeanServerFactory.java, * javax/management/MBeanServerInvocationHandler.java, * javax/management/MBeanServerPermission.java: Fix warnings due to use of non-generic collections. 2008-08-25 Mario Torre <neugens@aicas.com> * gnu/javax/rmi/CORBA/RmiUtilities.java (readValue): check if sender is null to avoid NPE. 2008-08-22 Mario Torre <neugens@aicas.com> * gnu/CORBA/OrbFunctional.java (set_parameters): Fix NullPointerException checking when param is null. 2008-08-23 Andrew John Hughes <gnu_andrew@member.fsf.org> * java/util/regex/Matcher.java: (reset()): Reset append position so we don't try and append to the end of the old input. 2008-08-22 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/32028: * m4/acinclude.m4: Also allow versions of GJDoc from 0.8* on, as CVS is 0.8.0-pre. 2008-08-21 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/32028: * m4/acinclude.m4: (CLASSPATH_WITH_GJDOC): Ensure version 0.7.9 is being used. 2008-08-20 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/Makefile.am: Add taglets subdirectory to list of excluded paths when GJDoc is not compiled. 2008-08-19 David P Grove <groved@us.ibm.com> * scripts/check_jni_methods.sh.in: Fix build issue on AIX by splitting generation of method list. 2008-08-18 Andrew John Hughes <gnu_andrew@member.fsf.org> * native/jni/gstreamer-peer/gst_native_pipeline.c: (get_free_space(int)): Use #else not #elif when there is no condition. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/31895: * java/text/DecimalFormat.java: (setCurrency(Currency)): Update prefixes and suffixes when currency changes. * java/text/DecimalFormatSymbols.java: (DecimalFormatSymbols(Locale)): Set locale earlier so it can be used by setCurrency(Currency). (setCurrency(Currency)): Set the symbol correctly using the locale of the instance. * java/util/Currency.java: Throw error instead of just printing a message. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * javax/activation/ActivationDataFlavor.java: Suppress warnings from public API. (mimeType): Made final. (representationClass): Added generic type and made final. (normalizeMimeTypeParameter(String,String)): Use CPStringBuilder. * javax/activation/CommandInfo.java: (verb): Made final. (className): Made final. * javax/activation/DataHandler.java: (dataSource): Made final. * javax/activation/FileDataSource.java: (file): Made final. * javax/activation/MailcapCommandMap.java: Use generics on collections and CPStringBuilder instead of StringBuffer. * javax/activation/MimeType.java: (toString()): Use CPStringBuilder. (getBaseType()): Likewise. * javax/activation/MimeTypeParameterList.java: Use generics on collections and CPStringBuilder instead of StringBuffer. * javax/activation/MimeTypeParseException.java: (MimeTypeParseException(String,String)): Use CPStringBuilder. * javax/activation/MimetypesFileTypeMap.java: Use generics on collections and CPStringBuilder instead of StringBuffer. * javax/activation/URLDataSource.java: (url): Made final. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/activation/viewers/ImageViewer.java, * gnu/javax/activation/viewers/TextEditor.java, * gnu/javax/activation/viewers/TextViewer.java, * javax/activation/ActivationDataFlavor.java, * javax/activation/CommandInfo.java, * javax/activation/CommandMap.java, * javax/activation/CommandObject.java, * javax/activation/DataContentHandler.java, * javax/activation/DataContentHandlerFactory.java, * javax/activation/DataHandler.java, * javax/activation/DataHandlerDataSource.java, * javax/activation/DataSource.java, * javax/activation/DataSourceDataContentHandler.java, * javax/activation/FileDataSource.java, * javax/activation/FileTypeMap.java, * javax/activation/MailcapCommandMap.java, * javax/activation/MimeType.java, * javax/activation/MimeTypeParameterList.java, * javax/activation/MimeTypeParseException.java, * javax/activation/MimetypesFileTypeMap.java, * javax/activation/ObjectDataContentHandler.java, * javax/activation/URLDataSource.java, * javax/activation/UnsupportedDataTypeException.java, * javax/activation/package.html, * resource/META-INF/mailcap.default, * resource/META-INF/mimetypes.default: Import GNU JAF CVS as of 17/08/2008. 2006-04-25 Archit Shah <ashah@redhat.com> * javax/activation/MimeTypeParameterList.java: Insert ';' separator before parameter list. 2005-06-29 Xavier Poinsard <xpoinsard@openpricer.com> * javax/activation/ObjectDataContentHandler.java: Fixed typo. 2005-05-28 Chris Burdess <dog@bluezoo.org> * javax/activation/CommandMap.java, * javax/activation/MailcapCommandMap.java: Updated to JAF 1.1. 2004-06-09 Chris Burdess <dog@bluezoo.org> * javax/activation/MailcapCommandMap.java: Fixed bug whereby x-java prefix was not attempted. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * AUTHORS: Added Laszlo. 2008-04-20 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/30436: * java/util/Scanner.java: Fix package to be java.util and correct indentation. 2007-07-25 Laszlo Andras Hernadi <e0327023@student.tuwien.ac.at> PR classpath/30436: * java/util/Scanner.java: Initial implementation. 2008-08-17 Andrew John Hughes <gnu_andrew@member.fsf.org> * java/util/regex/Matcher.java: (toMatchResult()): Implemented. 2008-08-13 Joshua Sumali <jsumali@redhat.com> * doc/Makefile.am (gjdoc.pod): Generate gjdoc pod from cp-tools.texinfo instead of invoke.texi. Remove invoke.texi from EXTRA_DIST. * doc/invoke.texi: Removed and merged into ... * doc/cp-tools.texinfo: Here 2008-08-12 Robert Schuster <robertschuster@fsfe.org> * native/jni/java-net/local.c (local_bind): Removed fprintf call, fixed access outside of array bounds. From-SVN: r141271
1458 lines
50 KiB
Java
1458 lines
50 KiB
Java
/* String.java -- immutable character sequences; the object of string literals
|
|
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
|
|
Free Software Foundation, Inc.
|
|
|
|
This file is part of GNU Classpath.
|
|
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
any later version.
|
|
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
02110-1301 USA.
|
|
|
|
Linking this library statically or dynamically with other modules is
|
|
making a combined work based on this library. Thus, the terms and
|
|
conditions of the GNU General Public License cover the whole
|
|
combination.
|
|
|
|
As a special exception, the copyright holders of this library give you
|
|
permission to link this library with independent modules to produce an
|
|
executable, regardless of the license terms of these independent
|
|
modules, and to copy and distribute the resulting executable under
|
|
terms of your choice, provided that you also meet, for each linked
|
|
independent module, the terms and conditions of the license of that
|
|
module. An independent module is a module which is not derived from
|
|
or based on this library. If you modify this library, you may extend
|
|
this exception to your version of the library, but you are not
|
|
obligated to do so. If you do not wish to do so, delete this
|
|
exception statement from your version. */
|
|
|
|
|
|
package java.lang;
|
|
|
|
import java.io.Serializable;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.util.Comparator;
|
|
import java.text.Collator;
|
|
import java.util.Formatter;
|
|
import java.util.Locale;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.PatternSyntaxException;
|
|
|
|
/**
|
|
* Strings represent an immutable set of characters. All String literals
|
|
* are instances of this class, and two string literals with the same contents
|
|
* refer to the same String object.
|
|
*
|
|
* <p>This class also includes a number of methods for manipulating the
|
|
* contents of strings (of course, creating a new object if there are any
|
|
* changes, as String is immutable). Case mapping relies on Unicode 3.0.0
|
|
* standards, where some character sequences have a different number of
|
|
* characters in the uppercase version than the lower case.
|
|
*
|
|
* <p>Strings are special, in that they are the only object with an overloaded
|
|
* operator. When you use '+' with at least one String argument, both
|
|
* arguments have String conversion performed on them, and another String (not
|
|
* guaranteed to be unique) results.
|
|
*
|
|
* <p>String is special-cased when doing data serialization - rather than
|
|
* listing the fields of this class, a String object is converted to a string
|
|
* literal in the object stream.
|
|
*
|
|
* @author Paul N. Fisher
|
|
* @author Eric Blake (ebb9@email.byu.edu)
|
|
* @author Per Bothner (bothner@cygnus.com)
|
|
* @author Tom Tromey (tromey@redhat.com)
|
|
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
|
* @since 1.0
|
|
* @status updated to 1.4
|
|
*/
|
|
public final class String
|
|
implements Serializable, Comparable<String>, CharSequence
|
|
{
|
|
// WARNING: String is a CORE class in the bootstrap cycle. See the comments
|
|
// in vm/reference/java/lang/Runtime for implications of this fact.
|
|
|
|
/**
|
|
* This is probably not necessary because this class is special cased already
|
|
* but it will avoid showing up as a discrepancy when comparing SUIDs.
|
|
*/
|
|
private static final long serialVersionUID = -6849794470754667710L;
|
|
|
|
/**
|
|
* This is the object that holds the characters that make up the
|
|
* String. It might be a char[], or it could be String. It could
|
|
* even be `this'. The actual characters can't be located using
|
|
* pure Java code.
|
|
* @see #boffset
|
|
*/
|
|
private Object data;
|
|
|
|
/**
|
|
* This is a <emph>byte</emph> offset of the actual characters from
|
|
* the start of the character-holding object. Don't use this field
|
|
* in Java code.
|
|
*/
|
|
private int boffset;
|
|
|
|
/**
|
|
* Holds the number of characters in value. Package visible for use
|
|
* by trusted code.
|
|
*/
|
|
int count;
|
|
|
|
/**
|
|
* Caches the result of hashCode(). If this value is zero, the hashcode
|
|
* is considered uncached (even if 0 is the correct hash value).
|
|
*/
|
|
private int cachedHashCode;
|
|
|
|
/**
|
|
* An implementation for {@link #CASE_INSENSITIVE_ORDER}.
|
|
* This must be {@link Serializable}. The class name is dictated by
|
|
* compatibility with Sun's JDK.
|
|
*/
|
|
private static final class CaseInsensitiveComparator
|
|
implements Comparator<String>, Serializable
|
|
{
|
|
/**
|
|
* Compatible with JDK 1.2.
|
|
*/
|
|
private static final long serialVersionUID = 8575799808933029326L;
|
|
|
|
/**
|
|
* The default private constructor generates unnecessary overhead.
|
|
*/
|
|
CaseInsensitiveComparator() {}
|
|
|
|
/**
|
|
* Compares to Strings, using
|
|
* <code>String.compareToIgnoreCase(String)</code>.
|
|
*
|
|
* @param o1 the first string
|
|
* @param o2 the second string
|
|
* @return < 0, 0, or > 0 depending on the case-insensitive
|
|
* comparison of the two strings.
|
|
* @throws NullPointerException if either argument is null
|
|
* @throws ClassCastException if either argument is not a String
|
|
* @see #compareToIgnoreCase(String)
|
|
*/
|
|
public int compare(String o1, String o2)
|
|
{
|
|
return o1.compareToIgnoreCase(o2);
|
|
}
|
|
} // class CaseInsensitiveComparator
|
|
|
|
/**
|
|
* A Comparator that uses <code>String.compareToIgnoreCase(String)</code>.
|
|
* This comparator is {@link Serializable}. Note that it ignores Locale,
|
|
* for that, you want a Collator.
|
|
*
|
|
* @see Collator#compare(String, String)
|
|
* @since 1.2
|
|
*/
|
|
public static final Comparator<String> CASE_INSENSITIVE_ORDER
|
|
= new CaseInsensitiveComparator();
|
|
|
|
/**
|
|
* Creates an empty String (length 0). Unless you really need a new object,
|
|
* consider using <code>""</code> instead.
|
|
*/
|
|
public String()
|
|
{
|
|
data = "".data;
|
|
boffset = 0;
|
|
count = 0;
|
|
}
|
|
|
|
/**
|
|
* Copies the contents of a String to a new String. Since Strings are
|
|
* immutable, only a shallow copy is performed.
|
|
*
|
|
* @param str String to copy
|
|
* @throws NullPointerException if value is null
|
|
*/
|
|
public String(String str)
|
|
{
|
|
data = str.data;
|
|
boffset = str.boffset;
|
|
count = str.count;
|
|
cachedHashCode = str.cachedHashCode;
|
|
}
|
|
|
|
/**
|
|
* Creates a new String using the character sequence of the char array.
|
|
* Subsequent changes to data do not affect the String.
|
|
*
|
|
* @param data char array to copy
|
|
* @throws NullPointerException if data is null
|
|
*/
|
|
public String(char[] data)
|
|
{
|
|
init(data, 0, data.length, false);
|
|
}
|
|
|
|
/**
|
|
* Creates a new String using the character sequence of a subarray of
|
|
* characters. The string starts at offset, and copies count chars.
|
|
* Subsequent changes to data do not affect the String.
|
|
*
|
|
* @param data char array to copy
|
|
* @param offset position (base 0) to start copying out of data
|
|
* @param count the number of characters from data to copy
|
|
* @throws NullPointerException if data is null
|
|
* @throws IndexOutOfBoundsException if (offset < 0 || count < 0
|
|
* || offset + count < 0 (overflow)
|
|
* || offset + count > data.length)
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
*/
|
|
public String(char[] data, int offset, int count)
|
|
{
|
|
init(data, offset, count, false);
|
|
}
|
|
|
|
/**
|
|
* Creates a new String using an 8-bit array of integer values, starting at
|
|
* an offset, and copying up to the count. Each character c, using
|
|
* corresponding byte b, is created in the new String as if by performing:
|
|
*
|
|
* <pre>
|
|
* c = (char) (((hibyte & 0xff) << 8) | (b & 0xff))
|
|
* </pre>
|
|
*
|
|
* @param ascii array of integer values
|
|
* @param hibyte top byte of each Unicode character
|
|
* @param offset position (base 0) to start copying out of ascii
|
|
* @param count the number of characters from ascii to copy
|
|
* @throws NullPointerException if ascii is null
|
|
* @throws IndexOutOfBoundsException if (offset < 0 || count < 0
|
|
* || offset + count < 0 (overflow)
|
|
* || offset + count > ascii.length)
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
* @see #String(byte[])
|
|
* @see #String(byte[], String)
|
|
* @see #String(byte[], int, int)
|
|
* @see #String(byte[], int, int, String)
|
|
* @deprecated use {@link #String(byte[], int, int, String)} to perform
|
|
* correct encoding
|
|
*/
|
|
public String(byte[] ascii, int hibyte, int offset, int count)
|
|
{
|
|
init(ascii, hibyte, offset, count);
|
|
}
|
|
|
|
/**
|
|
* Creates a new String using an 8-bit array of integer values. Each
|
|
* character c, using corresponding byte b, is created in the new String
|
|
* as if by performing:
|
|
*
|
|
* <pre>
|
|
* c = (char) (((hibyte & 0xff) << 8) | (b & 0xff))
|
|
* </pre>
|
|
*
|
|
* @param ascii array of integer values
|
|
* @param hibyte top byte of each Unicode character
|
|
* @throws NullPointerException if ascii is null
|
|
* @see #String(byte[])
|
|
* @see #String(byte[], String)
|
|
* @see #String(byte[], int, int)
|
|
* @see #String(byte[], int, int, String)
|
|
* @see #String(byte[], int, int, int)
|
|
* @deprecated use {@link #String(byte[], String)} to perform
|
|
* correct encoding
|
|
*/
|
|
public String(byte[] ascii, int hibyte)
|
|
{
|
|
init(ascii, hibyte, 0, ascii.length);
|
|
}
|
|
|
|
/**
|
|
* Creates a new String using the portion of the byte array starting at the
|
|
* offset and ending at offset + count. Uses the specified encoding type
|
|
* to decode the byte array, so the resulting string may be longer or
|
|
* shorter than the byte array. For more decoding control, use
|
|
* {@link java.nio.charset.CharsetDecoder}, and for valid character sets,
|
|
* see {@link java.nio.charset.Charset}. The behavior is not specified if
|
|
* the decoder encounters invalid characters; this implementation throws
|
|
* an Error.
|
|
*
|
|
* @param data byte array to copy
|
|
* @param offset the offset to start at
|
|
* @param count the number of bytes in the array to use
|
|
* @param encoding the name of the encoding to use
|
|
* @throws NullPointerException if data or encoding is null
|
|
* @throws IndexOutOfBoundsException if offset or count is incorrect
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
* @throws UnsupportedEncodingException if encoding is not found
|
|
* @throws Error if the decoding fails
|
|
* @since 1.1
|
|
*/
|
|
public String(byte[] data, int offset, int count, String encoding)
|
|
throws UnsupportedEncodingException
|
|
{
|
|
init (data, offset, count, encoding);
|
|
}
|
|
|
|
/**
|
|
* Creates a new String using the byte array. Uses the specified encoding
|
|
* type to decode the byte array, so the resulting string may be longer or
|
|
* shorter than the byte array. For more decoding control, use
|
|
* {@link java.nio.charset.CharsetDecoder}, and for valid character sets,
|
|
* see {@link java.nio.charset.Charset}. The behavior is not specified if
|
|
* the decoder encounters invalid characters; this implementation throws
|
|
* an Error.
|
|
*
|
|
* @param data byte array to copy
|
|
* @param encoding the name of the encoding to use
|
|
* @throws NullPointerException if data or encoding is null
|
|
* @throws UnsupportedEncodingException if encoding is not found
|
|
* @throws Error if the decoding fails
|
|
* @see #String(byte[], int, int, String)
|
|
* @since 1.1
|
|
*/
|
|
public String(byte[] data, String encoding)
|
|
throws UnsupportedEncodingException
|
|
{
|
|
this(data, 0, data.length, encoding);
|
|
}
|
|
|
|
/**
|
|
* Creates a new String using the portion of the byte array starting at the
|
|
* offset and ending at offset + count. Uses the encoding of the platform's
|
|
* default charset, so the resulting string may be longer or shorter than
|
|
* the byte array. For more decoding control, use
|
|
* {@link java.nio.charset.CharsetDecoder}. The behavior is not specified
|
|
* if the decoder encounters invalid characters; this implementation throws
|
|
* an Error.
|
|
*
|
|
* @param data byte array to copy
|
|
* @param offset the offset to start at
|
|
* @param count the number of bytes in the array to use
|
|
* @throws NullPointerException if data is null
|
|
* @throws IndexOutOfBoundsException if offset or count is incorrect
|
|
* @throws Error if the decoding fails
|
|
* @see #String(byte[], int, int, String)
|
|
* @since 1.1
|
|
*/
|
|
public String(byte[] data, int offset, int count)
|
|
{
|
|
try
|
|
{
|
|
init (data, offset, count,
|
|
System.getProperty("file.encoding", "8859_1"));
|
|
}
|
|
catch (UnsupportedEncodingException x1)
|
|
{
|
|
// Maybe the default encoding is bad.
|
|
try
|
|
{
|
|
init (data, offset, count, "8859_1");
|
|
}
|
|
catch (UnsupportedEncodingException x2)
|
|
{
|
|
// We know this can't happen.
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates a new String using the byte array. Uses the encoding of the
|
|
* platform's default charset, so the resulting string may be longer or
|
|
* shorter than the byte array. For more decoding control, use
|
|
* {@link java.nio.charset.CharsetDecoder}. The behavior is not specified
|
|
* if the decoder encounters invalid characters; this implementation throws
|
|
* an Error.
|
|
*
|
|
* @param data byte array to copy
|
|
* @throws NullPointerException if data is null
|
|
* @throws Error if the decoding fails
|
|
* @see #String(byte[], int, int)
|
|
* @see #String(byte[], int, int, String)
|
|
* @since 1.1
|
|
*/
|
|
public String(byte[] data)
|
|
{
|
|
this(data, 0, data.length);
|
|
}
|
|
|
|
/**
|
|
* Creates a new String using the character sequence represented by
|
|
* the StringBuffer. Subsequent changes to buf do not affect the String.
|
|
*
|
|
* @param buffer StringBuffer to copy
|
|
* @throws NullPointerException if buffer is null
|
|
*/
|
|
public String(StringBuffer buffer)
|
|
{
|
|
synchronized (buffer)
|
|
{
|
|
// Share unless buffer is 3/4 empty.
|
|
boolean should_copy = ((buffer.count << 2) < buffer.value.length);
|
|
if (! should_copy)
|
|
buffer.shared = true;
|
|
init (buffer.value, 0, buffer.count, ! should_copy);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates a new String using the character sequence represented by
|
|
* the StringBuilder. Subsequent changes to buf do not affect the String.
|
|
*
|
|
* @param buffer StringBuilder to copy
|
|
* @throws NullPointerException if buffer is null
|
|
*/
|
|
public String(StringBuilder buffer)
|
|
{
|
|
this(buffer.value, 0, buffer.count);
|
|
}
|
|
|
|
/**
|
|
* Special constructor which can share an array when safe to do so.
|
|
*
|
|
* @param data the characters to copy
|
|
* @param offset the location to start from
|
|
* @param count the number of characters to use
|
|
* @param dont_copy true if the array is trusted, and need not be copied
|
|
* @throws NullPointerException if chars is null
|
|
* @throws StringIndexOutOfBoundsException if bounds check fails
|
|
*/
|
|
String(char[] data, int offset, int count, boolean dont_copy)
|
|
{
|
|
init(data, offset, count, dont_copy);
|
|
}
|
|
|
|
// This is used by gnu.gcj.runtime.StringBuffer, so it must have
|
|
// package-private protection. It is accessed via CNI and so avoids
|
|
// ordinary protection mechanisms.
|
|
String(gnu.gcj.runtime.StringBuffer buffer)
|
|
{
|
|
// No need to synchronize or mark the buffer, since we know it is
|
|
// only used once.
|
|
init (buffer);
|
|
}
|
|
|
|
/**
|
|
* Returns the number of characters contained in this String.
|
|
*
|
|
* @return the length of this String
|
|
*/
|
|
public int length()
|
|
{
|
|
return count;
|
|
}
|
|
|
|
/**
|
|
* Returns the character located at the specified index within this String.
|
|
*
|
|
* @param index position of character to return (base 0)
|
|
* @return character located at position index
|
|
* @throws IndexOutOfBoundsException if index < 0 || index >= length()
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
*/
|
|
public native char charAt(int index);
|
|
|
|
/**
|
|
* Get the code point at the specified index. This is like #charAt(int),
|
|
* but if the character is the start of a surrogate pair, and the
|
|
* following character completes the pair, then the corresponding
|
|
* supplementary code point is returned.
|
|
* @param index the index of the codepoint to get, starting at 0
|
|
* @return the codepoint at the specified index
|
|
* @throws IndexOutOfBoundsException if index is negative or >= length()
|
|
* @since 1.5
|
|
*/
|
|
public synchronized int codePointAt(int index)
|
|
{
|
|
// Use the CharSequence overload as we get better range checking
|
|
// this way.
|
|
return Character.codePointAt(this, index);
|
|
}
|
|
|
|
/**
|
|
* Get the code point before the specified index. This is like
|
|
* #codePointAt(int), but checks the characters at <code>index-1</code> and
|
|
* <code>index-2</code> to see if they form a supplementary code point.
|
|
* @param index the index just past the codepoint to get, starting at 0
|
|
* @return the codepoint at the specified index
|
|
* @throws IndexOutOfBoundsException if index is negative or >= length()
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
* @since 1.5
|
|
*/
|
|
public synchronized int codePointBefore(int index)
|
|
{
|
|
// Use the CharSequence overload as we get better range checking
|
|
// this way.
|
|
return Character.codePointBefore(this, index);
|
|
}
|
|
|
|
/**
|
|
* Copies characters from this String starting at a specified start index,
|
|
* ending at a specified stop index, to a character array starting at
|
|
* a specified destination begin index.
|
|
*
|
|
* @param srcBegin index to begin copying characters from this String
|
|
* @param srcEnd index after the last character to be copied from this String
|
|
* @param dst character array which this String is copied into
|
|
* @param dstBegin index to start writing characters into dst
|
|
* @throws NullPointerException if dst is null
|
|
* @throws IndexOutOfBoundsException if any indices are out of bounds
|
|
* (while unspecified, source problems cause a
|
|
* StringIndexOutOfBoundsException, and dst problems cause an
|
|
* ArrayIndexOutOfBoundsException)
|
|
*/
|
|
public native void getChars(int srcBegin, int srcEnd,
|
|
char[] dst, int dstBegin);
|
|
|
|
/**
|
|
* Copies the low byte of each character from this String starting at a
|
|
* specified start index, ending at a specified stop index, to a byte array
|
|
* starting at a specified destination begin index.
|
|
*
|
|
* @param srcBegin index to being copying characters from this String
|
|
* @param srcEnd index after the last character to be copied from this String
|
|
* @param dst byte array which each low byte of this String is copied into
|
|
* @param dstBegin index to start writing characters into dst
|
|
* @throws NullPointerException if dst is null and copy length is non-zero
|
|
* @throws IndexOutOfBoundsException if any indices are out of bounds
|
|
* (while unspecified, source problems cause a
|
|
* StringIndexOutOfBoundsException, and dst problems cause an
|
|
* ArrayIndexOutOfBoundsException)
|
|
* @see #getBytes()
|
|
* @see #getBytes(String)
|
|
* @deprecated use {@link #getBytes()}, which uses a char to byte encoder
|
|
*/
|
|
public native void getBytes(int srcBegin, int srcEnd,
|
|
byte[] dst, int dstBegin);
|
|
|
|
/**
|
|
* Converts the Unicode characters in this String to a byte array. Uses the
|
|
* specified encoding method, so the result may be longer or shorter than
|
|
* the String. For more encoding control, use
|
|
* {@link java.nio.charset.CharsetEncoder}, and for valid character sets,
|
|
* see {@link java.nio.charset.Charset}. The behavior is not specified if
|
|
* the encoder encounters a problem; this implementation returns null.
|
|
*
|
|
* @param enc encoding name
|
|
* @return the resulting byte array, or null on a problem
|
|
* @throws NullPointerException if enc is null
|
|
* @throws UnsupportedEncodingException if encoding is not supported
|
|
* @since 1.1
|
|
*/
|
|
public native byte[] getBytes(String enc)
|
|
throws UnsupportedEncodingException;
|
|
|
|
/**
|
|
* Converts the Unicode characters in this String to a byte array. Uses the
|
|
* encoding of the platform's default charset, so the result may be longer
|
|
* or shorter than the String. For more encoding control, use
|
|
* {@link java.nio.charset.CharsetEncoder}. The behavior is not specified if
|
|
* the encoder encounters a problem; this implementation returns null.
|
|
*
|
|
* @return the resulting byte array, or null on a problem
|
|
* @since 1.1
|
|
*/
|
|
public byte[] getBytes()
|
|
{
|
|
try
|
|
{
|
|
return getBytes (System.getProperty("file.encoding", "8859_1"));
|
|
}
|
|
catch (UnsupportedEncodingException x)
|
|
{
|
|
// This probably shouldn't happen, but could if file.encoding
|
|
// is somehow changed to a value we don't understand.
|
|
try
|
|
{
|
|
return getBytes ("8859_1");
|
|
}
|
|
catch (UnsupportedEncodingException x2)
|
|
{
|
|
// This really shouldn't happen, because the 8859_1
|
|
// encoding should always be available.
|
|
throw new InternalError ("couldn't find 8859_1 encoder");
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Predicate which compares anObject to this. This is true only for Strings
|
|
* with the same character sequence.
|
|
*
|
|
* @param anObject the object to compare
|
|
* @return true if anObject is semantically equal to this
|
|
* @see #compareTo(String)
|
|
* @see #equalsIgnoreCase(String)
|
|
*/
|
|
public native boolean equals(Object anObject);
|
|
|
|
/**
|
|
* Compares the given StringBuffer to this String. This is true if the
|
|
* StringBuffer has the same content as this String at this moment.
|
|
*
|
|
* @param buffer the StringBuffer to compare to
|
|
* @return true if StringBuffer has the same character sequence
|
|
* @throws NullPointerException if the given StringBuffer is null
|
|
* @since 1.4
|
|
*/
|
|
public native boolean contentEquals(StringBuffer buffer);
|
|
|
|
/**
|
|
* Compares the given CharSequence to this String. This is true if
|
|
* the CharSequence has the same content as this String at this
|
|
* moment.
|
|
*
|
|
* @param seq the CharSequence to compare to
|
|
* @return true if CharSequence has the same character sequence
|
|
* @throws NullPointerException if the given CharSequence is null
|
|
* @since 1.5
|
|
*/
|
|
public native boolean contentEquals(CharSequence seq);
|
|
|
|
/**
|
|
* Compares a String to this String, ignoring case. This does not handle
|
|
* multi-character capitalization exceptions; instead the comparison is
|
|
* made on a character-by-character basis, and is true if:<br><ul>
|
|
* <li><code>c1 == c2</code></li>
|
|
* <li><code>Character.toUpperCase(c1)
|
|
* == Character.toUpperCase(c2)</code></li>
|
|
* <li><code>Character.toLowerCase(c1)
|
|
* == Character.toLowerCase(c2)</code></li>
|
|
* </ul>
|
|
*
|
|
* @param anotherString String to compare to this String
|
|
* @return true if anotherString is equal, ignoring case
|
|
* @see #equals(Object)
|
|
* @see Character#toUpperCase(char)
|
|
* @see Character#toLowerCase(char)
|
|
*/
|
|
public native boolean equalsIgnoreCase(String anotherString);
|
|
|
|
/**
|
|
* Compares this String and another String (case sensitive,
|
|
* lexicographically). The result is less than 0 if this string sorts
|
|
* before the other, 0 if they are equal, and greater than 0 otherwise.
|
|
* After any common starting sequence is skipped, the result is
|
|
* <code>this.charAt(k) - anotherString.charAt(k)</code> if both strings
|
|
* have characters remaining, or
|
|
* <code>this.length() - anotherString.length()</code> if one string is
|
|
* a subsequence of the other.
|
|
*
|
|
* @param anotherString the String to compare against
|
|
* @return the comparison
|
|
* @throws NullPointerException if anotherString is null
|
|
*/
|
|
public int compareTo(String anotherString)
|
|
{
|
|
return nativeCompareTo(anotherString);
|
|
}
|
|
|
|
/**
|
|
* The native implementation of compareTo(). Must be named different
|
|
* since cni doesn't understand the bridge method generated from
|
|
* the compareTo() method because of the Comparable<String> interface.
|
|
*/
|
|
private native int nativeCompareTo(String anotherString);
|
|
|
|
/**
|
|
* Compares this String and another String (case insensitive). This
|
|
* comparison is <em>similar</em> to equalsIgnoreCase, in that it ignores
|
|
* locale and multi-characater capitalization, and compares characters
|
|
* after performing
|
|
* <code>Character.toLowerCase(Character.toUpperCase(c))</code> on each
|
|
* character of the string. This is unsatisfactory for locale-based
|
|
* comparison, in which case you should use {@link java.text.Collator}.
|
|
*
|
|
* @param str the string to compare against
|
|
* @return the comparison
|
|
* @see Collator#compare(String, String)
|
|
* @since 1.2
|
|
*/
|
|
public int compareToIgnoreCase(String str)
|
|
{
|
|
return this.toUpperCase().toLowerCase().compareTo(
|
|
str.toUpperCase().toLowerCase());
|
|
}
|
|
|
|
/**
|
|
* Predicate which determines if this String matches another String
|
|
* starting at a specified offset for each String and continuing
|
|
* for a specified length. Indices out of bounds are harmless, and give
|
|
* a false result.
|
|
*
|
|
* @param toffset index to start comparison at for this String
|
|
* @param other String to compare region to this String
|
|
* @param ooffset index to start comparison at for other
|
|
* @param len number of characters to compare
|
|
* @return true if regions match (case sensitive)
|
|
* @throws NullPointerException if other is null
|
|
*/
|
|
public native boolean regionMatches(int toffset,
|
|
String other, int ooffset, int len);
|
|
|
|
/**
|
|
* Predicate which determines if this String matches another String
|
|
* starting at a specified offset for each String and continuing
|
|
* for a specified length, optionally ignoring case. Indices out of bounds
|
|
* are harmless, and give a false result. Case comparisons are based on
|
|
* <code>Character.toLowerCase()</code> and
|
|
* <code>Character.toUpperCase()</code>, not on multi-character
|
|
* capitalization expansions.
|
|
*
|
|
* @param ignoreCase true if case should be ignored in comparision
|
|
* @param toffset index to start comparison at for this String
|
|
* @param other String to compare region to this String
|
|
* @param ooffset index to start comparison at for other
|
|
* @param len number of characters to compare
|
|
* @return true if regions match, false otherwise
|
|
* @throws NullPointerException if other is null
|
|
*/
|
|
public native boolean regionMatches(boolean ignoreCase, int toffset,
|
|
String other, int ooffset, int len);
|
|
|
|
/**
|
|
* Predicate which determines if this String contains the given prefix,
|
|
* beginning comparison at toffset. The result is false if toffset is
|
|
* negative or greater than this.length(), otherwise it is the same as
|
|
* <code>this.substring(toffset).startsWith(prefix)</code>.
|
|
*
|
|
* @param prefix String to compare
|
|
* @param toffset offset for this String where comparison starts
|
|
* @return true if this String starts with prefix
|
|
* @throws NullPointerException if prefix is null
|
|
* @see #regionMatches(boolean, int, String, int, int)
|
|
*/
|
|
public native boolean startsWith(String prefix, int toffset);
|
|
|
|
/**
|
|
* Predicate which determines if this String starts with a given prefix.
|
|
* If the prefix is an empty String, true is returned.
|
|
*
|
|
* @param prefix String to compare
|
|
* @return true if this String starts with the prefix
|
|
* @throws NullPointerException if prefix is null
|
|
* @see #startsWith(String, int)
|
|
*/
|
|
public boolean startsWith(String prefix)
|
|
{
|
|
return startsWith (prefix, 0);
|
|
}
|
|
|
|
/**
|
|
* Predicate which determines if this String ends with a given suffix.
|
|
* If the suffix is an empty String, true is returned.
|
|
*
|
|
* @param suffix String to compare
|
|
* @return true if this String ends with the suffix
|
|
* @throws NullPointerException if suffix is null
|
|
* @see #regionMatches(boolean, int, String, int, int)
|
|
*/
|
|
public boolean endsWith(String suffix)
|
|
{
|
|
return regionMatches (this.count - suffix.count, suffix, 0, suffix.count);
|
|
}
|
|
|
|
/**
|
|
* Computes the hashcode for this String. This is done with int arithmetic,
|
|
* where ** represents exponentiation, by this formula:<br>
|
|
* <code>s[0]*31**(n-1) + s[1]*31**(n-2) + ... + s[n-1]</code>.
|
|
*
|
|
* @return hashcode value of this String
|
|
*/
|
|
public native int hashCode();
|
|
|
|
/**
|
|
* Finds the first instance of a character in this String.
|
|
*
|
|
* @param ch character to find
|
|
* @return location (base 0) of the character, or -1 if not found
|
|
*/
|
|
public int indexOf(int ch)
|
|
{
|
|
return indexOf(ch, 0);
|
|
}
|
|
|
|
/**
|
|
* Finds the first instance of a character in this String, starting at
|
|
* a given index. If starting index is less than 0, the search
|
|
* starts at the beginning of this String. If the starting index
|
|
* is greater than the length of this String, -1 is returned.
|
|
*
|
|
* @param ch character to find
|
|
* @param fromIndex index to start the search
|
|
* @return location (base 0) of the character, or -1 if not found
|
|
*/
|
|
public native int indexOf(int ch, int fromIndex);
|
|
|
|
/**
|
|
* Finds the last instance of a character in this String.
|
|
*
|
|
* @param ch character to find
|
|
* @return location (base 0) of the character, or -1 if not found
|
|
*/
|
|
public int lastIndexOf(int ch)
|
|
{
|
|
return lastIndexOf(ch, count - 1);
|
|
}
|
|
|
|
/**
|
|
* Finds the last instance of a character in this String, starting at
|
|
* a given index. If starting index is greater than the maximum valid
|
|
* index, then the search begins at the end of this String. If the
|
|
* starting index is less than zero, -1 is returned.
|
|
*
|
|
* @param ch character to find
|
|
* @param fromIndex index to start the search
|
|
* @return location (base 0) of the character, or -1 if not found
|
|
*/
|
|
public native int lastIndexOf(int ch, int fromIndex);
|
|
|
|
/**
|
|
* Finds the first instance of a String in this String.
|
|
*
|
|
* @param str String to find
|
|
* @return location (base 0) of the String, or -1 if not found
|
|
* @throws NullPointerException if str is null
|
|
*/
|
|
public int indexOf(String str)
|
|
{
|
|
return indexOf(str, 0);
|
|
}
|
|
|
|
/**
|
|
* Finds the first instance of a String in this String, starting at
|
|
* a given index. If starting index is less than 0, the search
|
|
* starts at the beginning of this String. If the starting index
|
|
* is greater than the length of this String, -1 is returned.
|
|
*
|
|
* @param str String to find
|
|
* @param fromIndex index to start the search
|
|
* @return location (base 0) of the String, or -1 if not found
|
|
* @throws NullPointerException if str is null
|
|
*/
|
|
public native int indexOf(String str, int fromIndex);
|
|
|
|
/**
|
|
* Finds the last instance of a String in this String.
|
|
*
|
|
* @param str String to find
|
|
* @return location (base 0) of the String, or -1 if not found
|
|
* @throws NullPointerException if str is null
|
|
*/
|
|
public int lastIndexOf(String str)
|
|
{
|
|
return lastIndexOf(str, count - str.count);
|
|
}
|
|
|
|
/**
|
|
* Finds the last instance of a String in this String, starting at
|
|
* a given index. If starting index is greater than the maximum valid
|
|
* index, then the search begins at the end of this String. If the
|
|
* starting index is less than zero, -1 is returned.
|
|
*
|
|
* @param str String to find
|
|
* @param fromIndex index to start the search
|
|
* @return location (base 0) of the String, or -1 if not found
|
|
* @throws NullPointerException if str is null
|
|
*/
|
|
public int lastIndexOf(String str, int fromIndex)
|
|
{
|
|
if (fromIndex >= count)
|
|
fromIndex = count - str.count;
|
|
for (;; --fromIndex)
|
|
{
|
|
if (fromIndex < 0)
|
|
return -1;
|
|
if (startsWith(str, fromIndex))
|
|
return fromIndex;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates a substring of this String, starting at a specified index
|
|
* and ending at the end of this String.
|
|
*
|
|
* @param begin index to start substring (base 0)
|
|
* @return new String which is a substring of this String
|
|
* @throws IndexOutOfBoundsException if begin < 0 || begin > length()
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
*/
|
|
public String substring(int begin)
|
|
{
|
|
return substring(begin, count);
|
|
}
|
|
|
|
/**
|
|
* Creates a substring of this String, starting at a specified index
|
|
* and ending at one character before a specified index.
|
|
*
|
|
* @param begin index to start substring (inclusive, base 0)
|
|
* @param end index to end at (exclusive)
|
|
* @return new String which is a substring of this String
|
|
* @throws IndexOutOfBoundsException if begin < 0 || end > length()
|
|
* || begin > end (while unspecified, this is a
|
|
* StringIndexOutOfBoundsException)
|
|
*/
|
|
public native String substring(int begin, int end);
|
|
|
|
/**
|
|
* Creates a substring of this String, starting at a specified index
|
|
* and ending at one character before a specified index. This behaves like
|
|
* <code>substring(begin, end)</code>.
|
|
*
|
|
* @param begin index to start substring (inclusive, base 0)
|
|
* @param end index to end at (exclusive)
|
|
* @return new String which is a substring of this String
|
|
* @throws IndexOutOfBoundsException if begin < 0 || end > length()
|
|
* || begin > end
|
|
* @since 1.4
|
|
*/
|
|
public CharSequence subSequence(int begin, int end)
|
|
{
|
|
return substring(begin, end);
|
|
}
|
|
|
|
/**
|
|
* Concatenates a String to this String. This results in a new string unless
|
|
* one of the two originals is "".
|
|
*
|
|
* @param str String to append to this String
|
|
* @return newly concatenated String
|
|
* @throws NullPointerException if str is null
|
|
*/
|
|
public native String concat(String str);
|
|
|
|
/**
|
|
* Replaces every instance of a character in this String with a new
|
|
* character. If no replacements occur, this is returned.
|
|
*
|
|
* @param oldChar the old character to replace
|
|
* @param newChar the new character
|
|
* @return new String with all instances of oldChar replaced with newChar
|
|
*/
|
|
public native String replace(char oldChar, char newChar);
|
|
|
|
/**
|
|
* Test if this String matches a regular expression. This is shorthand for
|
|
* <code>{@link Pattern}.matches(regex, this)</code>.
|
|
*
|
|
* @param regex the pattern to match
|
|
* @return true if the pattern matches
|
|
* @throws NullPointerException if regex is null
|
|
* @throws PatternSyntaxException if regex is invalid
|
|
* @see Pattern#matches(String, CharSequence)
|
|
* @since 1.4
|
|
*/
|
|
public boolean matches(String regex)
|
|
{
|
|
return Pattern.matches(regex, this);
|
|
}
|
|
|
|
/**
|
|
* Replaces the first substring match of the regular expression with a
|
|
* given replacement. This is shorthand for <code>{@link Pattern}
|
|
* .compile(regex).matcher(this).replaceFirst(replacement)</code>.
|
|
*
|
|
* @param regex the pattern to match
|
|
* @param replacement the replacement string
|
|
* @return the modified string
|
|
* @throws NullPointerException if regex or replacement is null
|
|
* @throws PatternSyntaxException if regex is invalid
|
|
* @see #replaceAll(String, String)
|
|
* @see Pattern#compile(String)
|
|
* @see Pattern#matcher(CharSequence)
|
|
* @see Matcher#replaceFirst(String)
|
|
* @since 1.4
|
|
*/
|
|
public String replaceFirst(String regex, String replacement)
|
|
{
|
|
return Pattern.compile(regex).matcher(this).replaceFirst(replacement);
|
|
}
|
|
|
|
/**
|
|
* Replaces all matching substrings of the regular expression with a
|
|
* given replacement. This is shorthand for <code>{@link Pattern}
|
|
* .compile(regex).matcher(this).replaceAll(replacement)</code>.
|
|
*
|
|
* @param regex the pattern to match
|
|
* @param replacement the replacement string
|
|
* @return the modified string
|
|
* @throws NullPointerException if regex or replacement is null
|
|
* @throws PatternSyntaxException if regex is invalid
|
|
* @see #replaceFirst(String, String)
|
|
* @see Pattern#compile(String)
|
|
* @see Pattern#matcher(CharSequence)
|
|
* @see Matcher#replaceAll(String)
|
|
* @since 1.4
|
|
*/
|
|
public String replaceAll(String regex, String replacement)
|
|
{
|
|
return Pattern.compile(regex).matcher(this).replaceAll(replacement);
|
|
}
|
|
|
|
/**
|
|
* Split this string around the matches of a regular expression. Each
|
|
* element of the returned array is the largest block of characters not
|
|
* terminated by the regular expression, in the order the matches are found.
|
|
*
|
|
* <p>The limit affects the length of the array. If it is positive, the
|
|
* array will contain at most n elements (n - 1 pattern matches). If
|
|
* negative, the array length is unlimited, but there can be trailing empty
|
|
* entries. if 0, the array length is unlimited, and trailing empty entries
|
|
* are discarded.
|
|
*
|
|
* <p>For example, splitting "boo:and:foo" yields:<br>
|
|
* <table border=0>
|
|
* <th><td>Regex</td> <td>Limit</td> <td>Result</td></th>
|
|
* <tr><td>":"</td> <td>2</td> <td>{ "boo", "and:foo" }</td></tr>
|
|
* <tr><td>":"</td> <td>t</td> <td>{ "boo", "and", "foo" }</td></tr>
|
|
* <tr><td>":"</td> <td>-2</td> <td>{ "boo", "and", "foo" }</td></tr>
|
|
* <tr><td>"o"</td> <td>5</td> <td>{ "b", "", ":and:f", "", "" }</td></tr>
|
|
* <tr><td>"o"</td> <td>-2</td> <td>{ "b", "", ":and:f", "", "" }</td></tr>
|
|
* <tr><td>"o"</td> <td>0</td> <td>{ "b", "", ":and:f" }</td></tr>
|
|
* </table>
|
|
*
|
|
* <p>This is shorthand for
|
|
* <code>{@link Pattern}.compile(regex).split(this, limit)</code>.
|
|
*
|
|
* @param regex the pattern to match
|
|
* @param limit the limit threshold
|
|
* @return the array of split strings
|
|
* @throws NullPointerException if regex or replacement is null
|
|
* @throws PatternSyntaxException if regex is invalid
|
|
* @see Pattern#compile(String)
|
|
* @see Pattern#split(CharSequence, int)
|
|
* @since 1.4
|
|
*/
|
|
public String[] split(String regex, int limit)
|
|
{
|
|
return Pattern.compile(regex).split(this, limit);
|
|
}
|
|
|
|
/**
|
|
* Split this string around the matches of a regular expression. Each
|
|
* element of the returned array is the largest block of characters not
|
|
* terminated by the regular expression, in the order the matches are found.
|
|
* The array length is unlimited, and trailing empty entries are discarded,
|
|
* as though calling <code>split(regex, 0)</code>.
|
|
*
|
|
* @param regex the pattern to match
|
|
* @return the array of split strings
|
|
* @throws NullPointerException if regex or replacement is null
|
|
* @throws PatternSyntaxException if regex is invalid
|
|
* @see #split(String, int)
|
|
* @see Pattern#compile(String)
|
|
* @see Pattern#split(CharSequence, int)
|
|
* @since 1.4
|
|
*/
|
|
public String[] split(String regex)
|
|
{
|
|
return Pattern.compile(regex).split(this, 0);
|
|
}
|
|
|
|
/**
|
|
* Lowercases this String according to a particular locale. This uses
|
|
* Unicode's special case mappings, as applied to the given Locale, so the
|
|
* resulting string may be a different length.
|
|
*
|
|
* @param loc locale to use
|
|
* @return new lowercased String, or this if no characters were lowercased
|
|
* @throws NullPointerException if loc is null
|
|
* @see #toUpperCase(Locale)
|
|
* @since 1.1
|
|
*/
|
|
public native String toLowerCase(Locale locale);
|
|
|
|
/**
|
|
* Lowercases this String. This uses Unicode's special case mappings, as
|
|
* applied to the platform's default Locale, so the resulting string may
|
|
* be a different length.
|
|
*
|
|
* @return new lowercased String, or this if no characters were lowercased
|
|
* @see #toLowerCase(Locale)
|
|
* @see #toUpperCase()
|
|
*/
|
|
public String toLowerCase()
|
|
{
|
|
// The JDK is a bit confused about what to do here. If we pass in
|
|
// the default Locale then special Locale handling might be
|
|
// invoked. However, the docs also say that Character.toLowerCase
|
|
// rules here. We go with the latter.
|
|
return toLowerCase (null);
|
|
}
|
|
|
|
/**
|
|
* Uppercases this String according to a particular locale. This uses
|
|
* Unicode's special case mappings, as applied to the given Locale, so the
|
|
* resulting string may be a different length.
|
|
*
|
|
* @param loc locale to use
|
|
* @return new uppercased String, or this if no characters were uppercased
|
|
* @throws NullPointerException if loc is null
|
|
* @see #toLowerCase(Locale)
|
|
* @since 1.1
|
|
*/
|
|
public native String toUpperCase(Locale locale);
|
|
|
|
/**
|
|
* Uppercases this String. This uses Unicode's special case mappings, as
|
|
* applied to the platform's default Locale, so the resulting string may
|
|
* be a different length.
|
|
*
|
|
* @return new uppercased String, or this if no characters were uppercased
|
|
* @see #toUpperCase(Locale)
|
|
* @see #toLowerCase()
|
|
*/
|
|
public String toUpperCase()
|
|
{
|
|
// The JDK is a bit confused about what to do here. If we pass in
|
|
// the default Locale then special Locale handling might be
|
|
// invoked. However, the docs also say that Character.toLowerCase
|
|
// rules here. We go with the latter.
|
|
return toUpperCase (null);
|
|
}
|
|
|
|
/**
|
|
* Trims all characters less than or equal to <code>'\u0020'</code>
|
|
* (<code>' '</code>) from the beginning and end of this String. This
|
|
* includes many, but not all, ASCII control characters, and all
|
|
* {@link Character#isWhitespace(char)}.
|
|
*
|
|
* @return new trimmed String, or this if nothing trimmed
|
|
*/
|
|
public native String trim();
|
|
|
|
/**
|
|
* Returns this, as it is already a String!
|
|
*
|
|
* @return this
|
|
*/
|
|
public String toString()
|
|
{
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Copies the contents of this String into a character array. Subsequent
|
|
* changes to the array do not affect the String.
|
|
*
|
|
* @return character array copying the String
|
|
*/
|
|
public native char[] toCharArray();
|
|
|
|
/**
|
|
* Returns a String representation of an Object. This is "null" if the
|
|
* object is null, otherwise it is <code>obj.toString()</code> (which
|
|
* can be null).
|
|
*
|
|
* @param obj the Object
|
|
* @return the string conversion of obj
|
|
*/
|
|
public static String valueOf(Object obj)
|
|
{
|
|
return obj == null ? "null" : obj.toString();
|
|
}
|
|
|
|
/**
|
|
* Returns a String representation of a character array. Subsequent
|
|
* changes to the array do not affect the String.
|
|
*
|
|
* @param data the character array
|
|
* @return a String containing the same character sequence as data
|
|
* @throws NullPointerException if data is null
|
|
* @see #valueOf(char[], int, int)
|
|
* @see #String(char[])
|
|
*/
|
|
public static String valueOf(char[] data)
|
|
{
|
|
return valueOf (data, 0, data.length);
|
|
}
|
|
|
|
/**
|
|
* Returns a String representing the character sequence of the char array,
|
|
* starting at the specified offset, and copying chars up to the specified
|
|
* count. Subsequent changes to the array do not affect the String.
|
|
*
|
|
* @param data character array
|
|
* @param offset position (base 0) to start copying out of data
|
|
* @param count the number of characters from data to copy
|
|
* @return String containing the chars from data[offset..offset+count]
|
|
* @throws NullPointerException if data is null
|
|
* @throws IndexOutOfBoundsException if (offset < 0 || count < 0
|
|
* || offset + count > data.length)
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
* @see #String(char[], int, int)
|
|
*/
|
|
public static native String valueOf(char[] data, int offset, int count);
|
|
|
|
/**
|
|
* Returns a String representing the character sequence of the char array,
|
|
* starting at the specified offset, and copying chars up to the specified
|
|
* count. Subsequent changes to the array do not affect the String.
|
|
*
|
|
* @param data character array
|
|
* @param offset position (base 0) to start copying out of data
|
|
* @param count the number of characters from data to copy
|
|
* @return String containing the chars from data[offset..offset+count]
|
|
* @throws NullPointerException if data is null
|
|
* @throws IndexOutOfBoundsException if (offset < 0 || count < 0
|
|
* || offset + count < 0 (overflow)
|
|
* || offset + count > data.length)
|
|
* (while unspecified, this is a StringIndexOutOfBoundsException)
|
|
* @see #String(char[], int, int)
|
|
*/
|
|
public static String copyValueOf(char[] data, int offset, int count)
|
|
{
|
|
String r = new String ();
|
|
r.init(data, offset, count, false);
|
|
return r;
|
|
}
|
|
|
|
/**
|
|
* Returns a String representation of a character array. Subsequent
|
|
* changes to the array do not affect the String.
|
|
*
|
|
* @param data the character array
|
|
* @return a String containing the same character sequence as data
|
|
* @throws NullPointerException if data is null
|
|
* @see #copyValueOf(char[], int, int)
|
|
* @see #String(char[])
|
|
*/
|
|
public static String copyValueOf(char[] data)
|
|
{
|
|
return copyValueOf (data, 0, data.length);
|
|
}
|
|
|
|
/**
|
|
* Returns a String representing a boolean.
|
|
*
|
|
* @param b the boolean
|
|
* @return "true" if b is true, else "false"
|
|
*/
|
|
public static String valueOf(boolean b)
|
|
{
|
|
return b ? "true" : "false";
|
|
}
|
|
|
|
/**
|
|
* Returns a String representing a character.
|
|
*
|
|
* @param c the character
|
|
* @return String containing the single character c
|
|
*/
|
|
public static native String valueOf(char c);
|
|
|
|
/**
|
|
* Returns a String representing an integer.
|
|
*
|
|
* @param i the integer
|
|
* @return String containing the integer in base 10
|
|
* @see Integer#toString(int)
|
|
*/
|
|
public static native String valueOf(int i);
|
|
|
|
/**
|
|
* Returns a String representing a long.
|
|
*
|
|
* @param l the long
|
|
* @return String containing the long in base 10
|
|
* @see Long#toString(long)
|
|
*/
|
|
public static String valueOf(long l)
|
|
{
|
|
return Long.toString(l);
|
|
}
|
|
|
|
/**
|
|
* Returns a String representing a float.
|
|
*
|
|
* @param f the float
|
|
* @return String containing the float
|
|
* @see Float#toString(float)
|
|
*/
|
|
public static String valueOf(float f)
|
|
{
|
|
return Float.toString(f);
|
|
}
|
|
|
|
/**
|
|
* Returns a String representing a double.
|
|
*
|
|
* @param d the double
|
|
* @return String containing the double
|
|
* @see Double#toString(double)
|
|
*/
|
|
public static String valueOf(double d)
|
|
{
|
|
return Double.toString(d);
|
|
}
|
|
|
|
|
|
/** @since 1.5 */
|
|
public static String format(Locale locale, String format, Object... args)
|
|
{
|
|
Formatter f = new Formatter(locale);
|
|
return f.format(format, args).toString();
|
|
}
|
|
|
|
/** @since 1.5 */
|
|
public static String format(String format, Object... args)
|
|
{
|
|
return format(Locale.getDefault(), format, args);
|
|
}
|
|
|
|
/**
|
|
* Fetches this String from the intern hashtable.
|
|
* If two Strings are considered equal, by the equals() method,
|
|
* then intern() will return the same String instance. ie.
|
|
* if (s1.equals(s2)) then (s1.intern() == s2.intern()).
|
|
* All string literals and string-valued constant expressions
|
|
* are already interned.
|
|
*
|
|
* @return the interned String
|
|
*/
|
|
public native String intern();
|
|
|
|
/**
|
|
* Return the number of code points between two indices in the
|
|
* <code>String</code>. An unpaired surrogate counts as a
|
|
* code point for this purpose. Characters outside the indicated
|
|
* range are not examined, even if the range ends in the middle of a
|
|
* surrogate pair.
|
|
*
|
|
* @param start the starting index
|
|
* @param end one past the ending index
|
|
* @return the number of code points
|
|
* @since 1.5
|
|
*/
|
|
public synchronized int codePointCount(int start, int end)
|
|
{
|
|
if (start < 0 || end > count || start > end)
|
|
throw new StringIndexOutOfBoundsException();
|
|
|
|
int count = 0;
|
|
while (start < end)
|
|
{
|
|
char base = charAt(start);
|
|
if (base < Character.MIN_HIGH_SURROGATE
|
|
|| base > Character.MAX_HIGH_SURROGATE
|
|
|| start == end
|
|
|| start == count
|
|
|| charAt(start + 1) < Character.MIN_LOW_SURROGATE
|
|
|| charAt(start + 1) > Character.MAX_LOW_SURROGATE)
|
|
{
|
|
// Nothing.
|
|
}
|
|
else
|
|
{
|
|
// Surrogate pair.
|
|
++start;
|
|
}
|
|
++start;
|
|
++count;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
/**
|
|
* Returns true iff this String contains the sequence of Characters
|
|
* described in s.
|
|
* @param s the CharSequence
|
|
* @return true iff this String contains s
|
|
*
|
|
* @since 1.5
|
|
*/
|
|
public boolean contains (CharSequence s)
|
|
{
|
|
return this.indexOf(s.toString()) != -1;
|
|
}
|
|
|
|
/**
|
|
* Returns a string that is this string with all instances of the sequence
|
|
* represented by <code>target</code> replaced by the sequence in
|
|
* <code>replacement</code>.
|
|
* @param target the sequence to be replaced
|
|
* @param replacement the sequence used as the replacement
|
|
* @return the string constructed as above
|
|
*/
|
|
public String replace (CharSequence target, CharSequence replacement)
|
|
{
|
|
String targetString = target.toString();
|
|
String replaceString = replacement.toString();
|
|
int targetLength = target.length();
|
|
int replaceLength = replacement.length();
|
|
|
|
int startPos = this.indexOf(targetString);
|
|
StringBuilder result = new StringBuilder(this);
|
|
while (startPos != -1)
|
|
{
|
|
// Replace the target with the replacement
|
|
result.replace(startPos, startPos + targetLength, replaceString);
|
|
|
|
// Search for a new occurrence of the target
|
|
startPos = result.indexOf(targetString, startPos + replaceLength);
|
|
}
|
|
return result.toString();
|
|
}
|
|
|
|
/**
|
|
* Return the index into this String that is offset from the given index by
|
|
* <code>codePointOffset</code> code points.
|
|
* @param index the index at which to start
|
|
* @param codePointOffset the number of code points to offset
|
|
* @return the index into this String that is <code>codePointOffset</code>
|
|
* code points offset from <code>index</code>.
|
|
*
|
|
* @throws IndexOutOfBoundsException if index is negative or larger than the
|
|
* length of this string.
|
|
* @throws IndexOutOfBoundsException if codePointOffset is positive and the
|
|
* substring starting with index has fewer than codePointOffset code points.
|
|
* @throws IndexOutOfBoundsException if codePointOffset is negative and the
|
|
* substring ending with index has fewer than (-codePointOffset) code points.
|
|
* @since 1.5
|
|
*/
|
|
public int offsetByCodePoints(int index, int codePointOffset)
|
|
{
|
|
if (index < 0 || index > count)
|
|
throw new IndexOutOfBoundsException();
|
|
|
|
return Character.offsetByCodePoints(this, index, codePointOffset);
|
|
}
|
|
|
|
/**
|
|
* Returns true if, and only if, {@link #length()}
|
|
* is <code>0</code>.
|
|
*
|
|
* @return true if the length of the string is zero.
|
|
* @since 1.6
|
|
*/
|
|
public boolean isEmpty()
|
|
{
|
|
return count == 0;
|
|
}
|
|
|
|
// Generate a String that shares the value array: subsequent changes
|
|
// to this array will affect the String. A private internal method
|
|
// that is called from CPStringBuilder by compiler-generated code.
|
|
private static String toString(char[] value, int startIndex, int count)
|
|
{
|
|
return new String(value, startIndex, count, true);
|
|
}
|
|
|
|
private native void init(char[] chars, int offset, int count,
|
|
boolean dont_copy);
|
|
private native void init(byte[] chars, int hibyte, int offset, int count);
|
|
private native void init(byte[] chars, int offset, int count, String enc)
|
|
throws UnsupportedEncodingException;
|
|
private native void init(gnu.gcj.runtime.StringBuffer buffer);
|
|
}
|