英語版
このページの英語版を見る
dmd.root.string
文字列に関連するさまざまな関数を含む。
Authors:
Walter Bright, https://www.digitalmars.com
License:
適用範囲 https://codecov.io/gh/dlang/dmd/src/master/src/dmd/root/string.d
- pure nothrow @nogc inout(char)[]
toDString
(inout(char)*s
); - \0 で終端する C 文字列を分割し、終端文字を除く
- static pure nothrow @nogc bool
iequals
(const(char)[]s1
, const(char)[]s2
); - 2つのスライスを大文字小文字を区別せずに等価であるか比較する比較はchar に基づいており、デコードは行われない。 そのため、ASCII文字列のみが正確に比較される。Parameters:
const(char)[] s1
比較する文字列 const(char)[] s2
比較する文字列 Returns:trues1
==s2
大文字小文字を区別せずに - nothrow auto
toCStringThen
(alias dg)(const(char)[]src
); - 内容をコピーする
src
C文字列('¥0'で終端)にコピーし、その後、dgを呼び出す。この関数の目的は、 Dスライスを使用してC関数を呼び出す際に、メモリ確保を不要にする ことである。この関数は必要に応じて内部的にバッファを確保するが、終了時にバッファを解放する。注釈 dg への引数はscope である。dg が終了した後もデータを保持するには、 データをコピーする必要がある。
Parameters:const(char)[] src
C関数を呼び出すために使用するスライス dg その後呼び出すために委任する Returns:戻り値のT - nothrow char[]
toCString
(scope const(char)[]s
); - D文字列をメモリを確保し、 コピーし、終端文字0を追加して、C文字列に変換する。Parameters:
const(char)[] s
コピーする文字列 戻り値 0で終端するsのコピー
- pure nothrow @nogc @safe string
stripLeadingLineTerminator
(stringstr
); - 与えられた文字列の最初の行終端文字を削除する。Unicode標準で改行文字として認められているものは以下の通りである。
この関数は、\r\n も削除する。Name D Escape Sequence Unicode Code Point 改行 \n U+000A 行タブ \v U+000B フォームフィード \f U+000C キャリッジリターン \r U+000D 次の行 U+0085 改行 U+2028 段落区切り U+2029 - @trusted int
dstrcmp
()(scope const char[]s1
, scope const char[]s2
); - 文字列比較関数は、strcmpと同じ結果を返す
注釈 文字列は、UTF-8 のデコードを行わずに ASCII 値に基づいて比較される。
いくつかの C 関数(例:qsort )では、比較を行う際にint の結果が必要となる。See Also:Druntimeのcore.internal.string - char[N + 1]
toStaticArray
(size_t N)(scope const(char)[N]literal
); - 文字列リテラルの長さN を推測し、その型を長さN + 1 の静的配列に強制する。 最後にヌル文字を付加した文字列を返す。Parameters:
const(char)[N] literal
文字列リテラル backup URLバックアップURL注釈
- LDCは短い文字列に対して非常に最適化されたコードを生成する。
- https://d.godbolt.org/z/M69Z1g
- https://gist.github.com/PetarKirov/338e4ab9292b6b2b311a3070572a07fb(バックアップ用URL)
Examples:auto m = "123".toStaticArray; const c = "123".toStaticArray; immutable i = "123".toStaticArray; enum e = "123".toStaticArray; assert(m == "123\0"); assert(c == "123\0"); assert(i == "123\0"); static assert(e == "123\0"); const empty = "".toStaticArray; static assert(empty.length == 1); static assert(empty[0] == '\0');
- LDCは短い文字列に対して非常に最適化されたコードを生成する。
- pure nothrow @nogc @system bool
startsWith
(scope const(char)*p
, scope const(char)[]needle
);
pure nothrow @nogc @safe boolstartsWith
(scope const(char)[]str
, scope const(char)[]prefix
); - C文字列が
p
始まっているかを確認するneedle
。Parameters:const(char)* p
C文字列をチェックする const(char)[] needle
文字列を検索する Returns:iftruep
needle
Examples:Takeconst buf = "123".toStaticArray; const ptr = &buf[0]; assert(ptr.startsWith("")); assert(ptr.startsWith("1")); assert(ptr.startsWith("12")); assert(ptr.startsWith("123")); assert(!ptr.startsWith("1234"));
- auto
splitLines
(const char[]text
); - 取得し、それを InputRange に変換してスライスを発行する。
text
それを InputRange に変換し、 各行に対してスライスをtext
各行に対してParameters: 文字の配列char[] text
文字の配列 Returns: InputRangeにアクセスするInputRangeにアクセスするtext
行のシーケンスとしてアクセスする参照std.string.
splitLines
() - FindSplit
findSplit
(return scope const(char)[]str
, scope const(char)[]needle
); - 文字列の中から部分文字列を見つけ、文字列を前と後ろの部分に分割する。Parameters:
const(char)[] str
調べる文字列 const(char)[] needle
strで検索する部分文字列(空であってはならない) Returns: xml-ph-0001@deepl.internal にキャストする xml-ph-0000@deepl.internal オブジェクト。ただし、xml-ph-0001@deepl.internal にキャストできる場合のみ。true にキャストするFindSplit オブジェクト。needle
見つかった場合、str
。 その場合、split[1] が針、split[0]/split[2] が針の前後となる。 - const(char)[]
findBetween
(const(char)[]str
, const(char)[]l
, const(char)[]r
); - 2つの文字列の間の文字列を見つけるParameters: 文字列を調べる
const(char)[] str
文字列を調べる const(char)[] l
左側で検索する部分文字列 const(char)[] r
右側にある部分文字列 Returns:str
中間にあるl
。r
Copyright © 1999-2024 by the D Language Foundation
DEEPL APIにより翻訳、ところどころ修正。
このページの最新版(英語)
このページの原文(英語)
翻訳時のdmdのバージョン: 2.109.1
ドキュメントのdmdのバージョン: 2.109.1
翻訳日付 :
HTML生成日時:
編集者: dokutoku