Fixed some lexing problems with DOS line-endings
[delight/core.git] / dmd / lstring.c
blob08847ddc46f6286d27e5870667db48719f7993a0
1 // lstring.c
3 // Copyright (c) 1999-2002 by Digital Mars
4 // All Rights Reserved
5 // written by Walter Bright
6 // www.digitalmars.com
7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
9 // See the included readme.txt for details.
11 #include <stdlib.h>
13 #include "dchar.h"
14 #include "mem.h"
15 #include "lstring.h"
17 Lstring Lstring::zero = LSTRING_EMPTY();
19 Lstring *Lstring::ctor(const dchar *p, unsigned length)
21 Lstring *s;
23 s = alloc(length);
24 memcpy(s->string, p, length * sizeof(dchar));
25 return s;
28 Lstring *Lstring::alloc(unsigned length)
30 Lstring *s;
32 s = (Lstring *)mem.malloc(size(length));
33 s->length = length;
34 s->string[length] = 0;
35 return s;
38 Lstring *Lstring::append(const Lstring *s)
40 Lstring *t;
42 if (!s->length)
43 return this;
44 t = alloc(length + s->length);
45 memcpy(t->string, string, length * sizeof(dchar));
46 memcpy(t->string + length, s->string, s->length * sizeof(dchar));
47 return t;
50 Lstring *Lstring::substring(int start, int end)
52 Lstring *t;
54 if (start == end)
55 return &zero;
56 t = alloc(end - start);
57 memcpy(t->string, string + start, (end - start) * sizeof(dchar));
58 return t;