Mercurial > projects > ldc
comparison runtime/internal/util/string.d @ 443:44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Reworked the LLVMDC specific pragmas.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Fri, 01 Aug 2008 00:32:06 +0200 |
parents | |
children | ecb429ee0648 |
comparison
equal
deleted
inserted
replaced
442:76078c8ab5b9 | 443:44f08170f4ef |
---|---|
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 } |