Mercurial > projects > ldc
annotate dmd/root/lstring.c @ 1351:8d501abecd24
Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Thu, 14 May 2009 17:20:17 +0200 |
parents | 1853dcd9b944 |
children |
rev | line source |
---|---|
1 | 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" | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1
diff
changeset
|
14 #include "rmem.h" |
1 | 15 #include "lstring.h" |
16 | |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
17 #ifdef _MSC_VER // prevent compiler internal crash |
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
18 Lstring Lstring::zero; |
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
19 #else |
1 | 20 Lstring Lstring::zero = LSTRING_EMPTY(); |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
21 #endif |
1 | 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 } |