Changeset 83

Show
Ignore:
Timestamp:
12/16/05 10:41:01 (3 years ago)
Author:
Don Clugston
Message:

added sliceheadoff!(), slicetailoff!() to strhacks (reduces some noise). Also improved comments for math + string functions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/meta/math.d

    r76 r83  
    3535template binaryExponent(real x) 
    3636{ 
    37   static if (x<0) const int binaryExponent = .binaryExponent!(-x); 
     37  static if (x<0) const int binaryExponent = .binaryExponent!(-x); 
    3838  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; 
    4645} 
    4746 
  • trunk/meta/regex.d

    r79 r83  
    5757 
    5858    - Cannot use an alias as a term within a static if 
    59     alias true foo; 
    60     static if(foo){} // fails 
    6159    // 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.]] 
    6263     
    6364    - No way to stop the compiler dead if there's an error ("pragma(halt)" would be nice) 
  • trunk/meta/strhacks.d

    r76 r83  
    99} 
    1010 
     11///  = str[from..to] 
    1112template slice(char [] str, int from, int to) 
    1213{ 
    1314  const char [] slice = str[from..to]; 
     15} 
     16 
     17/// = str[from..$] 
     18template sliceheadoff(char [] str, int from) 
     19{ 
     20  const char [] sliceheadoff = str[from..str.length]; 
     21} 
     22 
     23template slicetailoff(char [] str, int charstochopoff) 
     24{ 
     25  const char [] slicetailoff = str[0..str.length-charstochopoff]; 
    1426} 
    1527 
     
    5365 static assert(!streq!("abc", "axc") ); 
    5466 static assert(!streq!("abc", "abcd") ); 
     67 static assert(streq!(sliceheadoff!("abcdefg", 3), "defg")); 
    5568} 
  • trunk/meta/string.d

    r78 r83  
    33import meta.strhacks; 
    44 
    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. 
     7template chomp(char [] str, char delimiter) 
    78{ 
    89  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); 
    1112  else const char [] chomp = str; 
    1213} 
    1314 
    14 /// see if character c is in the pattern 
     15/// see if character c is in the string str. 
    1516template isInString(char c, char [] str) 
    1617{ 
    1718  static if (str.length==0) const bool isInString=false; 
    1819  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) ); 
    2021} 
    2122