1 /** 2 Copyright: Copyright (c) 2017, Joakim Brännström. All rights reserved. 3 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 4 Author: Joakim Brännström (joakim.brannstrom@gmx.com) 5 */ 6 module llvm_hiwrap.util; 7 8 import llvm_hiwrap.types; 9 10 immutable(char*)* strToCArray(string[] arr) { 11 import std..string : toStringz; 12 13 if (arr is null) 14 return null; 15 16 immutable(char*)[] cArr; 17 cArr.reserve(arr.length); 18 19 foreach (str; arr) 20 cArr ~= str.toStringz; 21 22 return cArr.ptr; 23 } 24 25 /** 26 * Beware, the data is duplicated and thus slightly inefficient. 27 * 28 * Params: 29 * msg = LLVM message to convert. 30 */ 31 string toD(ref LxMessage msg) { 32 return msg.toChar.idup; 33 } 34 35 /// Create the needed InputRange operation when opIndex is implemented. 36 mixin template IndexedRangeX(T) { 37 private size_t idx; 38 39 T front() { 40 assert(!empty, "Can't get front of an empty range"); 41 return this[idx]; 42 } 43 44 void popFront() { 45 assert(!empty, "Can't pop front of an empty range"); 46 idx++; 47 } 48 49 bool empty() { 50 return idx == length; 51 } 52 }