comparison dmd2/root/lstring.c @ 1452:638d16625da2

LDC 2 compiles again.
author Robert Clipsham <robert@octarineparrot.com>
date Sat, 30 May 2009 17:23:32 +0100
parents
children
comparison
equal deleted inserted replaced
1423:42bd767ec5a4 1452:638d16625da2
1 // lstring.c
2
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.
10
11 #include <stdlib.h>
12
13 #include "dchar.h"
14 #include "rmem.h"
15 #include "lstring.h"
16
17 #ifdef _MSC_VER // prevent compiler internal crash
18 Lstring Lstring::zero;
19 #else
20 Lstring Lstring::zero = LSTRING_EMPTY();
21 #endif
22
23 Lstring *Lstring::ctor(const dchar *p, unsigned length)
24 {
25 Lstring *s;
26
27 s = alloc(length);
28 memcpy(s->string, p, length * sizeof(dchar));
29 return s;
30 }
31
32 Lstring *Lstring::alloc(unsigned length)
33 {
34 Lstring *s;
35
36 s = (Lstring *)mem.malloc(size(length));
37 s->length = length;
38 s->string[length] = 0;
39 return s;
40 }
41
42 Lstring *Lstring::append(const Lstring *s)
43 {
44 Lstring *t;
45
46 if (!s->length)
47 return this;
48 t = alloc(length + s->length);
49 memcpy(t->string, string, length * sizeof(dchar));
50 memcpy(t->string + length, s->string, s->length * sizeof(dchar));
51 return t;
52 }
53
54 Lstring *Lstring::substring(int start, int end)
55 {
56 Lstring *t;
57
58 if (start == end)
59 return &zero;
60 t = alloc(end - start);
61 memcpy(t->string, string + start, (end - start) * sizeof(dchar));
62 return t;
63 }