forked from ldc-developers/ldc
-
Notifications
You must be signed in to change notification settings - Fork 10
/
string.d
44 lines (34 loc) · 903 Bytes
/
string.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// RUN: %ldc -cpp-cachedir=%t.cache -of %t %s
// RUN: %t > %t.out
// RUN: FileCheck %s < %t.out
/**
* std::string example.
*/
module _string_;
pragma (cppmap, "<string>");
import std.stdio, std.conv;
import (C++) std.string : cppstring = string;
void main()
{
cppstring s;
immutable char[] charArray = "Haumea";
s.reserve(charArray.length * 2);
s.insert(0, charArray.ptr, charArray.length);
writeln(s.c_str.to!string);
// CHECK: Haumea
writeln("3rd and 5th characters: ", s[2], ", ", s[4]);
// CHECK: 3rd and 5th characters: u, e
writeln("Size: ", s.size);
// CHECK: Size: 6
writeln("Capacity: ", s.capacity);
// CHECK: Capacity: 15
auto s2 = cppstring("Hi'iaka");
s += ',';
s.push_back(' ');
s += s2;
s.insert(0, "< ");
s += " >".ptr;
writeln(s.c_str.to!string);
// CHECK: < Haumea, Hi'iaka >
s.clear();
}