StringInterface (class)
public abstract StringInterface
Package: CURL.LANGUAGE.STRINGS
Direct Known Subclasses: WritableString, ReadOnlyString, SubString

Abstract class for strings.

Description

StringInterface provides the interface for string classes in Curl. In other words, StringInterface provides the accessors and methods that form the basis of most string classes in Curl.

You cannot instantiate StringInterface because it is an abstract class. To create a string object, instantiate one of the string classes that inherits from StringInterface. Note that Curl specifically optimizes usage of the String class; use this where possible for read-only strings.

Notes

The hierarchy of string classes in Curl is as follows:

StringInterface
SubString
ReadOnlyString
String
WritableString
StringBuf

For more information about Strings in Curl, see Curl Developer's Guide: Strings.

Properties
empty?:Checks if self is empty.
accessor public StringInterface.empty?:bool
for-loop-count:A getter that the Curl compiler uses when it encounters a container for loop that iterates over a string.
accessor public StringInterface.for-loop-count:int
size:The number of characters in self.
accessor public abstract StringInterface.size:int
Methods
clone:
public abstract {StringInterface.clone}:StringInterface
compare:Compares self to a specified StringInterface.
public {StringInterface.compare
    str:StringInterface,
    ignore-case?:bool = false
}:int
equal?:Checks if self is equal to a specified StringInterface.
public {StringInterface.equal?
    str:StringInterface,
    ignore-case?:bool = false
}:bool
find:Searches self for a particular character c.
public {StringInterface.find
    c:char,
    ignore-case?:bool = false,
    search-direction:SearchDirection = SearchDirection.forward,
    starting-index:int = 0
}:int
find-char-class:Searches self for a character in char-class.
public {StringInterface.find-char-class
    char-class:CharClass,
    search-direction:SearchDirection = SearchDirection.forward,
    starting-index:int = 0
}:int
find-string:Searches self for a substring str.
public {StringInterface.find-string
    str:StringInterface,
    ignore-case?:bool = false,
    search-direction:SearchDirection = SearchDirection.forward,
    starting-index:int = {if search-direction == SearchDirection.forward then 0 else {max -1, self.size - str.size} }
}:int
get:Returns the specified character from self.
public abstract {StringInterface.get index:int}:char
prefix?:Returns true if self starts with str.
public {StringInterface.prefix?
    str:StringInterface,
    ignore-case?:bool = false
}:bool
replace-clone:Returns a new String where each occurrence of old is replaced with new.
public final {StringInterface.replace-clone
    old:StringInterface,
    new:StringInterface,
    starting-index:int = 0
}:String
split:Splits self at specified characters.
public {StringInterface.split
    split-chars:#CharClass = CharClass.whitespace-chars
}:StringArray
substr:Returns a specified substring of self.
public {StringInterface.substr start:int, length:int}:String
suffix?:Returns true if self ends with str.
public {StringInterface.suffix?
    str:StringInterface,
    ignore-case?:bool = false
}:bool
tail:Returns {self.substr start, self.size - start}.
public {StringInterface.tail start:int}:String
to-double:Parses self into a double.
public {StringInterface.to-double
    whitespace:CharClass = CharClass.whitespace-chars,
    start:int = 0,
    error-if-over-or-underflow?:bool = true
}:( val:double, n-chars-consumed:int, overflow-or-underflow?:bool )
to-InputStream:Returns an input stream containing self.
public {StringInterface.to-InputStream}:SeekableTextInputStream
to-int:Parses self into an int.
public {StringInterface.to-int
    radix:int = 0,
    start:int = 0,
    whitespace:CharClass = CharClass.whitespace-chars,
    error-if-overflow?:bool = true
}:( val:int, n-chars-consumed:int, overflow?:bool, radix:int )
to-int64:Parses self into an int64.
public {StringInterface.to-int64
    radix:int = 0,
    start:int = 0,
    whitespace:CharClass = CharClass.whitespace-chars,
    error-if-overflow?:bool = true
}:( val:int64, n-chars-consumed:int, overflow?:bool, radix:int )
to-lower-clone:Returns a clone of self, with the characters in lowercase.
public {StringInterface.to-lower-clone}:String
to-String:Produces a String that is == to self.
public {StringInterface.to-String}:String
to-upper-clone:Returns a clone of self, with the characters in uppercase.
public {StringInterface.to-upper-clone}:String
trim-clone:Returns a clone of self, trimmed from the left and right.
public {StringInterface.trim-clone
    trim-chars:CharClass = CharClass.whitespace-chars
}:String
trim-left-clone:Returns a clone of self, trimmed only from the left.
public {StringInterface.trim-left-clone
    trim-chars:CharClass = CharClass.whitespace-chars
}:String
trim-right-clone:Returns a clone of self, trimmed only from the right.
public {StringInterface.trim-right-clone
    trim-chars:CharClass = CharClass.whitespace-chars
}:String
Methods inherited from Object: object-describe, object-describe-for-debugging, object-serialize

