The OpenD Programming Language

SmallString

Self-contained generic Small String implementaton.

Constructors

this
this(typeof(null) )
this(const(char)[] str)
this(SmallString!n str)
this(Range str)

Constructor

Members

Aliases

opBinary
alias opBinary(string op : "~") = concat
opDollar
alias opDollar(size_t pos : 0) = length
opOpAssign
alias opOpAssign(string op : "~") = append
put
alias put = append
toString
alias toString = opIndex

Functions

append
typeof(this) append(char c)
append
typeof(this) append(const(char)[] str)
concat
SmallString concat(const(char)[] str)
empty
bool empty()
length
size_t length()
opAssign
typeof(this) opAssign(typeof(null) )
typeof(this) opAssign(const(char)[] str)
typeof(this) opAssign(SmallString!n rhs)

= operator

opCmp
int opCmp(const(char)[] str)
int opCmp(SmallString!rhsMaxLength rhs)

Comparisons operator overloads

opEquals
bool opEquals(SmallString rhs)
bool opEquals(SmallString!rhsMaxLength rhs)
bool opEquals(const(char)[] str)

Comparisons operator overloads

opIndex
inout(char)[] opIndex()

Returns an scope common string.

opIndex
inout(char) opIndex(size_t index)
opIndex
inout(char)[] opIndex(size_t[2] range)
opSlice
size_t[2] opSlice(size_t i, size_t j)

Returns a common scope string.

toHash
size_t toHash()
trustedAssign
void trustedAssign(const(char)[] str)

= operator

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);

Concatenation

auto 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!!");

Meta