Warn about "assert X,Y"
[delight/core.git] / dmd2 / lstring.h
blobe906ae84cd826c08749f03b4976c340a94293a9e
2 // lstring.h
3 // length-prefixed strings
5 // Copyright (c) 1999-2002 by Digital Mars
6 // All Rights Reserved
7 // written by Walter Bright
8 // www.digitalmars.com
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.
13 #ifndef LSTRING_H
14 #define LSTRING_H 1
16 #include "dchar.h"
18 struct Lstring
20 unsigned length;
22 // Disable warning about nonstandard extension
23 #pragma warning (disable : 4200)
24 dchar string[];
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.
31 #if M_UNICODE
32 #define LSTRING(p,length) { length, L##p }
33 #else
34 #define LSTRING(p,length) { length, p }
35 #endif
37 #if __GNUC__
38 #define LSTRING_EMPTY() { 0 }
39 #else
40 #define LSTRING_EMPTY() LSTRING("", 0)
41 #endif
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);
47 Lstring *clone();
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);
72 #endif