/src/rt/util/string.d
D | 59 lines | 36 code | 11 blank | 12 comment | 4 complexity | 7a688c2b86c5813046493c1e36d7e70d MD5 | raw file
1/** 2 * String manipulation and comparison utilities. 3 * 4 * Copyright: Copyright Sean Kelly 2005 - 2009. 5 * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. 6 * Authors: Sean Kelly 7 */ 8 9/* Copyright Sean Kelly 2005 - 2009. 10 * Distributed under the Boost Software License, Version 1.0. 11 * (See accompanying file LICENSE or copy at 12 * http://www.boost.org/LICENSE_1_0.txt) 13 */ 14module rt.util.string; 15 16private import core.stdc.string; 17 18@trusted: 19pure: 20nothrow: 21 22char[] uintToString( char[] buf, uint val ) 23{ 24 assert( buf.length > 9 ); 25 auto p = buf.ptr + buf.length; 26 27 do 28 { 29 *--p = cast(char)(val % 10 + '0'); 30 } while( val /= 10 ); 31 32 return buf[p - buf.ptr .. $]; 33} 34 35char[] uintToString( char[] buf, ulong val ) 36{ 37 assert( buf.length >= 20 ); 38 auto p = buf.ptr + buf.length; 39 40 do 41 { 42 *--p = cast(char)(val % 10 + '0'); 43 } while( val /= 10 ); 44 45 return buf[p - buf.ptr .. $]; 46} 47 48 49int dstrcmp( in char[] s1, in char[] s2 ) 50{ 51 int ret = 0; 52 auto len = s1.length; 53 if( s2.length < len ) 54 len = s2.length; 55 if( 0 != (ret = memcmp( s1.ptr, s2.ptr, len )) ) 56 return ret; 57 return s1.length > s2.length ? 1 : 58 s1.length == s2.length ? 0 : -1; 59}