Property Details
empty? (accessor)
accessor public StringInterface.empty?:bool

Checks if self is empty.

Returns

A bool value. Returns true if self has no characters. Otherwise, returns false.

Example

The following example shows a string with no characters.


Example
{value
    || Declare and initialize an empty string
    let s:String = ""

    || Check if the string is empty and display an
    || appropriate message
    {if s.empty? then
        {text The string is empty!}
     else
        {text The string has characters!}
    }
}


The following example shows a string with characters.


Example
{value
    || Declare and initialize a string
    let s:String = "Hello World!"

    || Check if the string is empty and display an
    || appropriate message
    {if s.empty? then
        {text The string is empty!}
     else
        {text The string has characters!}
    }
}


for-loop-count (accessor)
accessor public StringInterface.for-loop-count:int

A getter that the Curl compiler uses when it encounters a container for loop that iterates over a string.

Notes

Do not call this getter; it is intended only for use by the Curl compiler.


size (accessor)
accessor public abstract StringInterface.size:int

The number of characters in self.

Returns

An int indicating the number of characters.

Description

For read-only strings: For writable strings: If you set the size to be smaller than the current size of the string, Curl truncates the string. If you set the size to be larger than the current size, Curl adds the appropriate number of characters (with Unicode value 0000) to the end of the string.

Example

The following example shows size with a read-only string.


Example
{value
    || Declare and initialize a read-only string
    let s:String = "Hello World!"

    || Output a message that includes the return value of
    || a call to "size".
    || Note that you must use "value" to display the value
    || of "s.size", rather than the text "s.size".
    {text There are {value s.size} characters in the string.}
}


The following examples show size with a writable string.


Example
{value
    || Declare and initialize a writable string.
    let sb:StringBuf = {StringBuf "Hello World!"}

    || Set the size of the string to 5 characters.
    || The string should now contain only the first five
    || characters, "Hello".
    set sb.size = 5

    || Output a message that includes the new string
    {text If {monospace size} is set to 5, the string
        becomes: {value sb}}
}



Example
{value
    || Declare and initialize a writable string.
    let sb:StringBuf = {StringBuf "Hello World!"}

    || Set the size of the string to 20 characters.
    || The string should now have 8 characters
    || with the Unicode value 0000 at the end.
    set sb.size = 20

    || Output a message that includes the new string.
    {text Then, if {monospace size} is set to 20, the string
        becomes: {value sb}}
}

Notes

This is an abstract getter of StringInterface; it is implemented by subclasses of StringInterface.


Method Details
clone (method)
public abstract {StringInterface.clone}:StringInterface
This item is unsupported and reserved for internal use.


compare (method)
public {StringInterface.compare
    str:StringInterface,
    ignore-case?:bool = false
}:int

Compares self to a specified StringInterface.

str: The StringInterface with which you want to compare.
ignore-case?: A keyword argument that indicates if the comparison is to ignore the case of the characters. By default, the comparison does not ignore case (ignore-case? = false). In other words, by default the comparison is case sensitive. For example, "aaaa" is greater than "BBBB".

ignore-case? is a keyword argument. To specify ignore-case?, make sure to assign the desired value to the keyword in the method call (for example ignore-case? = true).

If you specify ignore-case? and assign it to true, the comparison is not case-sensitive. In this situation, "aaaa" is less than "BBBB".

