0
|
1 module dmd.Lstring;
|
|
2
|
|
3 import dmd.Dchar;
|
|
4
|
|
5 struct Lstring
|
|
6 {
|
|
7 immutable(dchar_t)[] string_;
|
|
8
|
|
9 static Lstring zero; // 0 length string
|
|
10
|
|
11 // No constructors because we want to be able to statically
|
|
12 // initialize Lstring's, and Lstrings are of variable size.
|
|
13
|
|
14 version (M_UNICODE) {
|
|
15 ///#define LSTRING(p,length) { length, L##p }
|
|
16 } else {
|
|
17 ///#define LSTRING(p,length) { length, p }
|
|
18 }
|
|
19
|
|
20 ///#if __GNUC__
|
|
21 /// #define LSTRING_EMPTY() { 0 }
|
|
22 ///#else
|
|
23 /// #define LSTRING_EMPTY() LSTRING("", 0)
|
|
24 ///#endif
|
|
25
|
|
26 static Lstring* ctor(const(dchar_t)* p) { return ctor(p, Dchar.len(p)); }
|
|
27
|
|
28 static Lstring* ctor(const(dchar_t)* p, uint length)
|
|
29 {
|
|
30 assert(false);
|
|
31 }
|
|
32
|
|
33 static uint size(uint length) { return Lstring.sizeof + (length + 1) * dchar_t.sizeof; }
|
|
34
|
|
35 static Lstring* alloc(uint length)
|
|
36 {
|
|
37 assert(false);
|
|
38 }
|
|
39
|
|
40 Lstring* clone()
|
|
41 {
|
|
42 assert(false);
|
|
43 }
|
|
44
|
|
45 uint len() { return string_.length; }
|
|
46
|
|
47 const(dchar_t)[] toDchars() { return string_; }
|
|
48
|
|
49 hash_t hash() { return Dchar.calcHash(string_.ptr, string_.length); }
|
|
50 hash_t ihash() { return Dchar.icalcHash(string_.ptr, string_.length); }
|
|
51
|
|
52 static int cmp(const(Lstring)* s1, const(Lstring)* s2)
|
|
53 {
|
|
54 int c = s2.string_.length - s1.string_.length;
|
|
55 return c ? c : Dchar.memcmp(s1.string_.ptr, s2.string_.ptr, s1.string_.length);
|
|
56 }
|
|
57
|
|
58 static int icmp(const(Lstring)* s1, const(Lstring)* s2)
|
|
59 {
|
|
60 int c = s2.string_.length - s1.string_.length;
|
|
61 return c ? c : Dchar.memicmp(s1.string_.ptr, s2.string_.ptr, s1.string_.length);
|
|
62 }
|
|
63
|
|
64 Lstring* append(const(Lstring)* s)
|
|
65 {
|
|
66 assert(false);
|
|
67 }
|
|
68
|
|
69 Lstring* substring(int start, int end)
|
|
70 {
|
|
71 assert(false);
|
|
72 }
|
|
73 } |