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