StringBuf (クラス)
public final StringBuf {inherits WritableString, TextOutputStream}
パッケージ: CURL.LANGUAGE.STRINGS

文字 (char) の書き込み可能文字列。

注意事項

以下に、Curl の文字列クラスの階層を示します。
Curl の文字列に関する詳細は、Curl 開発者ガイド: 文字列 を参照してください。

プログラミング注意事項

コンストラクタ
{StringBuf ...}
は、各引数の String 式を連結した StringBuf を作成します。すべての残余引数に対する String 式が連結され、新しい StringBuf オブジェクト内に初期文字が形成されます。各 rest-arg に対する String 式を取得するには、{format "%s", rest-arg} を呼び出すか、またはより高速な同等の処理を実行します。

注意事項

文字が StringBuf に追加されると、その基本となるメモリ表現は Array-of と同じアルゴリズムを使用して拡大されます。

注意事項

StringBuf のほとんどのユーザーは、文字がメモリで表現される方法について考慮する必要はありませんが、上級ユーザーにはこの情報が役立つ場合があります。
スペースを最適化するには、StringBuf 内の文字は、それまで StringBuf 内に格納されていた「一番大きな」文字に基づいて、char あたり 1、2、または 4 バイトのいずれかを含む FastArray-of に格納されます。
たとえば、StringBuf は 1 文字あたり 1 バイトを使用して開始しますが、'\u1234' など、1 バイトとならない文字値の場合は、StringBuf に格納され、1 文字あたり 2 バイトを使用した表示に切り替えます。同様に、'\U00010000' などの非常に大きな値は 1 文字あたり 4 バイトに強制的に切り替えます。
メモリ表現は、すべての「大きな」 unicode 文字が削除される場合、自動的に小さなサイズに切り替えられることはありません。文字あたり 1 バイトを使用するよう StringBuf をリセットする唯一の方法は、すべての文字を削除して (StringBuf.clear を使用可能) 、その efficient-size を 0 に設定することです。

コンストラクタ
default:StringBuf を初期化します。
コンストラクタ public {StringBuf.default
size:int = 0,
efficient-size:int = 0,
...:any
}

プロパティ
efficient-size:selfefficient-size を取得または設定します。
アクセサ public final StringBuf.efficient-size:int
セッター public final StringBuf.efficient-size:int
for-loop-count:文字列に対して繰り返し処理を実行するコンテナである for ループが出現したときに Curl コンパイラが使うゲッター。
アクセサ public final StringBuf.for-loop-count:int
non-blocking-supported?:特定のインスタンスまたはサブクラスが non-blocking? フラグをサポートし、InputStream-of.read または OutputStream-of.write のようなメソッドで使用できるかどうかを示します。
アクセサ public StringBuf.non-blocking-supported?:bool
open?:ダミー アクセッサ。
アクセサ public final inline StringBuf.open?:bool
origin-url:このストリームを開いた Url を返します。そのような Url が存在しない場合は null を返します。
アクセサ public StringBuf.origin-url:#Url
size:self 内の文字数。
アクセサ public final StringBuf.size:int
セッター public final StringBuf.size:int
write-buffer-data-size:バッファ内のフラッシュされていないデータ量を示します。
アクセサ public StringBuf.write-buffer-data-size:int
write-buffer-size:最大バッファ サイズを示します。
アクセサ public StringBuf.write-buffer-size:int
プロパティ 継承 TextOutputStream: character-encoding
プロパティ 継承 StringInterface: empty?
プロパティ 継承 BufferedOutputStream-of: write-buffer-full?

