SubString (クラス)
public SubString {inherits StringInterface}
パッケージ: CURL.LANGUAGE.STRINGS

StringInterface オブジェクトの軽量ラッパーで、StringInterface の部分文字列を表現します。

説明

通常、StringInterface.substr を呼び出して新しい String を割り当てて返すより、SubString オブジェクトの方がスペース効率がよくなります (文字列が非常に小さい場合を除く)。


StringInterface.substr よりも SubString を優先して使用する場合、不都合な点が 2 つあります。
  1. ほとんどの SubString メソッドは、String で呼び出される同じメソッドより処理速度が多少遅くなります。
  2. SubString s には、作成された元の rep (StringInterface) への参照が含まれます。該当する repWritableString (StringBuf など) で、誰かが rep の内容またはサイズを変更した場合、変更結果は警告なしで s に現れます。rep が縮小された場合、s が不正に変形する可能性もあります。その結果、s[i] を呼び出すと、0 <= i < s.size の範囲にある i に対して例外がスローされることになります。

コンストラクタ
default:SubString を初期化します。
コンストラクタ public {SubString.default rep:StringInterface, start:int, length:int}

プロパティ
for-loop-count:for ループで使用されます。
アクセサ public final inline SubString.for-loop-count:int
length:部分文字列の長さ。
フィールド protected constant SubString.length:int
rep:部分文字列の基になる表現。
フィールド protected constant SubString.rep:StringInterface
size:self 内の文字数。
アクセサ public final inline SubString.size:int
start:元の表現内での部分文字列の開始位置を示します。
フィールド protected constant SubString.start:int
プロパティ 継承 StringInterface: empty?

メソッド
clone:
public {SubString.clone}:SubString
get:self 内の指定された文字を返します。
public final inline {SubString.get index:int}:char
substr:self の指定された部分文字列を返します。
public {SubString.substr start:int, length:int}:String
to-String:self と同一 (==) の String を作成します。
public {SubString.to-String}:String
メソッド 継承 StringInterface: compare, equal?, find, find-char-class, find-string, prefix?, replace-clone, split, suffix?, tail, to-double, to-InputStream, to-int, to-int64, to-lower-clone, to-upper-clone, trim-clone, trim-left-clone, trim-right-clone
メソッド 継承 Object: object-describe, object-describe-for-debugging, object-serialize



コンストラクタ詳細
default (コンストラクタ)
public {SubString.default rep:StringInterface, start:int, length:int}

SubString を初期化します。

注意事項

start または start + length が範囲外を指している場合、このメソッドは ArrayBoundsException をスローします。
rep: self の派生元となる下位の StringInterface
start: self 内のインデックス 0 に対応する、rep 内の開始インデックス。
length: selfの長さ。



プロパティ詳細
for-loop-count (アクセサ)
アクセサ public final inline SubString.for-loop-count:int

for ループで使用されます。



length (フィールド)
protected constant SubString.length:int

部分文字列の長さ。

説明

SubString.default コンストラクタも参照してください。


rep (フィールド)
protected constant SubString.rep:StringInterface

部分文字列の基になる表現。

説明

これは、部分文字列を構成する文字の格納場所を指します。
SubString.default コンストラクタも参照してください。


size (アクセサ)
アクセサ public final inline SubString.size:int

self 内の文字数。

戻り値

文字数を示す int 値。

説明

読み取り専用文字列の場合 書き込み可能文字列の場合 size をその文字列の現在のサイズよりも小さい値に設定した場合、その文字列は切り詰められます。size を現在のサイズよりも大きい値に設定した場合、差分の文字数がその文字列の末尾に追加されます。この場合、追加される文字の値は Unicode 値の 0000 になります。

次の例は、読み取り専用文字列に対して size を使用した場合です。


{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.}
}


次の例は、書き込み可能文字列に対して size を使用した場合です。


{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}}
}



{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}}
}

注意事項

これは StringInterface の抽象ゲッターです。このゲッターは StringInterface のサブクラスによって実装されます。


start (フィールド)
protected constant SubString.start:int

元の表現内での部分文字列の開始位置を示します。

説明

これは、rep 内で部分文字列が開始する文字オフセット位置です。
SubString.default コンストラクタも参照してください。





メソッド詳細
clone (メソッド)
public {SubString.clone}:SubString
この項目はサポートされていません。内部使用限定となっています。


get (メソッド)
public final inline {SubString.get index:int}:char

self 内の指定された文字を返します。

index: 取得する文字の位置。最左端の文字の位置は 0 です。最右端の文字の位置は (self.size - 1) です。有効値は 0(self.size - 1) の範囲です (0(self.size - 1) を含む)。

例外のスロー

index が範囲外の場合は ArrayBoundsException をスローします。


{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}.}
}

注意事項

これは StringInterface の抽象メソッドです。このメソッドは StringInterface のサブクラスによって実装されます。


substr (メソッド)
public {SubString.substr start:int, length:int}:String

self の指定された部分文字列を返します。

start: self 内における部分文字列の開始位置。最左端の文字の位置は 0 です。最右端の文字の位置は (self.size - 1) です。有効値は 0 ~ (self.size - 1) の範囲です (0 と (self.size - 1) を含む)。
length: 部分文字列の長さ。つまり、部分文字列内の文字数です。

戻り値

self の指定された部分文字列が格納された String。この部分文字列は、start の位置から始まる length 個の連続した文字です。

注意事項

start または start + length が範囲外を指している場合、このメソッドは ArrayBoundsException をスローします。


{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}
}

注意事項

クローン作成の詳細については、『Curl 開発者ガイド』の「文字列クローンの操作」のセクションを参照してください。


to-String (メソッド)
public {SubString.to-String}:String

self と同一 (==) の String を作成します。

戻り値

self 内の文字を含む String


{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}
}