Returns

An int value:

Description

This method uses the Unicode value of each character when comparing the StringInterfaces. That is, it performs a lexicographic comparison of the strings.

Example


Example
{value
    || Declare and initialize two strings
    let s1:String = "Hello World!"
    let s2:String = "hello world!"

    || Display the strings.
    {text String 1: {value s1}
        {br}String 2: {value s2}

        || Compare the two strings and display an
        || appropriate message.
        {switch {s1.compare s2}
         case -1 do
            {text String 1 is less than String 2.}
         case 0 do
            {text String 1 is equal to String 2.}
         else
            {text String 1 is greater than String 2.}
        }

        || Compare the two strings, this time ignoring case,
        || and display an appropriate message.
        But, if you ignore case,
        {switch {s1.compare s2, ignore-case? = true}
         case -1 do
            {text String 1 is less than String 2.}
         case 0 do
            {text String 1 is equal to String 2.}
         else
            {text String 1 is greater than String 2.}
        }
    }
}


equal? (method)
public {StringInterface.equal?
    str:StringInterface,
    ignore-case?:bool = false
}:bool

Checks if self is equal to a specified StringInterface.

str: The StringInterface with which you want to check for equality.
ignore-case?: A keyword argument that indicates if the test is to ignore the case of the characters. By default, the test does not ignore case (ignore-case? = false). In other words, by default the test is case sensitive. For example, "abcdefg" is not equal to "ABCDEFG".

ignore-case? is a keyword argument. To specify ignore-case?, make sure to assign the desired value to the keyword in the method call (for example ignore-case? = true).

If you specify ignore-case? and assign it to true, the test is not case-sensitive. In this situation, "abcdefg" is equal to "ABCDEFG".

Returns

A bool value. Returns true if each character in self is equal to the corresponding character in str. Otherwise, returns false.

Example


Example
{value
    || Declare and initialize two strings
    let s1:String = "Hello World!"
    let s2:String = "hello world!"

    || Display the strings.
    {text
        String 1: {value s1}
        {br}String 2: {value s2}

        || Test if the two strings are equal and display
        || an appropriate message.
        {if {s1.equal? s2} then
            {text The strings are equal.}
         else
            {text The strings are NOT equal.}
        }

        || Test if the two strings are equal, this time
        || ignoring case, and display an appropriate message.
        But, if you ignore case,
        {if {s1.equal? s2, ignore-case? = true} then
            {text they are equal.}
         else
            {text they are NOT equal.}
        }
    }
}


find (method)
public {StringInterface.find
    c:char,
    ignore-case?:bool = false,
    search-direction:SearchDirection = SearchDirection.forward,
    starting-index:int = 0
}:int

Searches self for a particular character c.

c: is the character for which you want to search.
ignore-case?: A keyword argument that indicates if the comparison is to ignore the case of the characters.
search-direction: is the search direction. SearchDirection.forward indicates a left-to-right search. SearchDirection.backward indicates a right-to-left search.
starting-index: is an int that indicates the index of the character from which you want to start searching. For left-to-right searches, this parameter defaults to 0. For right-to-left searches, this parameter defaults to self.size - 1.

Returns

An int containing the index of the matching character. If there is no matching character, this method returns -1.

Description

Searches self for the first character that equals c. Returns the index of that character. If there is no match, this method returns -1.

If starting-index is out of bounds, this method throws an ArrayBoundsException.


find-char-class (method)
public {StringInterface.find-char-class
    char-class:CharClass,
    search-direction:SearchDirection = SearchDirection.forward,
    starting-index:int = 0
}:int

Searches self for a character in char-class.

char-class: is the CharClass for which you want to search.
search-direction: is the search direction. SearchDirection.forward indicates a left-to-right search. SearchDirection.backward indicates a right-to-left search.
starting-index: is an int that indicates the index of the character from which you want to start searching. For left-to-right searches, this parameter defaults to 0. For right-to-left searches, this parameter defaults to self.size - 1.

Returns

An int containing the index of the first matching character. If there is no match, this method returns -1.

Description