メソッド
append:文字を self の末尾に追加します。
public final {StringBuf.append c:char}:void
clear:self をクリアします。
public final {StringBuf.clear}:void
clone:
public {StringBuf.clone}:StringBuf
close:ダミー メソッド。
public final {StringBuf.close}:void
concat:StringInterfaceself に連結します。
public final {StringBuf.concat str:StringInterface}:void
equal?:self と、指定された StringInterface が等しいかどうかを検査します。
public {StringBuf.equal?
str:StringInterface,
ignore-case?:bool = false
}:bool
flush:ダミー メソッド。
public final {StringBuf.flush
non-blocking?:bool = false,
allow-short-write?:bool = false
}:void
get:self 内の指定された文字を返します。
public final {StringBuf.get index:int}:char
insert:文字を self に挿入します。
public final {StringBuf.insert c:char, index:int}:void
remove:指定された文字を self から削除します。
public {StringBuf.remove
index:int,
length:int = 1,
error-if-missing?:bool = true
}:void
reverse:self 内の文字の順序を逆にします。
public {StringBuf.reverse}:void
set:self 内の文字を置換します。
public final {StringBuf.set index:int, c:char}:void
substr:self の指定された部分文字列を返します。
public {StringBuf.substr start:int, length:int}:String
to-String:self と同一 (==) の String を作成します。
public {StringBuf.to-String}:String
write-one:文字を self の末尾に追加します。
public final {StringBuf.write-one c:char}:void
write-one-string:StringInterface または StringInterface の一部を self に連結します。
public final {StringBuf.write-one-string
str:StringInterface,
start:int = 0,
length:int = str.size - start
}:int
メソッド 継承 WritableString: replace, set-contents, splice, to-lower, to-upper, trim, trim-left, trim-right
メソッド 継承 StringInterface: compare, 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
メソッド 継承 OutputStream-of: async-write, write
メソッド 継承 Stream-of: verify-open
メソッド 継承 Object: object-describe, object-describe-for-debugging, object-serialize



コンストラクタ詳細
default (コンストラクタ)
public {StringBuf.default
size:int = 0,
efficient-size:int = 0,
...:any
}

StringBuf を初期化します。

size: Curl は、StringBuf の内容を FastArray に格納します。このパラメータは、その FastArray の初期サイズを示します。

size が指定されてもその値が小さすぎて残余引数に対する出力式を格納できない場合、このコンストラクタは ArrayBoundsException をスローします。
efficient-size: Curl は、StringBuf の内容を FastArray に格納します。このパラメータは、FastArray の初期サイズの上限の推奨値を示します。このパラメータの値は、システム内で適切な値に調整されます。既定では、システムによって適切な値が決まります。
...: この残余引数には、文字列の要素が含まれています。

注意事項

size が指定されてもその値が小さすぎて残余引数に対する出力式を格納できない場合、このコンストラクタは ArrayBoundsException をスローします。



プロパティ詳細
efficient-size (アクセサ)
アクセサ public final StringBuf.efficient-size:int
セッター public final StringBuf.efficient-size:int

selfefficient-size を取得または設定します。

説明

efficient-size は、self が効率的に拡張できるサイズの上限です。サイズがこの efficient-size を超えた場合、基本データ構造が新規に割り当てられたときにパフォーマンスが低下します。サイズ拡張は、他のメソッド (例:size の設定) によって実行されます。
requested-size: requested-size はシステムによって評価され、場合によっては変更されます。変更後の efficient-size を取得するには、ゲッターを使います。変更後の efficient-size は必ず requested-size 以上の大きさになります。


for-loop-count (アクセサ)
アクセサ public final StringBuf.for-loop-count:int

文字列に対して繰り返し処理を実行するコンテナである for ループが出現したときに Curl コンパイラが使うゲッター。

注意事項

このゲッターを直接呼び出さないでください。このゲッターは、Curl コンパイラによってのみ使われるよう用意されているものです。


non-blocking-supported? (アクセサ)
アクセサ public StringBuf.non-blocking-supported?:bool

特定のインスタンスまたはサブクラスが non-blocking? フラグをサポートし、InputStream-of.read または OutputStream-of.write のようなメソッドで使用できるかどうかを示します。

注意事項

また、これにより、InputStream-of または OutputStream-of 内のメソッドの既定実装は、呼び出すメソッド InputStream-of.read-one または OutputStream-of.write-one がどんな場合でもブロックしないものと仮定します。それらのメソッドが特定のサブクラスでブロックできる場合は、Stream-of.non-blocking-supported?false のままでいるか、InputStream-of.read または OutputStream-of.write の既定実装をオーバーライドしてブロック不可サポートを提供するようにする必要があります。


open? (アクセサ)
アクセサ public final inline StringBuf.open?:bool

ダミー アクセッサ。

説明

このアクセッサは OutputStream-of.open? をオーバーライドします。このアクセッサにはコードは含まれておらず、true を返します。つまり、文字列は常にオープンされていると見なされます。ストリーム コードが open? を呼び出した場合、正しいアクションが実行されます。


