Report a bug
If you spot a problem with this page, click here to create a GitHub 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 using
a local clone.
mir.small_string
Small String
The module contains self-contained generic small string implementaton.
SmallString supports ASDF - Json Serialisation Library.
See also include/mir/small_series.h for a C++ version of this type.
Both C++ and D implementations have the same ABI and name mangling.
Authors:
Ilia Ki
- struct
SmallString(uint maxLength) if (maxLength); - Self-contained generic Small String implementaton.Examples:
SmallString!16 s16; assert(s16.empty); auto s8 = SmallString!8("Hellow!!"); assert(s8 == "Hellow!!"); assert(s8[] == "Hellow!!"); assert(s8[0 .. $] == "Hellow!!"); assert(s8[1 .. 4] == "ell"); s16 = s8; assert(s16 == "Hellow!!"); s16[7] = '@'; s8 = null; assert(s8.empty); s8 = s16; assert(s8 == "Hellow!@"); auto s8_2 = s8; assert(s8_2 == "Hellow!@"); assert(s8_2 == s8); assert(s8 < "Hey"); assert(s8 > "Hellow!"); assert(s8.opCmp("Hey") < 0); assert(s8.opCmp(s8) == 0);
Examples:Concatenationauto a = SmallString!16("asdf"); a ~= " "; auto b = a ~ "qwerty"; static assert(is(typeof(b) == SmallString!16)); assert(b == "asdf qwerty"); b.put('!'); b.put("!"); assert(b == "asdf qwerty!!");
- this(typeof(null)) scope;
this(scope const(char)[]str) scope;
this(uint n)(auto ref scope const SmallString!nstr) scope;
this(Range)(auto ref scope Rangestr) scope
if (isIterable!Range); - Constructor
- ref typeof(this)
opAssign(typeof(null)) scope return;
ref @trusted typeof(this)opAssign(scope const(char)[]str) scope return;
ref typeof(this)opAssign(uint n)(auto ref scope const SmallString!nrhs) scope return
if (n != maxLength);
ref typeof(this)opAssign(uint n)(const SmallString!nrhs) scope return
if (n != maxLength);
nothrow @trusted voidtrustedAssign(scope const(char)[]str) return; - = operator
- ref @trusted typeof(this)
append(charc); - ref @trusted typeof(this)
append(scope const(char)[]str);
aliasput= append;
templateopOpAssign(string op : "~") - const SmallString
concat(scope const(char)[]str) scope;
templateopBinary(string op : "~") - const nothrow @safe size_t
toHash(); - inout @trusted inout(char)[]
opIndex() scope return; - Returns an scope common string.The method implement with [] operation.
- inout ref inout(char)
opIndex(size_tindex) scope return; - inout @trusted inout(char)[]
opIndex(size_t[2]range) scope return;
size_t[2]opSlice(size_t pos : 0)(size_ti, size_tj); - Returns a common scope string.The method implement with [
i..j] operation. - @property bool
empty(); - @property size_t
length();
templateopDollar(size_t pos : 0) - alias
toString= opIndex; - bool
opEquals(ref scope const SmallStringrhs);
boolopEquals(SmallStringrhs);
boolopEquals(uint rhsMaxLength)(auto ref scope const SmallString!rhsMaxLengthrhs)
if (rhsMaxLength != maxLength);
boolopEquals()(scope const(char)[]str);
intopCmp(uint rhsMaxLength)(auto ref scope const SmallString!rhsMaxLengthrhs);
intopCmp()(scope const(char)[]str); - Comparisons operator overloads
Copyright © 2016-2026 by Ilya Yaroshenko | Page generated by
Ddoc on Wed Apr 8 13:47:04 2026