annotate dmd/Lstring.d @ 169:e7769d53e750

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