origin-url (アクセサ)
アクセサ public StringBuf.origin-url:#Url

このストリームを開いた Url を返します。そのような Url が存在しない場合は null を返します。

{read-open {url "file://c:/foo.txt"}}.origin-url Url file://c:/foo.txt (そのようなファイルが存在すると仮定して) を返します。

一方、{{TextInputStream-from String} "foo"}.origin-urlnull を返します。


size (アクセサ)
アクセサ public final StringBuf.size:int
セッター public final StringBuf.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 のサブクラスによって実装されます。


write-buffer-data-size (アクセサ)
アクセサ public StringBuf.write-buffer-data-size:int

バッファ内のフラッシュされていないデータ量を示します。



write-buffer-size (アクセサ)
アクセサ public StringBuf.write-buffer-size:int

最大バッファ サイズを示します。






メソッド詳細
append (メソッド)
public final {StringBuf.append c:char}:void

文字を self の末尾に追加します。

c: 追加する文字。

説明

文字 cself の末尾に追加します。


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

    || Append an exclamation mark (!).
    {sb.append '!'}

    || Display the resulting StringBuf.
    {value sb}
}


clear (メソッド)
public final {StringBuf.clear}:void

self をクリアします。

説明

self の内容を空の文字列に置き換えます。


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

    || Clear the StringBuf.
    {sb.clear}

    || Check if the StringBuf is empty.
    {text The assertion that the string is empty
        is... {value sb.empty?}}
}


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


close (メソッド)
public final {StringBuf.close}:void

ダミー メソッド。

説明

このメソッドは OutputStream-of.close をオーバーライドします。このメソッドにはコードは含まれておらず、void を返します。ストリーム コードが close を呼び出した場合、正しいアクションが実行されます。

注意事項

self.close が呼び出された場合、何のアクションも実行されません。つまり、その後に write-one を呼び出した場合、その呼び出しは成功します。


concat (メソッド)
public final {StringBuf.concat str:StringInterface}:void

StringInterfaceself に連結します。

str: StringInterface を連結する文字。このオブジェクトのデータ型は self と同じでなければなりません。

説明

strself の末尾に追加します。


{value
    || Declare and initialize two StringBufs.
    let sb1:StringBuf = {StringBuf "Hello World!"}
    let sb2:StringBuf = {StringBuf " Can you hear me?"}

    || Concatenate "sb2" onto "sb1".
    {sb1.concat sb2}

    || Display the resulting StringBuf.
    {value sb1}
}


equal? (メソッド)
public {StringBuf.equal?
str:StringInterface,
ignore-case?:bool = false
}:bool

self と、指定された StringInterface が等しいかどうかを検査します。

str: 等しいかどうか比較する StringInterface
ignore-case?: 検査時に大文字と小文字の区別を無視するかどうかを示すキーワード引数。既定では、大文字と小文字の区別は無視されません (ignore-case? = false)。つまり、既定では大文字と小文字は区別されます。たとえば、"abcdefg""ABCDEFG" は等しくありません。

ignore-case? はキーワード引数です。ignore-case? を指定するには、メソッド呼び出しのキーワードに対して適切な値を設定します (例:ignore-case? = true)。

ignore-case?true を設定した場合、検査時に大文字と小文字は区別されません。この場合、"abcdefg""ABCDEFG" は等しいと評価されます。

戻り値

bool 値。self 内の各文字が str 内の対応する文字と等しい場合、true を返します。それ以外の場合は、false を返します。


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


flush (メソッド)
public final {StringBuf.flush
non-blocking?:bool = false,
allow-short-write?:bool = false
}:void

ダミー メソッド。

説明

このメソッドは OutputStream-of.flush をオーバーライドします。このメソッドにはコードは含まれておらず、void を返します。ストリーム コードが flush を呼び出した場合、正しいアクションが実行されます。


get (メソッド)
public final {StringBuf.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 のサブクラスによって実装されます。


insert (メソッド)
public final {StringBuf.insert c:char, index:int}:void

文字を self に挿入します。

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

説明

位置 index より後ろにあるすべての文字を 1 つずつ後ろにずらし、位置 index に文字 c を挿入します。


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

    || Insert a comma (,) at position 5.
    || Remember that the leftmost position
    || is 0 (zero).
    {sb.insert ',', 5}

    || Display the resulting StringBuf.
    {value sb}
}

