Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

dmd.root.string

Contains various string related functions.
Authors:
Walter Bright,https://www.digitalmars.com
License:
Boost License 1.0

Sourceroot/string.d

Documentationhttps://dlang.org/phobos/dmd_root_string.html

Coveragehttps://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/root/string.d

pure nothrow @nogc inout(char)[]toDString(inout(char)*s);
Slices a\0-terminated C-string, excluding the terminator
autofTuple(const(char)[]str);
Returns:
a (length, ptr) tuple for passing a D string toprintf-style functions with the format string%.*s
Examples:
import core.stdc.stdio: snprintf;char[6] buf = '.';const(char)[]str ="cutoff"[0..4];snprintf(buf.ptr, buf.length,"%.*s",str.fTuple.expand);assert(buf[] =="cuto\0.");
static pure nothrow @nogc booliequals(const(char)[]s1, const(char)[]s2);
Compare two slices for equality, in a case-insensitive way
Comparison is based onchar and does not do decoding.As a result, it's only really accurate for plain ASCII strings.
Parameters:
const(char)[]s1string to compare
const(char)[]s2string to compare
Returns:
true ifs1 ==s2 regardless of case
nothrow autotoCStringThen(alias dg)(const(char)[]src);
Copy the content ofsrc into a C-string ('\0' terminated) then calldg
The intent of this function is to provide an allocation-lessway to call a C function using a D slice.The function internally allocates a buffer if needed, but frees it on exit.

NoteThe argument todg isscope. To keep the data around afterdg exits,one has to copy it.

Parameters:
const(char)[]srcSlice to use to call the C function
dgDelegate to call afterwards
Returns:
The return value ofT
nothrow char[]toCString(scope const(char)[]s);
Convert a D string to a C string by allocating memory, copying it, and adding a terminating 0.
Parameters:
const(char)[]sstring to copy

Result0-terminated copy of s

pure nothrow @nogc @safe stringstripLeadingLineTerminator(stringstr);
Strips one leading line terminator of the given string.
The following are what the Unicode standard considers as line terminators:
NameD Escape SequenceUnicode Code Point
Line feed\nU+000A
Line tabulation\vU+000B
Form feed\fU+000C
Carriage return\rU+000D
Next lineU+0085
Line separatorU+2028
Paragraph separatorU+2029
This function will also strip\r\n.
@trusted intdstrcmp()(scope const char[]s1, scope const char[]s2);
A string comparison functions that returns the same result as strcmp

NoteStrings are compared based on their ASCII values, no UTF-8 decoding.

Some C functions (e.g.qsort) require aint result for comparison.

See Also:
Druntime'score.internal.string
char[N + 1]toStaticArray(size_t N)(scope const(char)[N]literal);
Infers the lengthN of a string literal and coerces its type to a static array with lengthN + 1. Returns the string with a null character appended to the end.
Parameters:
const(char)[N]literalstring literal

Notes

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");staticassert(e =="123\0");const empty ="".toStaticArray;staticassert(empty.length == 1);staticassert(empty[0] == '\0');
pure nothrow @nogc @system boolstartsWith(scope const(char)*p, scope const(char)[]needle);

pure nothrow @nogc @safe boolstartsWith(scope const(char)[]str, scope const(char)[]prefix);
Checks if C stringp starts withneedle.
Parameters:
const(char)*pthe C string to check
const(char)[]needlethe string to look for
Returns:
true ifp starts withneedle
Examples:
const 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"));
autosplitLines(const char[]text);
Taketext and turn it into an InputRange that emits slices intotext for each line.
Parameters:
char[]textarray of characters
Returns:
InputRange accessingtext as a sequence of lines

Referencestd.string.splitLines()

@safe FindSplitfindSplit(return scope const(char)[]str, scope const(char)[]needle);
Find a substring in a string and split the string into before and after parts.
Parameters:
const(char)[]strstring to look into
const(char)[]needlesubstring to find in str (must not be empty)
Returns:
aFindSplit object that casts totrue iffneedle was found insidestr. In that case,split[1] is the needle, andsplit[0]/split[2] are before/after the needle.
@safe const(char)[]findBetween(const(char)[]str, const(char)[]l, const(char)[]r);
Find a string inbetween two substrings
Parameters:
const(char)[]strstring to look into
const(char)[]lsubstring to find on the left
const(char)[]rsubstring to find on the right
Returns:
substring ofstr inbetweenl andr
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 06:40:37 2026

[8]ページ先頭

©2009-2026 Movatter.jp