Package com.dd.plist
Class NSString
- java.lang.Object
-
- com.dd.plist.NSObject
-
- com.dd.plist.NSString
-
- All Implemented Interfaces:
java.lang.Cloneable,java.lang.Comparable<NSObject>
public class NSString extends NSObject
The NSString class is a wrapper for a string.- See Also:
- Foundation NSString documentation
-
-
Field Summary
Fields Modifier and Type Field Description private static java.nio.charset.CharsetEncoderasciiEncoderprivate java.lang.Stringcontentprivate static java.nio.charset.CharsetEncoderutf16beEncoderprivate static java.nio.charset.CharsetEncoderutf8Encoder-
Fields inherited from class com.dd.plist.NSObject
ASCII_LINE_LENGTH, NEWLINE
-
-
Constructor Summary
Constructors Constructor Description NSString(byte[] bytes, int startIndex, int endIndex, java.lang.String encoding)Creates a new NSString instance from its binary representation.NSString(byte[] bytes, java.lang.String encoding)Creates a new NSString instance from its binary representation.NSString(java.lang.String string)Creates a new NSString instance with the specified content.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(NSString s)Appends a string to this string.voidappend(java.lang.String s)Appends a string to this string.booleanboolValue()Gets the boolean value of this string.NSStringclone()Creates and returns a deep copy of this instance.intcompareTo(NSObject o)doubledoubleValue()Gets the floating-point value (double precision) of this string.booleanequals(java.lang.Object obj)(package private) static java.lang.StringescapeStringForASCII(java.lang.String s)Escapes a string for use in ASCII property lists.(package private) static java.lang.StringescapeStringForXml(java.lang.String s)floatfloatValue()Gets the floating-point value of this string.java.lang.StringgetContent()Gets the string content of this instance.inthashCode()intintValue()Gets the integer value of this string.voidprepend(NSString s)Prepends a string to this string.voidprepend(java.lang.String s)Prepends a string to this string.voidsetContent(java.lang.String c)Sets the string content of this instance.protected voidtoASCII(java.lang.StringBuilder ascii, int level)Generates the ASCII representation of this object.protected voidtoASCIIGnuStep(java.lang.StringBuilder ascii, int level)Generates the ASCII representation of this object in the GnuStep format.voidtoBinary(BinaryPropertyListWriter out)Generates the binary representation of the object.java.lang.ObjecttoJavaObject()Converts this NSObject into an equivalent object of the Java Runtime Environment.java.lang.StringtoString()(package private) voidtoXML(java.lang.StringBuilder xml, int level)Generates the XML representation of the object (without XML headers or enclosing plist-tags).-
Methods inherited from class com.dd.plist.NSObject
assignIDs, fromJavaObject, indent, toJavaObject, toXMLPropertyList
-
-
-
-
Constructor Detail
-
NSString
public NSString(byte[] bytes, java.lang.String encoding) throws java.io.UnsupportedEncodingExceptionCreates a new NSString instance from its binary representation.- Parameters:
bytes- The binary representation.encoding- The string encoding (name of the charset).- Throws:
java.io.UnsupportedEncodingException- When the given encoding is not supported by the JRE.- See Also:
String(byte[], String)
-
NSString
public NSString(byte[] bytes, int startIndex, int endIndex, java.lang.String encoding) throws java.io.UnsupportedEncodingExceptionCreates a new NSString instance from its binary representation.- Parameters:
bytes- An array containing the binary representation of the string.startIndex- The offset inside the array at which the string data starts.endIndex- The offset inside the array at which the string data ends.encoding- The string encoding (name of the charset).- Throws:
java.io.UnsupportedEncodingException- When the given encoding is not supported by the JRE.- See Also:
String(byte[], int, int, String)
-
NSString
public NSString(java.lang.String string)
Creates a new NSString instance with the specified content.- Parameters:
string- The string that will be contained in the NSString.
-
-
Method Detail
-
intValue
public int intValue()
Gets the integer value of this string.- Returns:
- The integer value of this string, assuming a decimal representation and skipping whitespace at the beginning of the string. If the string does not contain a valid decimal representation of a number, 0 is returned. If the string contains an integer larger than Integer.MAX_VALUE, Integer.MAX_VALUE is returned. If the string contains an integer less than Integer.MIN_VALUE, Integer.MIN_VALUE is returned.
-
floatValue
public float floatValue()
Gets the floating-point value of this string.- Returns:
- The floating-point value of this string, assuming a decimal representation and skipping whitespace at the beginning of the string. If the string does not contain a valid decimal representation of a number, 0 is returned. If the string contains an integer larger than Float.MAX_VALUE, Float.MAX_VALUE is returned. If the string contains an integer less than -Float.MAX_VALUE, -Float.MAX_VALUE is returned.
-
doubleValue
public double doubleValue()
Gets the floating-point value (double precision) of this string.- Returns:
- The floating-point value of this string, assuming a decimal representation and skipping whitespace at the beginning of the string. If the string does not contain a valid decimal representation of a floating-point number, 0 is returned.
-
boolValue
public boolean boolValue()
Gets the boolean value of this string.- Returns:
- The boolean value of this string. Leading whitespaces are ignored. Any + or - sign and leading zeroes are
ignored.
If the remaining string starts with 'Y', 'y', 'T', 't' or a positive digit (1-9), true is returned.
Otherwise, false is returned.
Examples: "YES" is true "true" is true " YES" is true "+1" is true "-9" is true " +01" is true "0" is false "false" is false "no" is false "1FALSE" is true "0TRUE" is true "FALSE1" is false
-
getContent
public java.lang.String getContent()
Gets the string content of this instance.- Returns:
- This string contained in this instance.
-
setContent
public void setContent(java.lang.String c)
Sets the string content of this instance.- Parameters:
c- The new content of this string object.
-
append
public void append(NSString s)
Appends a string to this string.- Parameters:
s- The string to append.
-
append
public void append(java.lang.String s)
Appends a string to this string.- Parameters:
s- The string to append.
-
prepend
public void prepend(java.lang.String s)
Prepends a string to this string.- Parameters:
s- The string to prepend.
-
prepend
public void prepend(NSString s)
Prepends a string to this string.- Parameters:
s- The string to prepend.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
clone
public NSString clone()
Description copied from class:NSObjectCreates and returns a deep copy of this instance.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toJavaObject
public java.lang.Object toJavaObject()
Description copied from class:NSObjectConverts this NSObject into an equivalent object of the Java Runtime Environment.NSArrayobjects are converted to arrays.NSDictionaryobjects are converted to objects extending theMapclass.NSSetobjects are converted to objects extending theSetclass.NSNumberobjects are converted to primitive number values (int, long, double or boolean).NSStringobjects are converted toStringobjects.NSDataobjects are converted to byte arrays.NSDateobjects are converted toDateobjects.UIDobjects are converted to byte arrays.
- Specified by:
toJavaObjectin classNSObject- Returns:
- A native java object representing this NSObject's value.
-
toXML
void toXML(java.lang.StringBuilder xml, int level)Description copied from class:NSObjectGenerates the XML representation of the object (without XML headers or enclosing plist-tags).
-
toBinary
public void toBinary(BinaryPropertyListWriter out) throws java.io.IOException
Description copied from class:NSObjectGenerates the binary representation of the object.
-
toASCII
protected void toASCII(java.lang.StringBuilder ascii, int level)Description copied from class:NSObjectGenerates the ASCII representation of this object. The generated ASCII representation does not end with a newline. Complies with the Old-Style ASCII Property Lists definition.
-
toASCIIGnuStep
protected void toASCIIGnuStep(java.lang.StringBuilder ascii, int level)Description copied from class:NSObjectGenerates the ASCII representation of this object in the GnuStep format. The generated ASCII representation does not end with a newline.- Specified by:
toASCIIGnuStepin classNSObject- Parameters:
ascii- TheStringBuilderonto which the ASCII representation is appended.level- The indentation level of the object.
-
compareTo
public int compareTo(NSObject o)
-
escapeStringForASCII
static java.lang.String escapeStringForASCII(java.lang.String s)
Escapes a string for use in ASCII property lists.- Parameters:
s- The unescaped string.- Returns:
- The escaped string.
-
escapeStringForXml
static java.lang.String escapeStringForXml(java.lang.String s)
-
-