1 /** 2 * Copyright: Copyright (c) 2012 Jacob Carlborg. All rights reserved. 3 * Authors: Jacob Carlborg 4 * Version: Initial created: Mar 3, 2012 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 6 */ 7 module mambo.core.core; 8 9 import std.regex; 10 11 import mambo.core.Array; 12 import mambo.core.AssociativeArray; 13 import mambo.util.Traits; 14 15 /** 16 * Returns true if the given value is blank. A string is considered blank if any of 17 * the following conditions are true: 18 * 19 * $(UL 20 * $(LI The string is null) 21 * $(LI The length of the string is equal to 0) 22 * $(LI The string only contains blank characters, i.e. space, newline or tab) 23 * ) 24 * 25 * Params: 26 * str = the string to test if it's blank 27 * 28 * Returns: $(D_KEYWORD true) if any of the above conditions are met 29 * 30 * See_Also: isPresent 31 */ 32 @property bool isBlank (T) (T t) 33 { 34 static if (isString!(T)) 35 { 36 if (t.length == 0) 37 return true; 38 39 return match(t, regex(`\S`, "g")).empty; 40 } 41 42 else static if (__traits(compiles, t.isEmpty)) 43 return t.isEmpty; 44 45 else static if (isPrimitive!(T) || isStruct!(T) || isUnion!(T)) 46 return false; 47 48 else 49 return T.init == t; 50 } 51 52 @property bool isPresent (T) (T t) 53 { 54 return !isBlank(t); 55 }