Searches self for the first character that is also in char-class. Returns the index of that character. If there is no match, this method returns -1.

If starting-index is out of bounds, this method throws an ArrayBoundsException.


find-string (method)
public {StringInterface.find-string
    str:StringInterface,
    ignore-case?:bool = false,
    search-direction:SearchDirection = SearchDirection.forward,
    starting-index:int = {if search-direction == SearchDirection.forward then 0 else {max -1, self.size - str.size} }
}:int

Searches self for a substring str.

str: is the substring for which you want to search.
ignore-case?: A keyword argument that indicates if the comparison is to ignore the case of the characters.
search-direction: is the search direction. SearchDirection.forward indicates a left-to-right search. SearchDirection.backward indicates a right-to-left search.
starting-index: is an int that indicates the index of the character from which you want to start searching. For left-to-right searches, this parameter defaults to 0. For right-to-left searches, this parameter defaults to {max -1, self.size - str.size}.

Returns

An int containing the index of the first matching character. If there is no matching string, this method returns -1.

Description

Searches self for the first substring that equals str. Returns the index of the first character of the matching substring. If there is no matching substring, this method returns -1.

If starting-index or starting-index + str.size is out of bounds, this method throws an ArrayBoundsException.


get (method)
public abstract {StringInterface.get index:int}:char

Returns the specified character from self.

index: The position of the character that you want to return. The leftmost character is at position 0. The rightmost character is at position (self.size - 1). Valid values range from 0 to (self.size - 1) inclusive.

Throws

Should throw an ArrayBoundsException if index is out of bounds.

Example


Example
{value
    || Declare and initialize a string.
    let s:String = "Hello World!"

    || Display the string and return the
    || character at position 7.
    || Remember that the leftmost position
    || is 0 (zero).
    {text {value s}
        {br}The character at position 7 is {s.get 7}.}
}

Notes

This is an abstract method of StringInterface; it is implemented by subclasses of StringInterface.


prefix? (method)
public {StringInterface.prefix?
    str:StringInterface,
    ignore-case?:bool = false
}:bool

Returns true if self starts with str.



replace-clone (method)
public final {StringInterface.replace-clone
    old:StringInterface,
    new:StringInterface,
    starting-index:int = 0
}:String

Returns a new String where each occurrence of old is replaced with new.

old: The substring that you want to replace with new.
new: The substring that you want to replace each occurrence of old.

Description

Searches for the substring old from left-to-right. For each occurrence it removes old, splices in new, and resumes searching after the newly inserted characters.

Example


Example
{value
    || Declare and initialize a String.
    let x:String = "Silly willy"

    || Replace each occurrence of "ill" with "ick".
    let y:String = {x.replace-clone "ill", "ick"}

    || Display the resulting String.
    y
}


split (method)
public {StringInterface.split
    split-chars:#CharClass = CharClass.whitespace-chars
}:StringArray

Splits self at specified characters.

split-chars: The characters at which to split self. The default value of split-chars is the set of characters that comprise whitespace for the current locale, as defined by CharClass.whitespace-chars. To specify different characters for a call to this method, specify a CharClass containing the characters. split-chars is a keyword argument. To specify split-chars, make sure to assign the desired value to the keyword in the method call (for example split-chars = {CharClass " .,;:"}).

If the split-chars keyword-argument is specified to be null, this method returns an array containing one element for each character.

Returns

An array of StringInterface. There is one element in the array for each resulting StringInterface.

Description

Splits self at each character in split-chars, forming a number of smaller strings. The smaller strings do not include the split-chars characters. This method then returns an array containing the smaller strings.

In the following situations, this method adds an element with an empty string to the array:

If split-chars is null, this method returns an array containing one element for each character.

Example


Example
{value
    || Declare and initialize a string.
    let s:String = "www.curl.com"

    || Split the string at the periods.
    let a:StringArray = {s.split split-chars = "."}

    || Declare and instantiate a VBox for displaying
    || an output message indicating the results.
    let out:VBox = {VBox}

    || For each element in the results array, add it
    || to the output message.
    {for str in a do
        {out.add str}
    }

    || Display the string and the output message.
    {text String: {value s}
        {br}Splitting the string returns the following strings...
        {br}{value out}
    }
}


