@haxall/haxall
    Preparing search index...

    Class Str

    Str represents a sequence of Unicode characters.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    type$: Type

    Methods

    • Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:

      this < that   =>  <0
      this == that => 0
      this > that => >0

      This method may also be accessed via the < <= <=> >= and > shortcut operators. If not overridden the default implementation compares the toStr representations. Also see docLang.

      Examples:

      3.compare(8)  =>  -1
      8.compare(3) => 1
      8.compare(8) => 0
      3 <=> 8 => -1 // shortcut for 3.compare(8)

      Parameters

      Returns number

    • Compare this object to the specified for equality. This method may be accessed via the == and != shortcut operators. If not overridden the default implementation compares for reference equality using the === operator. If this method is overridden, then hash() must also be overridden such that any two objects which return true for equals() must return the same value for hash(). This method must accept null and return false.

      Parameters

      Returns boolean

    • Return a unique hashcode for this object. If a class overrides hash() then it must ensure if equals() returns true for any two objects then they have same hash code.

      Returns number

    • Return if this Obj is immutable and safe to share between threads:

      • an instance of a const class
      • the result of toImmutable on List, Map, or Buf
      • a Func object may or may not be immutable - see sys::Func.
      • other instances are assumed mutable and return false

      Returns boolean

    • Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:

      • if type is const, return this
      • if already an immutable List, Map, Buf, or Func return this
      • if a List, then attempt to perform a deep clone by calling toImmutable on all items
      • if a Map, then attempt to perform a deep clone by calling toImmutable on all values (keys are already immutable)
      • some Funcs can be made immutable - see sys::Func
      • if a Buf create immutable copy, see sys::Buf
      • any other object throws NotImmutableErr

      Returns Readonly<this>

    • Return a string representation of this object.

      Returns string

    • Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:

      a->x        a.trap("x", null)
      a->x() a.trap("x", null)
      a->x = b a.trap("x", [b])
      a->x(b) a.trap("x", [b])
      a->x(b, c) a.trap("x", [b, c])

      The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.

      Parameters

      Returns JsObj

    • Get the Type instance which represents this object's class. Also seeType.of or Pod.of.

      Returns Type

    • This method called whenever an it-block is applied to an object. The default implementation calls the function with this, and then returns this.

      Parameters

      • f: (arg0: this) => void

      Returns this

    • Return true if c returns true for all of the characters in this string. If this string is empty, return true.

      Example:

      "Bar".all |c| { c.isUpper } => false
      "BAR".all |c| { c.isUpper } => true

      Parameters

      • self: string
      • c: (arg0: number, arg1: number) => boolean

      Returns boolean

    • Return true if c returns true for any of the characters in this string. If this string is empty, return false.

      Example:

      "Foo".any |c| { c.isUpper } => true
      "foo".any |c| { c.isUpper } => false

      Parameters

      • self: string
      • c: (arg0: number, arg1: number) => boolean

      Returns boolean

    • Return this string with the first character converted uppercase. The case conversion is for ASCII only. Also see decapitalize and localeCapitalize.

      Example:

      "foo".capitalize => "Foo"
      

      Parameters

      • self: string

      Returns string

    • Get the characters in this string as a list of integer code points. Also see fromChars.

      Parameters

      • self: string

      Returns List<number>

    • Compare based on Unicode character values. Case is not taken into account - also see compareIgnoreCase and localeCompare.

      Examples:

      "a".compare("b")    =>  -1
      "hi".compare("hi") => 0
      "hi".compare("HI") => 1
      "b".compare("a") => 1

      Parameters

      Returns number

    • Compare two strings without regard to case and return -1, 0, or 1 if this string is less than, equal to, or greater than the specified string. Only ASCII character case is taken into account. See localeCompare for localized case insensitive comparisions.

      Examples:

      "a".compareIgnoreCase("b")    =>  -1
      "hi".compareIgnoreCase("HI") => 0
      "b".compareIgnoreCase("a") => 1

      Parameters

      • self: string
      • s: string

      Returns number

    • Return if this string contains the specified string. Convenience for index(s) != null

      Parameters

      • self: string
      • s: string

      Returns boolean

    • Return if this string contains the specified character.

      Parameters

      • self: string
      • ch: number

      Returns boolean

    • Return this string with the first character converted lowercase. The case conversion is for ASCII only. Also see capitalize and localeDecapitalize.

      Example:

      "Foo".decapitalize => "foo"
      

      Parameters

      • self: string

      Returns string

    • Default value is "".

      Returns string

    • Call the specified function for every char in the string with index 0 and incrementing up to size-1.

      Example:

      "abc".each |Int c| { echo(c.toChar) }
      

      Parameters

      • self: string
      • c: (arg0: number, arg1: number) => void

      Returns void

    • Reverse each - call the specified function for every char in the string starting with index size-1 and decrementing down to 0.

      Example:

      "abc".eachr |Int c| { echo(c.toChar) }
      

      Parameters

      • self: string
      • c: (arg0: number, arg1: number) => void

      Returns void

    • Iterate each character in the string until the function returns non-null. If function returns non-null, then break the iteration and return the resulting object. Return null if the function returns null for every item.

      Parameters

      • self: string
      • c: (arg0: number, arg1: number) => JsObj

      Returns JsObj

    • Write x.toStr to standard output followed by newline. If x is null then print "null". If no argument is provided then print an empty line.

      Parameters

      Returns void

    • Return if this Str ends with the specified Str.

      Parameters

      • self: string
      • s: string

      Returns boolean

    • Return true if a Str with exact same char sequence.

      Parameters

      Returns boolean

    • Convenience for compareIgnoreCase(s) == 0. Only ASCII character case is taken into account. See localeCompare for localized case insensitive comparisions.

      Parameters

      • self: string
      • s: string

      Returns boolean

    • Construct a string from a list of unicode code points. Also see chars.

      Parameters

      Returns string

    • Translate a display name like "Foo Bar" to a programmatic name "fooBar". This method decapitalizes the first letter, then walks the string removing spaces. Also see toDisplayName.

      Examples:

      "Foo".fromDisplayName         ->  "foo"
      "Foo Bar".fromDisplayName -> "fooBar"
      "Foo Bar Baz".fromDisplayName -> "fooBarBaz"
      "Foo 33 Bar".fromDisplayName -> "foo33Bar"
      "Foo XML".fromDisplayName -> "fooXML"
      "foo bar".fromDisplayName -> "fooBar"

      Parameters

      • self: string

      Returns string

    • Get the character at the zero based index as a Unicode code point. Negative indexes may be used to access from the end of the string. This method is accessed via the [] operator. Throw IndexErr if the index is out of range.

      Parameters

      • self: string
      • index: number

      Returns number

    • Return a substring based on the specified range. Negative indexes may be used to access from the end of the string. This method is accessed via the [] operator. Throw IndexErr if range illegal.

      Examples:

      "abcd"[0..2]   => "abc"
      "abcd"[3..3] => "d"
      "abcd"[-2..-1] => "cd"
      "abcd"[0..<2] => "ab"
      "abcd"[1..-2] => "bc"
      "abcd"[4..-1] => ""

      Parameters

      Returns string

    • Get the character at the zero based index as a Unicode code point. Negative indexes may be used to access from the end of the string. Unlike get, this method does not throw IndexErr when the index is out or range, instead it returns def.

      Parameters

      • self: string
      • index: number
      • Optionaldef: number

      Returns number

    • The hash for a Str is platform dependent.

      Parameters

      • self: string

      Returns number

    • Create an input stream to read characters from this string. The input stream is designed only to read character data. Attempts to perform binary reads will throw UnsupportedErr.

      Parameters

      • self: string

      Returns InStream

    • Return the first occurrence of the specified substring searching forward, starting at the specified offset index. A negative offset may be used to access from the end of string. Return null if no occurrences are found.

      Examples:

      "abcabc".index("b")     => 1
      "abcabc".index("b", 1) => 1
      "abcabc".index("b", 3) => 4
      "abcabc".index("b", -3) => 4
      "abcabc".index("x") => null

      Parameters

      • self: string
      • s: string
      • Optionaloffset: number

      Returns number

    • Find the index just like index, but ignoring case for ASCII chars only.

      Parameters

      • self: string
      • s: string
      • Optionaloffset: number

      Returns number

    • Reverse index - return the first occurrence of the specified substring searching backward, starting at the specified offset index. A negative offset may be used to access from the end of string. Return null if no occurrences are found.

      Examples:

      "abcabc".indexr("b")     => 4
      "abcabc".indexr("b", -3) => 1
      "abcabc".indexr("b", 0) => null

      Parameters

      • self: string
      • s: string
      • Optionaloffset: number

      Returns number

    • Find the index just like indexr, but ignoring case for ASCII chars only.

      Parameters

      • self: string
      • s: string
      • Optionaloffset: number

      Returns number

    • Internalize this Str such that two strings which are equal via the == operator will have the same reference such that === will be true.

      Parameters

      • self: string

      Returns string

    • Return if every char is an ASCII letter.

      Parameters

      • self: string

      Returns boolean

    • Return if every char is an ASCII alpha-numeric.

      Parameters

      • self: string

      Returns boolean

    • Return if every character in this Str is a US-ASCII character less than 128.

      Parameters

      • self: string

      Returns boolean

    • Return if size() == 0.

      Parameters

      • self: string

      Returns boolean

    • Return if every character in this Str is ASCII lowercase: a-'z'.

      Parameters

      • self: string

      Returns boolean

    • Return if every character in this Str is whitespace: space \t \n \r \f

      Parameters

      • self: string

      Returns boolean

    • Return if every character in this Str is ASCII uppercase: A-'Z'.

      Parameters

      • self: string

      Returns boolean

    • If size is less than width, then add spaces to the right to create a left justified string. Also see padr.

      Examples:

      "xyz".justl(2) => "xyz"
      "xyz".justl(4) => "xyz "

      Parameters

      • self: string
      • width: number

      Returns string

    • If size is less than width, then add spaces to the left to create a right justified string. Also see padl.

      Examples:

      "xyz".justr(2) => "xyz"
      "xyz".justr(4) => " xyz"

      Parameters

      • self: string
      • width: number

      Returns string

    • Return this string with the first character converted to uppercase using the current locale. Also see localeDecapitalize and capitalize.

      Parameters

      • self: string

      Returns string

    • Compare two strings without regard to case according to the current locale. Return -1, 0, or 1 if this string is less than, equal to, or greater than the specified string.

      Examples (assuming English locale):

      "a".localeCompare("b")   =>  -1
      "hi".localeCompare("HI") => 0
      "b".localeCompare("A") => 1

      Parameters

      • self: string
      • s: string

      Returns number

    • Return this string with the first character converted to lowercase using the current locale. Also see localeCapitalize and decapitalize.

      Parameters

      • self: string

      Returns string

    • Return this string with all uppercase characters replaced to lowercase using the current locale. Also see localeUpper, lower, and Int.localeLower.

      Parameters

      • self: string

      Returns string

    • Return this string with all lowercase characters replaced to uppercase using the current locale. Also see localeLower, upper, and Int.localeUpper.

      Parameters

      • self: string

      Returns string

    • Return this string with all uppercase characters replaced to lowercase. The case conversion is for ASCII only. Also see upper, localeLower, Int.lower, Int.localeLower.

      Example:

      "Apple".lower => "apple"
      

      Parameters

      • self: string

      Returns string

    • Duplicate this string the given number of times. Any integer less than or equal to zero returns an empty string.

      Examples:

      "x" * 4  =>  "xxxx"
      

      Parameters

      • self: string
      • times: number

      Returns string

    • Count the number of newline combinations: "\n", "\r", or "\r\n".

      Parameters

      • self: string

      Returns number

    • If size is less than width, then add the given char to the left to achieve the specified width. Also see justr.

      Examples:

      "3".padl(3, '0') => "003"
      "123".padl(2, '0') => "123"

      Parameters

      • self: string
      • width: number
      • Optionalchar: number

      Returns string

    • If size is less than width, then add the given char to the left to achieve the specified width. Also see justl.

      Examples:

      "xyz".padr(2, '.') => "xyz"
      "xyz".padr(5, '-') => "xyz--"

      Parameters

      • self: string
      • width: number
      • Optionalchar: number

      Returns string

    • Concat the value of obj.toStr

      Parameters

      Returns string

    • Replace all occurrences of from with to.

      Examples:

      "hello".replace("hell", "t")  =>  "to"
      "aababa".replace("ab", "-") => "a--a"

      Parameters

      • self: string
      • from$: string
      • to: string

      Returns string

    • Reverse the contents of this string.

      Example:

      "stressed".reverse => "desserts"
      

      Parameters

      • self: string

      Returns string

    • Return number of characters in this string.

      Parameters

      • self: string

      Returns number

    • Get a Str containing the specified number of spaces. Also see justl and justr to justify an existing string.

      Examples:

      Str.spaces(1)  =>  " "
      Str.spaces(2) => " "

      Parameters

      • n: number

      Returns string

    • Split a string into a list of substrings using the given separator character. If there are contiguous separators, then they are split into empty strings. If trim is true, then whitespace is trimmed from the beginning and end of the results.

      If separator is null, then the string is split according to any sequence of whitespace characters (any character equal to or less than the 0x20 space character including , \r, \n, and \t).

      If this is the empty string or there are no splits return a list of one item.

      Examples:

      // split on whitespace
      "".split => [""]
      "x".split => ["x"]
      "x y".split => ["x", "y"]
      " x y ".split => ["x", "y"]
      " x \n y \n z ".split => ["x", "y", "z"]

      // split on sep with trim
      "".split('|') => [""]
      "22".split(';') => ["22"]
      "22;33".split(';') => ["22","33"]
      "22, 33".split(',') => ["22","33"]
      " 22 ; 33 ".split(';') => ["22","33"]

      // split on sep with no trim
      "22#33".split('#', false) => ["22","33"]
      " x ; y".split(';', false) => [" x "," y"]

      Parameters

      • self: string
      • Optionalseparator: number
      • Optionaltrim: boolean

      Returns List<string>

    • Split this string into individual lines where lines are terminated by \n, \r\n, or \r. The returned strings do not contain the newline character.

      Examples:

      "x\ny".splitLines  => ["x", "y"]
      "".splitLines => [""]
      "x".splitLines => ["x"]
      "\r\n".splitLines => ["", ""]
      "x\n".splitLines => ["x", ""]

      Parameters

      • self: string

      Returns List<string>

    • Return if this Str starts with the specified Str.

      Parameters

      • self: string
      • s: string

      Returns boolean

    • Convenience for Bool.fromStr using this string.

      Parameters

      • self: string
      • Optionalchecked: boolean

      Returns boolean

    • Get this string encoded into a buffer of bytes.

      Parameters

      • self: string
      • Optionalcharset: Charset

      Returns Buf

    • Return this string as its Fantom source code and serialization representation surrounded by the specified quote character (which defaults to "). If quote is null then the return is unquoted. This method will backslash escape the following characters: \n \r \f \t \\ $. If the quote character is the double quote, single quote, or backtick then it is escaped too. Control chars less than 0x20 are escaped as \uXXXX. If escapeUnicode is true then any char over 0x7F is escaped as \uXXXX.

      Parameters

      • self: string
      • Optionalquote: number
      • OptionalescapeUnicode: boolean

      Returns string

    • Convenience for Decimal.fromStr using this string.

      Parameters

      • self: string
      • Optionalchecked: boolean

      Returns number

    • Translate a programmer name like "fooBar" to "Foo Bar". This method capitalizes the first letter, then walks the string looking for ASCII capital letters and inserting a space. Any underbars are replaced with a space. Also see fromDisplayName.

      Examples:

      "foo".toDisplayName       ->  "Foo
      "fooBar".toDisplayName -> "Foo Bar"
      "fooBarBaz".toDisplayName -> "Foo Bar Baz"
      "foo33".toDisplayName -> "Foo 33"
      "fooXML".toDisplayName -> "Foo XML"
      "Foo".toDisplayName -> "Foo"
      "foo_bar".toDisplayName -> "Foo Bar"

      Parameters

      • self: string

      Returns string

    • Convenience for Float.fromStr using this string.

      Parameters

      • self: string
      • Optionalchecked: boolean

      Returns number

    • Convenience for Int.fromStr using this string.

      Parameters

      • self: string
      • Optionalradix: number
      • Optionalchecked: boolean

      Returns number

    • Return this. This method is used to enable toLocale to be used with duck typing across most built-in types.

      Parameters

      • self: string

      Returns string

    • Convenience for Regex.fromStr using this string.

      Parameters

      • self: string

      Returns Regex

    • Return this.

      Parameters

      • self: string

      Returns string

    • Convenience for Uri.fromStr using this string.

      Parameters

      • self: string

      Returns Uri

    • Return this string as valid XML text. The special control characters amp, lt, apos and quot are always escaped. The gt char is escaped only if it is the first char or if preceded by the ] char. Also see OutStream.writeXml which is more efficient if streaming.

      Parameters

      • self: string

      Returns string

    • Trim whitespace from the beginning and end of the string. For the purposes of this method, whitespace is defined as any character equal to or less than the 0x20 space character (including , \r, \n, and \t).

      Examples:

      "foo".trim      =>  "foo"
      " foo".trim => "foo"
      " foo ".trim => "foo"
      " foo\n".trim => "foo"
      " ".trim => ""

      Parameters

      • self: string

      Returns string

    • Trim whitespace only from the end of the string. See trim for definition of whitespace.

      Examples:

      "foo".trim    =>  "foo"
      " foo ".trim => " foo"

      Parameters

      • self: string

      Returns string

    • Trim whitespace only from the beginning of the string. See trim for definition of whitespace.

      Examples:

      "foo".trim    =>  "foo"
      " foo ".trim => "foo "

      Parameters

      • self: string

      Returns string

    • Trim whitespace from the beginning and end of the string. Should the resultant string be empty, null is returned.

      For the purposes of this method, whitespace is defined as any character equal to or less than the 0x20 space character (including , \r, \n, and \t).

      Examples:

      "foo".trimToNull      =>  "foo"
      " foo ".trimToNull => "foo"
      "".trimToNull => null
      " ".trimToNull => null

      Parameters

      • self: string

      Returns string

    • Return this string with all lowercase characters replaced to uppercase. The case conversion is for ASCII only. Also see lower, localeUpper, Int.upper, Int.localeUpper.

      Example:

      "Foo Bar".upper => "FOO BAR"
      

      Parameters

      • self: string

      Returns string