注意事項

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


remove (メソッド)
public {StringBuf.remove
index:int,
length:int = 1,
error-if-missing?:bool = true
}:void

指定された文字を self から削除します。

index: 文字の削除を開始する位置。最左端の文字の位置は 0 です。最右端の文字の位置は (self.size - 1) です。有効値は 0self.size の範囲です (0self.size を含む)。
length: 削除する文字数。length の既定値は 1 です。length はキーワード引数です。length を指定するには、メソッド呼び出しのキーワードに対して適切な値を設定します (例:length = 6)。
error-if-missing?:
存在しない文字を削除しようとしたときにこのメソッドがエラーを生成するかどうかを示す、ブール値のフラグ。位置 0 と self.size の間の文字を削除できます。
error-if-missing?true に設定した場合、存在しない文字を削除しようとするとエラーがスローされます。エラーが発生するとプログラムの実行が停止し、エラー メッセージが表示されます。既定では、error-if-missing?true です。error-if-missing?false に設定した場合、エラーは生成されません。また、有効な範囲内にある文字は削除されますが、有効な範囲内にない文字は削除されず、削除後の文字列が返されます。
error-if-missing? はキーワード引数です。error-if-missing? を指定するには、メソッド呼び出しのキーワードに対して適切な値を設定します (例:error-if-missing? = false)。

説明

self から length 個の文字を削除します。削除開始位置は index です。


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

    || Remove 6 characters, starting at
    || position 5.
    || Remember that the leftmost position
    || is 0 (zero).
    {sb.remove 5, length = 6}

    || Display the resulting StringBuf.
    {value sb}
}

注意事項

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


reverse (メソッド)
public {StringBuf.reverse}:void

self 内の文字の順序を逆にします。


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

    || Reverses the order of the characters
    {sb.reverse}

    || Display the resulting StringBuf
    {value sb}
}

注意事項

このメソッドは、self に格納されている個々の char の順序を逆にします。Unicode 文字列の意味はその表現の個々の char の順序に依存するので、このメソッドは元の文字列を反転したものを生成しません。
例えば、文字シーケンス "\u305D\u3099\u305F" によって表される文字列は "\u305E\u305F" (ZO-TA) と同じですが、反転されると "\u3060\u305D" (SO-DA) と同じものになります。


set (メソッド)
public final {StringBuf.set index:int, c:char}:void

self 内の文字を置換します。

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

説明

位置 index にある文字を c に置換します。


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

    || Replace character 11 (!) with a period (.).
    || Remember that the leftmost position
    || is 0 (zero).
    {sb.set 11, '.'}

    || Display the resulting StringBuf.
    {value sb}
}

注意事項

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


substr (メソッド)
public {StringBuf.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 {StringBuf.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}
}


write-one (メソッド)
public final {StringBuf.write-one c:char}:void

文字を self の末尾に追加します。

obj: 追加する文字。

説明

文字 objself の末尾に追加します。


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

    || Append an exclamation mark (!)
    {sb.write-one '!'}

    || Display the resulting StringBuf
    {value sb}
}


write-one-string (メソッド)
public final {StringBuf.write-one-string
str:StringInterface,
start:int = 0,
length:int = str.size - start
}:int

StringInterface または StringInterface の一部を self に連結します。

str: 連結する StringInterface
start: 連結を開始する str 内の位置。最左端の文字の位置は 0 です。最右端の文字の位置は (self.size - 1) です。有効値は 0self.size の範囲です (0self.size を含む)。start の既定値は 0 です。つまり、既定では str の先頭から連結が開始されます。
length: 連結される str の文字数。

戻り値

self の末尾に連結された str の文字数を示す int。この値は、length と同じになるはずです。

注意事項

start または start + lengthstr の境界を超える場合、または、length が負である場合は、ArrayBoundsException がスローされます。


{value
    || Declare and initialize two StringBufs.
    let sb1:StringBuf = {StringBuf "Hello World!"}
    let sb2:StringBuf = {StringBuf " Can you hear me?"}

    || Declare a variable to hold the return
    || value from the method call.
    let i:int

    || Write "sb2" onto "sb1"
    set i = {sb1.write-one-string sb2}

    || Display a message indicating the resulting
    || StringBuf.
    {text {value i} characters were added to create the string:
        {br}{value sb1}}
}