substr (method)
public {StringInterface.substr start:int, length:int}:String

Returns a specified substring of self.

start: The position in self at which the substring starts. The leftmost character is at position 0. The rightmost character is at position (self.size - 1). Valid values range from 0 to (self.size - 1) inclusive.
length: The length of the substring. In other words, the number of characters in the substring.

Returns

A String containing the specified substring of self, containing length consecutive characters, beginning at position start.

Notes

If start or start + length is out of bounds this method throws an ArrayBoundsException.

Example


Example
{value
    || Declare and initialize s1 (the original string).
    let s1:String = "Hello World!"

    || Initialize s2 with a substring of s1.  The
    || substring begins at position 6 and is 5
    || characters long ("World").
    || Remember that the leftmost position
    || is 0 (zero).
    let s2:String = {s1.substr 6, 5}

    || Display the contents of s2.
    {value s2}
}

Notes

For a detailed description of cloning, see Curl Developer's Guide: Strings: Working with String Clones.


suffix? (method)
public {StringInterface.suffix?
    str:StringInterface,
    ignore-case?:bool = false
}:bool

Returns true if self ends with str.



tail (method)
public {StringInterface.tail start:int}:String

Returns {self.substr start, self.size - start}.



to-double (method)
public {StringInterface.to-double
    whitespace:CharClass = CharClass.whitespace-chars,
    start:int = 0,
    error-if-over-or-underflow?:bool = true
}:( val:double, n-chars-consumed:int, overflow-or-underflow?:bool )

Parses self into a double.

whitespace: The characters that comprise whitespace at the beginning of self. Whitespace characters usually include spaces and tabs. The default value of whitespace is the set of characters that comprise whitespace for the current locale, as defined by CharClass.whitespace-chars. To specify different whitespace characters for a call to this method, specify a CharClass containing the whitespace characters. whitespace is a keyword argument. To specify whitespace, make sure to assign the desired value to the keyword in the method call (for example whitespace = {CharClass " .,;:"}). Of course, you can also use this parameter to specify characters, other than whitespace, that you want to ignore.
start: The position in self at which to start parsing. The leftmost character is at position 0. The rightmost character is at position (self.size - 1). Valid values range from 0 to self.size inclusive. The default value is 0. start is a keyword argument. To specify start, make sure to assign the desired value to the keyword in the method call (for example start = 4).

If start is out of bounds, this method throws an ArrayBoundsException.
error-if-over-or-underflow?: A Boolean flag that indicates if this method generates an error when the number overflows or underflows. A number overflows when it is too large to be stored in a double. A number underflows when it is too small to be stored in a double.

If error-if-over-or-underflow? is true, this method throws an error when it detects an overflow or an underflow. An error terminates execution of the program and displays an appropriate error message. By default, error-if-over-or-underflow? is true. If error-if-over-or-underflow? is false, this method does not generate an error and returns a value:

error-if-over-or-underflow? is a keyword argument. To specify error-if-over-or-underflow?, make sure to assign the desired value to the keyword in the method call (for example error-if-over-or-underflow? = false).

Also see StringInterface.to-int.

Returns

Returns the following values, from left-to-right:

Description

self must have the following format:

spaces[sign]num[exp]

Where:

For example, this method can parse numbers from the following strings:

The string can include characters following those that make up the number; these characters are sometimes called trailing characters. This method ignores trailing characters. However, the return value that indicates the number of characters that are parsed includes the trailing characters. This means, for example, that "365e-10 is the multiplier" is a valid string upon which to call this method.

If the characters in self do not conform to the format, this method returns 0 for the value of the double.

Example

The following example converts a string with whitespace, a number, and a negative exponent to a double.


Example
{value
    || Declare and initialize a string
    let s:String = "  365e-10"

    || Declare variables to hold the return values from
    || a call to "to-double"
    let number:double
    let chars:int
    let over-or-underflow?:bool

    || Call "to-double" and assign the multiple return
    || values to the variables.
    set (number, chars, over-or-underflow?) =
        {s.to-double error-if-over-or-underflow? = false}

    || Display a message containing the result of a call
    || to "to-double".
    || Note that you must use "value" to display the values
    || of the variables.
    {text The number is {value number}, which occupied
        {value chars} characters in the original string.}

    || Note that you can use "format" to change how Curl
    || displays numbers.
}


