Changeset 83
- Timestamp:
- 12/16/05 10:41:01 (3 years ago)
- Files:
-
- trunk/meta/math.d (modified) (1 diff)
- trunk/meta/regex.d (modified) (1 diff)
- trunk/meta/strhacks.d (modified) (2 diffs)
- trunk/meta/string.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/meta/math.d
r76 r83 35 35 template binaryExponent(real x) 36 36 { 37 static if (x<0) const int binaryExponent = .binaryExponent!(-x);37 static if (x<0) const int binaryExponent = .binaryExponent!(-x); 38 38 else static if (x>0x1p128) const int binaryExponent = .binaryExponent!(x/0x1p128)+ 128; 39 else static if (x<0x1p-128) const int binaryExponent = .binaryExponent!(x*0x1p128)- 128; 40 else static if (x>=2.0) 41 const int binaryExponent = .binaryExponent!(x/2) + 1; 42 else static if (x<1.0) 43 const int binaryExponent = .binaryExponent!(x*2) - 1; 44 else 45 const int binaryExponent = 0; 39 else static if (x<0x1p-128)const int binaryExponent = .binaryExponent!(x*0x1p128)- 128; 40 else static if (x>0x1p32) const int binaryExponent = .binaryExponent!(x/0x1p32)+ 32; 41 else static if (x<0x1p-32) const int binaryExponent = .binaryExponent!(x*0x1p32)- 32; 42 else static if (x>=2.0) const int binaryExponent = .binaryExponent!(x/2) + 1; 43 else static if (x<1.0) const int binaryExponent = .binaryExponent!(x*2) - 1; 44 else const int binaryExponent = 0; 46 45 } 47 46 trunk/meta/regex.d
r79 r83 57 57 58 58 - Cannot use an alias as a term within a static if 59 alias true foo;60 static if(foo){} // fails61 59 // this is why there are so many templates in this file 60 [[DAC: This is part of the rule that 'static if' can't refer to variables declared in the same scope. 61 It makes it difficult to do complicated functions. 62 But, there's a bug in the spec for static if, the "AssignExpression" doesn't make sense.]] 62 63 63 64 - No way to stop the compiler dead if there's an error ("pragma(halt)" would be nice) trunk/meta/strhacks.d
r76 r83 9 9 } 10 10 11 /// = str[from..to] 11 12 template slice(char [] str, int from, int to) 12 13 { 13 14 const char [] slice = str[from..to]; 15 } 16 17 /// = str[from..$] 18 template sliceheadoff(char [] str, int from) 19 { 20 const char [] sliceheadoff = str[from..str.length]; 21 } 22 23 template slicetailoff(char [] str, int charstochopoff) 24 { 25 const char [] slicetailoff = str[0..str.length-charstochopoff]; 14 26 } 15 27 … … 53 65 static assert(!streq!("abc", "axc") ); 54 66 static assert(!streq!("abc", "abcd") ); 67 static assert(streq!(sliceheadoff!("abcdefg", 3), "defg")); 55 68 } trunk/meta/string.d
r78 r83 3 3 import meta.strhacks; 4 4 5 /// Returns str[] sans trailing delimiter[], if any. 6 template chomp(char [] str, char charToTrim) 5 /// Returns str[] sans trailing delimiter[], if any. 6 /// Unlike std.string.chomp, it removes all instances of the delimiter. 7 template chomp(char [] str, char delimiter) 7 8 { 8 9 static if (str.length==0) const char[] chomp=str; 9 else static if (str[strlen!(str)-1]== charToTrim)10 const char [] chomp = .chomp!( slice !(str, 0, strlen!(str)-1), charToTrim);10 else static if (str[strlen!(str)-1]==delimiter) 11 const char [] chomp = .chomp!( slicetailoff!(str, 1), delimiter); 11 12 else const char [] chomp = str; 12 13 } 13 14 14 /// see if character c is in the pattern15 /// see if character c is in the string str. 15 16 template isInString(char c, char [] str) 16 17 { 17 18 static if (str.length==0) const bool isInString=false; 18 19 else static if( c==str[0]) const bool isInString=true; 19 else const bool isInString = .isInString!(c, slice !(str, 1, strlen!(str)) );20 else const bool isInString = .isInString!(c, sliceheadoff!(str, 1) ); 20 21 } 21 22
