Mercurial > projects > ldc
comparison tango/lib/compiler/llvmdc/util/string.d @ 132:1700239cab2e trunk
[svn r136] MAJOR UNSTABLE UPDATE!!!
Initial commit after moving to Tango instead of Phobos.
Lots of bugfixes...
This build is not suitable for most things.
author | lindquist |
---|---|
date | Fri, 11 Jan 2008 17:57:40 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:5825d48b27d1 | 132:1700239cab2e |
---|---|
1 /******************************************************************************* | |
2 | |
3 copyright: Copyright (c) 2004 Tango group. All rights reserved | |
4 | |
5 license: BSD style: $(LICENSE) | |
6 | |
7 version: Initial release: July 2006 | |
8 | |
9 | |
10 Various char[] utilities | |
11 | |
12 *******************************************************************************/ | |
13 | |
14 module util.string; | |
15 | |
16 private import tango.stdc.string; | |
17 | |
18 // convert uint to char[], within the given buffer | |
19 // Returns a valid slice of the populated buffer | |
20 char[] intToUtf8 (char[] tmp, size_t val) | |
21 in { | |
22 assert (tmp.length > 20, "atoi buffer should be 20 or more chars wide"); | |
23 } | |
24 body | |
25 { | |
26 char* p = tmp.ptr + tmp.length; | |
27 | |
28 do { | |
29 *--p = (val % 10) + '0'; | |
30 } while (val /= 10); | |
31 | |
32 return tmp [cast(size_t)(p - tmp.ptr) .. $]; | |
33 } | |
34 | |
35 | |
36 // function to compare two strings | |
37 int stringCompare (char[] s1, char[] s2) | |
38 { | |
39 auto len = s1.length; | |
40 | |
41 if (s2.length < len) | |
42 len = s2.length; | |
43 | |
44 int result = memcmp(s1.ptr, s2.ptr, len); | |
45 | |
46 if (result == 0) | |
47 result = cast(int)s1.length - cast(int)s2.length; | |
48 | |
49 return result; | |
50 } |