The following example converts a string with trailing characters to a double.


Example
{value
    || Declare and initialize a string
    let s:String = "365e-10 is the multiplier"

    || Declare variables to hold the return values from
    || a call to "to-double"
    let number:double
    let chars:int
    let over-or-underflow?:bool

    || Call "to-double" and assign the multiple return
    || values to the variables.
    set (number, chars, over-or-underflow?) =
        {s.to-double error-if-over-or-underflow? = false}

    || Display a message containing the result of a call
    || to "to-double".
    {text The number is {value number}.  {value chars}
        characters were parsed.}
}


And the following example, only takes the first return value, which is a typical usage scenario.


Example
{value
    || Declare and initialize a string
    let s:String = "365e-10 is the multiplier"

    || Declare variable to hold the return value from
    || a call to "to-double"
    let number:double

    || Call "to-double" and assign the first return
    || value to the variable.
    set number = {s.to-double}

    || Display a message containing the result of a call
    || to "to-double".
    {text The number is {value number}.}
}


to-InputStream (method)
public {StringInterface.to-InputStream}:SeekableTextInputStream

Returns an input stream containing self.

Returns

A SeekableTextInputStream containing the characters from self.

Description

Returns a SeekableTextInputStream containing self. The order of characters is preserved (the leftmost character of self is also the leftmost character of the input stream).

Example

The following example uses the to-InputStream method to convert a string to an input stream.


Example
{value
    || Declare and initialize a string.
    let s:String = "Hello World!"

    || Use to-InputStream to set the contents of "s"
    || to the input stream.
    let tis:TextInputStream = {s.to-InputStream}

    || Retrieve (and display) a string from the input
    || stream.
    {tis.read-one-string}
}

Notes

For information about streams, see Curl Developer's Guide: Input/Output: Streams.


to-int (method)
public {StringInterface.to-int
    radix:int = 0,
    start:int = 0,
    whitespace:CharClass = CharClass.whitespace-chars,
    error-if-overflow?:bool = true
}:( val:int, n-chars-consumed:int, overflow?:bool, radix:int )

Parses self into an int.

radix: The number system for the digits as they appear in self. You can specify any number system between base 2 and base 36. The default value of radix is 0, which indicates that self specifies the number system. In other words, if the number uses a number system other than decimal, self includes the number system prefix. Valid number system prefixes are 0b or 0B for binary, 0o or 0O for octal, and 0x or 0X for hexadecimal. radix is a keyword argument. To specify radix, make sure to assign the desired value to the keyword in the method call (for example radix = 16).
start: The position in self at which to start parsing. The leftmost character is at position 0. The rightmost character is at position (self.size - 1). Valid values range from 0 to self.size inclusive. The default value is 0. start is a keyword argument. To specify start, make sure to assign the desired value to the keyword in the method call (for example start = 4).

If start is out of bounds, this method throws an ArrayBoundsException.
whitespace: The characters that comprise whitespace at the beginning of self. Whitespace characters usually include spaces and tabs. The default value of whitespace is the set of characters that comprise whitespace for the current locale, as defined by CharClass.whitespace-chars. To specify different whitespace characters for a call to this method, specify a CharClass containing the whitespace characters. whitespace is a keyword argument. To specify whitespace, make sure to assign the desired value to the keyword in the method call (for example whitespace = {CharClass " .,;:"}). Of course, you can also use this parameter to specify characters, other than whitespace, that you want to ignore.
error-if-overflow?: A Boolean flag that indicates if this method generates an error when the number is outside the valid range for an int (in other words, when the number overflows). Note that this method performs a signed overflow check for base 10 numbers and an unsigned overflow check for all other numbers.

If error-if-overflow? is true, this method throws an error when it detects an overflow. An error terminates execution of the program and displays an appropriate error message. If error-if-overflow? is false, this method does not generate an error and returns whatever it can produce, losing most significant bits. By default, error-if-overflow? is true.

