1 // Written in D programming language 2 /** 3 * Copyright: © 2014 DSoftOut 4 * License: Subject to the terms of the MIT license, as written in the included LICENSE file. 5 * Authors: NCrashed <ncrashed@gmail.com> 6 */ 7 module pgator.util..string; 8 9 static if (__VERSION__ < 2066) { // from phobos 2.066-b1 10 import std.c..string; 11 12 /++ 13 Returns a D-style array of $(D char) given a zero-terminated C-style string. 14 The returned array will retain the same type qualifiers as the input. 15 16 $(RED Important Note:) The returned array is a slice of the original buffer. 17 The original data is not changed and not copied. 18 +/ 19 20 inout(char)[] fromStringz(inout(char)* cString) @system pure { 21 return cString ? cString[0 .. strlen(cString)] : null; 22 } 23 24 /// 25 @system pure unittest 26 { 27 assert(fromStringz(null) == null); 28 assert(fromStringz("foo") == "foo"); 29 } 30 } else { 31 public import std..string: fromStringz; 32 }