BasicString

The BasicString is the generalization of struct string for character of type char, wchar or dchar.

BasicString use utf-8, utf-16 or utf-32 encoding.

BasicString use SSO (Small String Optimization).

Template parameters:

_Char Character type. (char, wchar or dchar).

_Allocator Type of the allocator object used to define the storage allocation model. By default DefaultAllocator is used.

N Minimal capacity of BasicString (increase max length of small string).

Members

Aliases

Storage
alias Storage = .Storage!(_Char, N, size_t, _allowHeap)
Undocumented in source.

Structs

BasicString
struct BasicString
Undocumented in source.

Variables

_allowHeap
enum bool _allowHeap;
Undocumented in source.

Examples

1 alias String = BasicString!(
2 	char,               //character type
3 	32,                 //additional padding to increas max size of small string (small string does not allocate memory).
4 	DefaultAllocator    //allocator type (can be stateless or with state)
5 );
6 
7 
8 //copy:
9 {
10 	String a = "123";
11 	String b = a;
12 
13 	a = "456"d;
14 
15 	assert(a == "456");
16 	assert(b == "123");
17 }
18 
19 
20 //append:
21 {
22 	String str = "12";
23 
24 	str.append("34");   //same as str += "34"
25 	str.append("56"w);  //same as str += "56"w
26 	str.append(7);      //same as str += 7;
27 	str.append('8');
28 
29 	assert(str == "12345678");
30 
31 	str.clear();
32 
33 	assert(str.empty);
34 }
35 
36 //erase:
37 {
38 	String str = "123456789";
39 
40 	str.erase(2, 2);
41 
42 	assert(str == "1256789");
43 }
44 
45 //insert:
46 {
47 	String str = "123456789";
48 
49 	str.insert(1, "xyz");
50 
51 	assert(str == "1xyz23456789");
52 }
53 
54 //replace:
55 {
56 	String str = "123456789";
57 
58 	str.replace(1, 2, "xyz");
59 
60 	assert(str == "1xyz456789");
61 }
62 
63 //slice to string:
64 ()@trusted{
65 	String str = "123456789";
66 
67 	const(char)[] dstr = str[];
68 
69 	assert(str == dstr);
70 }();

Meta