error-if-overflow? is a keyword argument. To specify error-if-overflow?, make sure to assign the desired value to the keyword in the method call (for example error-if-overflow? = false).

Returns

Returns the following values, from left-to-right:

Description

self must have the following format:

spaces[sign][num-sys]num

Where:

For example, this method can parse integers from the following strings:

The string can include characters following those that make up the integer; these characters are sometimes called trailing characters. This method ignores trailing characters. However, the return value that indicates the number of characters that are parsed includes the trailing characters. This means, for example, that "365 days of the year" is a valid string upon which to call this method.

If the characters in self do not conform to the format, this method returns 0 for the value of the integer.

If self includes a number system prefix, make sure to set the radix parameter accordingly.

Also see StringInterface.to-int64 and StringInterface.to-double.

Example

The following example converts a string with whitespace, a sign, and a hexadecimal representation of a number to an integer.


Example
{value
    || Declare and initialize a string
    let s:String = "  -0X16D"

    || Declare variables to hold the return values from
    || a call to "to-int"
    let number:int
    let chars:int
    let overflow?:bool

    || Call "to-int" and assign the multiple return
    || values to the variables.
    set (number, chars, overflow?) =
        {s.to-int error-if-overflow? = false}

    || Display a message containing the result of a call
    || to "to-int".
    || Note that you must use "value" to display the values
    || of the variables.
    {text The number is {value number}.  {value chars}
        characters were parsed.}

    || Note that to display an integer in a number system
    || other than decimal, you must use "format".
}


The following example converts a string with trailing characters to an integer.


Example
{value
    || Declare and initialize a string
    let s:String = "365 days of the year"

    || Declare variables to hold the return values from
    || a call to "to-int"
    let number:int
    let chars:int
    let overflow?:bool

    || Call "to-int" and assign the multiple return
    || values to the variables.
    set (number, chars, overflow?) =
        {s.to-int error-if-overflow? = false}

    || Display a message containing the result of a call
    || to "to-int".
    {text The number is {value number}.  {value chars}
        characters were parsed.}
}


And the following example, only takes the first return value, which is a typical usage scenario.


Example
{value
    || Declare and initialize a string
    let s:String = "365 days of the year"

    || Declare a variable to hold the first return value
    || from a call to "to-int"
    let number:int

    || Call "to-int" and assign the first return
    || value to the variable.
    set number = {s.to-int}

    || Display a message containing the result of a call
    || to "to-int".
    {text The number is {value number}.}
}


to-int64 (method)
public {StringInterface.to-int64
    radix:int = 0,
    start:int = 0,
    whitespace:CharClass = CharClass.whitespace-chars,
    error-if-overflow?:bool = true
}:( val:int64, n-chars-consumed:int, overflow?:bool, radix:int )

Parses self into an int64.

Description

This is exactly like StringInterface.to-int except that it handles 64-bit values.


to-lower-clone (method)
public {StringInterface.to-lower-clone}:String

Returns a clone of self, with the characters in lowercase.

Returns

A String containing the resulting characters.

Example


Example
{value
    || Declare and initialize a string
    let s1:String = "Hello World!"

    || Initialize s2 with a string containing the
    || characters of s1 in lowercase.
    let s2:String = {s1.to-lower-clone}

    || Display the contents of s2.
    {value s2}
}

Notes

For a detailed description of cloning, see Curl Developer's Guide: Strings: Working with String Clones.


to-String (method)
public {StringInterface.to-String}:String

Produces a String that is == to self.

Returns

A String containing the characters in self.

Example


Example
{value
    || Define and initialize a StringBuf.
    let sb:StringBuf = {StringBuf "Hello World!"}

    || Convert the StringBuf to a String.
    let s:String = {sb.to-String}

    || Display the contents of the String.
    {value s}
}


to-upper-clone (method)
public {StringInterface.to-upper-clone}:String

Returns a clone of self, with the characters in uppercase.

Returns

A String containing the resulting characters.

Example


