1 /// Utilities not related to the bot framework. 2 module diggler.util; 3 4 string pluralize(string word)(long amount) 5 { 6 static immutable plural = word ~ "s"; 7 return amount == 1? word : plural; 8 } 9 10 // Attributes 11 private template isAttribute(Attribute) 12 { 13 enum isAttribute(alias other) = is(typeof(other) == Attribute); 14 enum isAttribute(Other) = is(Other == Attribute); 15 } 16 17 template hasAttribute(alias sym, Attribute) 18 { 19 import std.typetuple : anySatisfy; 20 enum hasAttribute = anySatisfy!(isAttribute!Attribute, __traits(getAttributes, sym)); 21 } 22 23 template getAttribute(alias sym, Attribute) 24 { 25 import std.typetuple : Filter; 26 enum getAttribute = Filter!(isAttribute!Attribute, __traits(getAttributes, sym))[0]; 27 } 28 29 // From LuaD's `luad.conversions.functions` module 30 template StripHeadQual(T : const(T*)) 31 { 32 alias const(T)* StripHeadQual; 33 } 34 35 template StripHeadQual(T : const(T[])) 36 { 37 alias const(T)[] StripHeadQual; 38 } 39 40 template StripHeadQual(T : immutable(T*)) 41 { 42 alias immutable(T)* StripHeadQual; 43 } 44 45 template StripHeadQual(T : immutable(T[])) 46 { 47 alias immutable(T)[] StripHeadQual; 48 } 49 50 template StripHeadQual(T : T[]) 51 { 52 alias T[] StripHeadQual; 53 } 54 55 template StripHeadQual(T : T*) 56 { 57 alias T* StripHeadQual; 58 } 59 60 template StripHeadQual(T : T[N], size_t N) 61 { 62 alias T[N] StripHeadQual; 63 } 64 65 template StripHeadQual(T) 66 { 67 alias T StripHeadQual; 68 } 69 70 template FillableParameterTypeTuple(T) 71 { 72 import std.typetuple : staticMap; 73 import std.traits : ParameterTypeTuple; 74 alias staticMap!(StripHeadQual, ParameterTypeTuple!T) FillableParameterTypeTuple; 75 }