annotate dmd/Lstring.d @ 0:10317f0c89a5

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