Example
{value
    || Declare and initialize a string
    let s1:String = "Hello World!"

    || Initialize s2 with a string containing the
    || characters of s1 in uppercase.
    let s2:String = {s1.to-upper-clone}

    || Display the contents of s2.
    {value s2}
}

Notes

For a detailed description of cloning, see Curl Developer's Guide: Strings: Working with String Clones.


trim-clone (method)
public {StringInterface.trim-clone
    trim-chars:CharClass = CharClass.whitespace-chars
}:String

Returns a clone of self, trimmed from the left and right.

trim-chars: The characters that you want to trim. The default value of trim-chars is the set of characters that comprise whitespace for the current locale, as defined by CharClass.whitespace-chars. To specify different trim characters for a call to this method, specify a CharClass containing the characters. trim-chars is a keyword argument. To specify trim-chars, make sure to assign the desired value to the keyword in the method call (for example trim-chars = {CharClass " .,;:"}).

Returns

A String containing the resulting characters.

Description

Moves from the left end of self, removing the characters indicated in trim-chars until it encounters a character that is not in trim-chars. Repeats this process from the right end of self. Returns the resulting string.

Note that characters in trim-chars that appear between non-trim characters are not removed. For example, if the trim characters include a space, spaces will be removed at the beginning of the string and at the end of the string, but not between words in the string.

Example


Example
{value
    || Declare and initialize a string
    let s1:String = "  Hello World!  "

    || Initialize s2 with the characters of s1,
    || removing whitespace from the beginning
    || and the end of the string.
    let s2:String = {s1.trim-clone}

    || Display the contents of s2.
    || The # characters are used to indicate
    || beginning and end of the string.
    {pre #{value s2}#}
}

Notes

For a detailed description of cloning, see Curl Developer's Guide: Strings: Working with String Clones.


trim-left-clone (method)
public {StringInterface.trim-left-clone
    trim-chars:CharClass = CharClass.whitespace-chars
}:String

Returns a clone of self, trimmed only from the left.

trim-chars: The characters that you want to trim. The default value of trim-chars is the set of characters that comprise whitespace for the current locale, as defined by CharClass.whitespace-chars. To specify different trim characters for a call to this method, specify a CharClass containing the characters. trim-chars is a keyword argument. To specify trim-chars, make sure to assign the desired value to the keyword in the method call (for example trim-chars = {CharClass " .,;:"}).

Returns

A String containing the resulting characters.

Description

Moves from the left end of self, removing the characters indicated in trim-chars until it encounters a character that is not in trim-chars. Returns the resulting string.

Example


Example
{value
    || Declare and initialize a string
    let s1:String = "  Hello World!  "

    || Initialize s2 with the characters of s1,
    || removing whitespace from the beginning
    || of the string.
    let s2:String = {s1.trim-left-clone}

    || Display the contents of s2.
    || The # characters are used to indicate
    || beginning and end of the string.
    {pre #{value s2}#}
}

Notes

For a detailed description of cloning, see Curl Developer's Guide: Strings: Working with String Clones.


trim-right-clone (method)
public {StringInterface.trim-right-clone
    trim-chars:CharClass = CharClass.whitespace-chars
}:String

Returns a clone of self, trimmed only from the right.

trim-chars: The characters that you want to trim. The default value of trim-chars is the set of characters that comprise whitespace for the current locale, as defined by CharClass.whitespace-chars. To specify different trim characters for a call to this method, specify a CharClass containing the characters. trim-chars is a keyword argument. To specify trim-chars, make sure to assign the desired value to the keyword in the method call (for example trim-chars = {CharClass " .,;:"}).

Returns

A String containing the resulting characters.

Description

Moves from the right end of self, removing the characters indicated in trim-chars until it encounters a character that is not in trim-chars. Returns the resulting string.

Example


Example
{value
    || Declare and initialize a string
    let s1:String = "  Hello World!  "

    || Initialize s2 with the characters of s1,
    || removing whitespace from the end of the
    || string.
    let s2:String = {s1.trim-right-clone}

    || Display the contents of s2.
    || The # characters are used to indicate
    || beginning and end of the string.
    {pre #{value s2}#}
}

Notes

For a detailed description of cloning, see Curl Developer's Guide: Strings: Working with String Clones.