3 // length-prefixed strings
5 // Copyright (c) 1999-2002 by Digital Mars
7 // written by Walter Bright
9 // License for redistribution is by either the Artistic License
10 // in artistic.txt, or the GNU General Public License in gnu.txt.
11 // See the included readme.txt for details.
22 // Disable warning about nonstandard extension
23 #pragma warning (disable : 4200)
26 static Lstring zero
; // 0 length string
28 // No constructors because we want to be able to statically
29 // initialize Lstring's, and Lstrings are of variable size.
32 #define LSTRING(p,length) { length, L##p }
34 #define LSTRING(p,length) { length, p }
38 #define LSTRING_EMPTY() { 0 }
40 #define LSTRING_EMPTY() LSTRING("", 0)
43 static Lstring
*ctor(const dchar
*p
) { return ctor(p
, Dchar::len(p
)); }
44 static Lstring
*ctor(const dchar
*p
, unsigned length
);
45 static unsigned size(unsigned length
) { return sizeof(Lstring
) + (length
+ 1) * sizeof(dchar
); }
46 static Lstring
*alloc(unsigned length
);
49 unsigned len() { return length
; }
51 dchar
*toDchars() { return string
; }
53 hash_t
hash() { return Dchar::calcHash(string
, length
); }
54 hash_t
ihash() { return Dchar::icalcHash(string
, length
); }
56 static int cmp(const Lstring
*s1
, const Lstring
*s2
)
58 int c
= s2
->length
- s1
->length
;
59 return c
? c
: Dchar::memcmp(s1
->string
, s2
->string
, s1
->length
);
62 static int icmp(const Lstring
*s1
, const Lstring
*s2
)
64 int c
= s2
->length
- s1
->length
;
65 return c
? c
: Dchar::memicmp(s1
->string
, s2
->string
, s1
->length
);
68 Lstring
*append(const Lstring
*s
);
69 Lstring
*substring(int start
, int end
);