Changeset 217

Show
Ignore:
Timestamp:
07/15/08 07:28:15 (6 months ago)
Author:
yidabu
Message:

upgrade to with tango latest svn

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/bridge/php/String.d

    r154 r217  
    33 
    44/******************************************************************************* 
    5          
     5 
    66        Copyright:      Copyright (c) 2007  (yidabu  g m a i l at com) All rights reserved 
    77 
     
    2222 
    2323import  dwin.text.Unicode : toLower; 
    24      
     24 
    2525import  tango.text.Unicode, 
    2626        tango.core.Traits, 
     
    3232import  Unicode = tango.text.Unicode; 
    3333import  Util    = tango.text.Util; 
    34      
     34 
    3535 
    3636 
     
    5050    if(!str.length) 
    5151        return result; 
    52      
     52 
    5353    auto crc = getCrc32(str); 
    5454    result = Integer.toInt(crc.hexDigest, 16); 
    55      
     55 
    5656    return result; 
    5757} 
     
    6767ƒçŽ ïŒŒè€Œæœ€åŽé‚£äžªå 
    6868ƒçŽ å°†åŒ 
    69 å« string 的剩䜙郚分。  
     69含 string 的剩䜙郚分。 
    7070 
    7171    劂果 separator 䞺空字笊䞲""explode() 将返回 FALSE。劂果 separator 所匠
    7272含的倌圚 string 䞭扟䞍到那么 explode() 将返回匠
    7373含 string 单䞪å 
    74 ƒçŽ çš„æ•°ç»„ã€‚  
     74ƒçŽ çš„æ•°ç»„ã€‚ 
    7575 
    7676    劂果 limit 参数是莟数则返回陀了最后的 -limit 䞪å 
    7777ƒçŽ å€–çš„æ‰€æœ‰å 
    78 ƒçŽ ã€‚æ­€ç‰¹æ€§æ˜¯ PHP 5.1.0 䞭新增的。  
     78ƒçŽ ã€‚æ­€ç‰¹æ€§æ˜¯ PHP 5.1.0 䞭新增的。 
    7979 
    8080*/ 
    8181char[][] explode ( char[] separator , char[] src, int limit = int.max ) 
    82 {     
     82{ 
    8383    if(!separator.length) 
    8484        return null; 
    85      
     85 
    8686    //if( !Util.containsPattern(src, separator) ) 
    8787        //return [src]; 
    88      
     88 
    8989    char[][] result; 
    90      
     90 
    9191    auto i = Util.locatePattern (src, separator); 
    9292    while (i != src.length ) 
     
    9595            if(result.length >= limit -1) 
    9696                break; 
    97              
     97 
    9898        result ~= src[0 .. i]; 
    9999        src = src [i + separator.length .. $]; 
    100         i = Util.locatePattern (src, separator);         
    101     } 
    102      
     100        i = Util.locatePattern (src, separator); 
     101    } 
     102 
    103103    if(limit < 0 ) 
    104104    { 
     
    108108    else 
    109109        result ~= src; 
    110      
     110 
    111111    return result; 
    112 }     
     112} 
    113113debug unittest 
    114114{ 
     
    117117        assert ( pieces[0] == "piece1" ); 
    118118        assert ( pieces[1] == "piece2" ); 
    119          
     119 
    120120        auto str = "one|two|three|four"; 
    121121        auto result = explode("|", str, 2); 
    122122        assert( result.length == 2 && result[0] == "one" && result[1] == "two|three|four" ); 
    123          
     123 
    124124        // 莟数的 limit自 PHP 5.1 起 
    125125        result = explode("|", str, -1); 
    126126        assert( result.length == 3 && result[0] == "one" && result[1] == "two" && result[2] == "three" ); 
    127              
     127 
    128128} 
    129129// 
     
    132132 
    133133/** 
    134 The default mode, ENT_COMPAT, is the backwards compatible mode which only translates the double-quote character and leaves the single-quote untranslated. If ENT_QUOTES is set, both single and double quotes are translated and if ENT_NOQUOTES is set neither single nor double quotes are translated.  
    135 '&' (ampersand) becomes '&amp;'  
    136 '"' (double quote) becomes '&quot;' when ENT_NOQUOTES is not set.  
    137 ''' (single quote) becomes '&#039;' only when ENT_QUOTES is set.  
    138 '<' (less than) becomes '&lt;'  
    139 '>' (greater than) becomes '&gt;'  
     134The default mode, ENT_COMPAT, is the backwards compatible mode which only translates the double-quote character and leaves the single-quote untranslated. If ENT_QUOTES is set, both single and double quotes are translated and if ENT_NOQUOTES is set neither single nor double quotes are translated. 
     135'&' (ampersand) becomes '&amp;' 
     136'"' (double quote) becomes '&quot;' when ENT_NOQUOTES is not set. 
     137''' (single quote) becomes '&#039;' only when ENT_QUOTES is set. 
     138'<' (less than) becomes '&lt;' 
     139'>' (greater than) becomes '&gt;' 
    140140*/ 
    141141 
     
    151151            str = Util.substitute(str, "'", "&#039;"); 
    152152            break; 
    153         case ENT_COMPAT :   //only translates the double-quote  
     153        case ENT_COMPAT :   //only translates the double-quote 
    154154            str = Util.substitute(str, "\"", "&quot;"); 
    155155        case ENT_NOQUOTES : //both not 
    156156            break; 
    157157    } 
    158      
     158 
    159159    return str; 
    160160} 
     
    163163    char[] result = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES); 
    164164    assert( result == "&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;" ); 
    165      
    166      
     165 
     166 
    167167} 
    168168// 
     
    202202 
    203203/** 
    204     substr() returns the portion of string specified by the start and length parameters.  
    205  
    206     If start is non-negative, the returned string will start at the start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.  
    207  
    208     If start is negative, the returned string will start at the start'th character from the end of string.  
    209  
    210     If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string). If string is less than or equal to start characters long, FALSE will be returned.  
    211  
    212     If length is given and is negative, then that many characters will be omitted from the end of string (after the start position has been calculated when a start is negative). If start denotes a position beyond this truncation, an empty string will be returned.  
     204    substr() returns the portion of string specified by the start and length parameters. 
     205 
     206    If start is non-negative, the returned string will start at the start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth. 
     207 
     208    If start is negative, the returned string will start at the start'th character from the end of string. 
     209 
     210    If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string). If string is less than or equal to start characters long, FALSE will be returned. 
     211 
     212    If length is given and is negative, then that many characters will be omitted from the end of string (after the start position has been calculated when a start is negative). If start denotes a position beyond this truncation, an empty string will be returned. 
    213213 
    214214 
     
    221221    if(start >= str.length) 
    222222        return null; 
    223      
     223 
    224224    if(start < 0) 
    225225        start = str.length + start; 
    226      
     226 
    227227    if(len < 0) 
    228228    { 
     
    236236            len = str.length - start; 
    237237    } 
    238      
     238 
    239239    return str[start .. start + len]; 
    240240} 
     
    242242debug unittest 
    243243{ 
    244      
     244 
    245245    char[] str = "abcdef"; 
    246246    assert( substr(str, 1)     == "bcdef" ); 
     
    249249    assert( substr(str, 0, 8)  == "abcdef" ); 
    250250    assert( substr(str, -1, 1) == "f" ); 
    251          
     251 
    252252    assert( substr(str, -1)    == "f" ); 
    253253    assert( substr(str, -2)    == "ef" ); 
     
    269269 
    270270/** 
    271     strpos --  Find position of first occurrence of a string  
     271    strpos --  Find position of first occurrence of a string 
    272272    Description 
    273273 
    274     Returns the numeric position of the first occurrence of needle in the haystack string.  
    275     Unlike the strrpos(), this function can take a full string as the needle parameter and the entire string will be used.  
     274    Returns the numeric position of the first occurrence of needle in the haystack string. 
     275    Unlike the strrpos(), this function can take a full string as the needle parameter and the entire string will be used. 
    276276 
    277277    TODO: D can not have two types of return value : bool and int 
     
    291291{ 
    292292// Provides: <body text='black'> 
    293     assert( str_replace("%body%", "black", "<body text='%body%'>") == "<body text='black'>" );     
     293    assert( str_replace("%body%", "black", "<body text='%body%'>") == "<body text='black'>" ); 
    294294} 
    295295// 
     
    312312{ 
    313313    char[64] tmp; 
    314     return Integer.format(tmp, number, Integer.Style.Hex).dup; 
     314    return Integer.format(tmp, number, "x").dup; 
    315315} 
    316316char[] dechex ( char[] str ) 
     
    325325    assert(dechex(10) == "a"); 
    326326    assert(dechex(47) == "2f"); 
    327      
     327 
    328328} 
    329329// 
     
    343343    assert( is_numeric('1') ); 
    344344    assert( !is_numeric('a') ); 
    345     assert( is_numeric(56789) );     
    346 } 
    347  
    348  
    349  
     345    assert( is_numeric(56789) ); 
     346} 
     347 
     348 
     349 
  • trunk/core/Array.d

    r160 r217  
    22 
    33/******************************************************************************* 
    4          
     4 
    55        Copyright:      Copyright (c) 2007  (yidabu  g m a i l at com) All rights reserved 
    66 
     
    1919 * 
    2020 * 
    21  *  
     21 * 
    2222 */ 
    2323module dwin.core.Array ; 
    2424 
    2525 
    26 private import  tango.core.Array, 
    27                 tango.core.Traits, 
    28                 tango.math.Random, 
    29                 tango.core.Vararg; 
     26 
     27import  tango.core.Array; 
     28private import  tango.core.Traits; 
     29                //tango.math.Kiss, 
     30private import  tango.core.Vararg; 
    3031 
    3132private import tango.stdc.string : memmove ; 
    3233private import tango.text.Util : substitute; 
    33      
     34 
    3435private import dwin.core.Ctfe : IsLessEqual, IsMoreEqual, IsMore; 
    3536 
    36      
    37 version (ArrayVerbose)  
     37 
     38version (ArrayVerbose) 
    3839    private import tango.util.log.Trace; 
    39          
     40 
    4041 
    4142 
     
    6263 *  The index of the nth match or buf.length if no match was found. 
    6364 */ 
    64   
     65 
    6566 //modified from tango.core.Array.find 
    6667template findNth_( Elem, Pred = IsEqual!(Elem) ) 
     
    141142    unittest 
    142143    { 
    143          
     144 
    144145        int[] foo = [1, 2, 3, 2, 4, 2]; 
    145         assert( findNth(foo, 5) == 6U );        //not found         
     146        assert( findNth(foo, 5) == 6U );        //not found 
    146147        assert( findNth(foo, 2) == 1U );        //first 2, index is 1 
    147         assert( findNth(foo, 2, 2U) == 3U );     
     148        assert( findNth(foo, 2, 2U) == 3U ); 
    148149        assert( findNth(foo, 2, 3U) == 5U ); 
    149150        assert( findNth(foo, 5, 2U) == 6U );    //not found 
    150          
     151 
    151152        char[] bar = "abcabc"; 
    152153        assert( findNth(bar, "a") == 0U ); 
     
    154155        assert( findNth(bar, 'a', 2U) == 3U ); 
    155156        assert( findNth(bar, "a", 2U) == 3U ); 
    156          
     157 
    157158        assert( findNth(bar, "a", 3U) == 6U );  //not found 
    158159        assert( findNth(bar, "d") == 6U );      //not found 
     
    160161        assert( findNth(bar, 'd', 2U) == 6U );      //not found 
    161162        assert( findNth(bar, "d", 2U) == 6U );      //not found 
    162          
     163 
    163164    } 
    164165} 
     
    273274        assert( rfindNth(s, "abc") == 6U); 
    274275        assert( rfindNth(s, "abc", 2U) == 3U); 
    275          
     276 
    276277        assert( rfindNth(s, "abc", 3U) == 0U); 
    277          
     278 
    278279        assert( rfindNth(s, 'a') == 6U); 
    279280        assert( rfindNth(s, 'a', 2U) == 3U); 
    280281        assert( rfindNth(s, 'a', 3U) == 0U); 
    281          
     282 
    282283        assert( rfindNth(s, 'd') == 9U);    //not found 
    283284        assert( rfindNth(s, "d") == 9U);    //not found 
    284          
     285 
    285286    } 
    286287} 
     
    307308{ 
    308309    static assert( isCallableType!(Pred) ); 
    309      
     310 
    310311    Buf replaceNth( Buf buf, Elem pat, Elem val, uint nth, Pred pred ) 
    311312    { 
     
    313314        if( where == buf.length ) 
    314315            return buf; 
    315         return buf[0..where] ~ val ~ buf[where + pat.length .. $];         
     316        return buf[0..where] ~ val ~ buf[where + pat.length .. $]; 
    316317    } 
    317318} 
     
    328329        r = replaceNth(s, "ab", "AB", 3U); 
    329330        assert ( r == "ababAB" ); 
    330          
     331 
    331332        // not found 
    332333        r = replaceNth(s, "ac", "AB"); 
    333         assert ( r == "ababab" );         
     334        assert ( r == "ababab" ); 
    334335        r = replaceNth(s, "ac", "AB", 2U); 
    335336        assert ( r == "ababab" ); 
    336          
     337 
    337338        r = replaceNth(s, 'a', 'A', 1U); 
    338         assert ( r == "Ababab" );     
     339        assert ( r == "Ababab" ); 
    339340        r = replaceNth(s, 'c', 'C', 2U); 
    340         assert ( r == "ababab" );         
    341          
     341        assert ( r == "ababab" ); 
     342 
    342343    } 
    343344} 
     
    364365{ 
    365366    static assert( isCallableType!(Pred) ); 
    366      
     367 
    367368    Buf rreplaceNth( Buf buf, Elem pat, Elem val, uint nth, Pred pred ) 
    368369    { 
     
    370371        if( where == buf.length ) 
    371372            return buf; 
    372         return buf[0..where] ~ val ~ buf[where + pat.length .. $];         
     373        return buf[0..where] ~ val ~ buf[where + pat.length .. $]; 
    373374    } 
    374375} 
     
    385386        r = rreplaceNth(s, "ab", "AB", 3U); 
    386387        assert ( r == "ABabab" ); 
    387          
     388 
    388389        // not found 
    389390        r = rreplaceNth(s, "ac", "AB"); 
    390         assert ( r == "ababab" );         
     391        assert ( r == "ababab" ); 
    391392        r = rreplaceNth(s, "ac", "AB", 2U); 
    392393        assert ( r == "ababab" ); 
    393          
     394 
    394395        r = rreplaceNth(s, 'a', 'A', 1U); 
    395         assert ( r == "ababAb" );         
     396        assert ( r == "ababAb" ); 
    396397        r = rreplaceNth(s, "c", "C", 2U); 
    397         assert ( r == "ababab" );     
     398        assert ( r == "ababab" ); 
    398399    } 
    399400} 
     
    407408 
    408409char[] replaceSeries(char[] buf, ... ) 
    409 {     
     410{ 
    410411    alias char[] t; 
    411412    for(uint i = 0; i < _arguments.length -1; i += 2 ) 
     
    434435 
    435436//////////////////////////////////////////////////////////////////////////////// 
    436 // Remove by index  
     437// Remove by index 
    437438//////////////////////////////////////////////////////////////////////////////// 
    438439 
     
    440441 * Performs a linear scan of buf from $(LB)0 .. buf.length$(RB), moving all 
    441442 * elements matching index  to the end of the sequence.  The relative order of 
    442  * elements not matching index will be preserved.   
     443 * elements not matching index will be preserved. 
    443444 * Params: 
    444445 *  buf  = The array to scan.  This parameter is not marked 'inout' 
     
    449450 *  inx  = The pattern index to match against. 
    450451 * 
    451  * Returns:xxx      
     452 * Returns:xxx 
    452453*  The result array. 
    453454 */ 
    454   
     455 
    455456template removeByIndex( Buf ) 
    456457{ 
     
    459460    { 
    460461        alias ElemTypeOf!(Buf) Elem; 
    461          
    462         if( !buf.length || inx >= buf.length )  
     462 
     463        if( !buf.length || inx >= buf.length ) 
    463464            return buf; 
    464          
    465         if (inx != buf.length - 1)  
     465 
     466        if (inx != buf.length - 1) 
    466467        { 
    467468            memmove(&(buf[inx]), &(buf[inx + 1]), Elem.sizeof * (buf.length - inx - 1)); 
    468469        } 
    469          
     470 
    470471        buf.length = buf.length - 1; 
    471472        return buf; 
     
    494495 * Performs a linear scan of buf from $(LB)0 .. buf.length$(RB), moving all 
    495496 * elements matching index  to the end of the sequence.  The relative order of 
    496  * elements not matching index will be preserved.   
     497 * elements not matching index will be preserved. 
    497498 * Params: 
    498499 *  buf  = The array to scan.  This parameter is not marked 'inout' 
     
    508509 */ 
    509510 
    510 template removeNth (Buf, Pat)  
     511template removeNth (Buf, Pat) 
    511512{ 
    512513    Buf removeNth (Buf buf, Pat pat, uint nth = 1) 
     
    514515        size_t index = findNth(buf, pat, nth); 
    515516 
    516         if (index != buf.length)  
     517        if (index != buf.length) 
    517518        { 
    518519            buf.removeByIndex(index); 
     
    525526    unittest 
    526527    { 
    527          
     528 
    528529        int[] foo = [1, 2, 3, 2, 3]; 
    529530        foo = foo.removeNth(2); 
    530         assert(foo == [1, 3, 2, 3]);   
     531        assert(foo == [1, 3, 2, 3]); 
    531532        foo = foo.removeNth(3, 2U); 
    532533        assert(foo == [1, 3, 2]); 
    533          
     534 
    534535    } 
    535536} 
     
    547548Elem[] replacePairs (Elem) (ref Elem[] buf, Elem[Elem] pairs) 
    548549{ 
    549     //cashew.utils.Array     
     550    //cashew.utils.Array 
    550551  Elem* peer ; 
    551552 
     
    565566        auto pairs = assoc!(int, int)( 
    566567            [1, 2, 3] , 
    567             [4, 5, 6]  
     568            [4, 5, 6] 
    568569        ); 
    569570        foo.replacePairs(pairs); 
    570         assert(foo == [4, 5, 6, 4, 5, 6, 4, 5, 6]);   
     571        assert(foo == [4, 5, 6, 4, 5, 6, 4, 5, 6]); 
    571572    } 
    572573} 
     
    581582 *  Update/modify all elements of an array. 
    582583 */ 
    583 template apply (Elem, Pred)  
     584template apply (Elem, Pred) 
    584585{ 
    585586    static assert( isCallableType!(Pred) ); 
    586587 
    587588    Elem[] apply (ref Elem[] buf, Pred pred) 
    588     {         
    589         foreach (ref cur; buf)  
     589    { 
     590        foreach (ref cur; buf) 
    590591            pred(cur); 
    591592      return buf; 
     
    595596{ 
    596597    unittest 
    597     {   
     598    { 
    598599        int[] foo = [1, 3, 5, 7]; 
    599600        foo.apply((ref int n) { n++; }); 
     
    619620    ElemV[ElemK] result ; 
    620621 
    621     foreach (i, x; keys)  
     622    foreach (i, x; keys) 
    622623    { 
    623624        result[x] = values[i]; 
     
    626627} 
    627628 
    628 debug( UnitTest )  
    629 { 
    630     unittest  
     629debug( UnitTest ) 
     630{ 
     631    unittest 
    631632    { 
    632633        auto foo = assoc!(int, char)( 
     
    647648/// Return the maximum value of an array. 
    648649T max(T)(T[] array) 
    649 {   
     650{ 
    650651    /* 
    651652    T m = array[0]; 
    652653    foreach (T a; array) 
    653654        if (a>m) 
    654             m=a;    
     655            m=a; 
    655656    return m; 
    656657    */ 
     
    671672{ 
    672673    static assert( isIntegerType!(V), "array value type must been integer type" ); 
    673      
    674     if(!array.length)  
     674 
     675    if(!array.length) 
    675676        return null; 
    676      
    677      
     677 
     678 
    678679    K[] result ; 
    679680    long i = -(long.max); 
     
    683684        { 
    684685            i = v; 
    685             result = k;     
     686            result = k; 
    686687        } 
    687688    } 
    688      
     689 
    689690    return result; 
    690691} 
     
    709710/// Return the minimum value of an array. 
    710711T min(T)(T[] array) 
    711 {   
     712{ 
    712713    //yage.core.array; 
    713714    T m = array[0]; 
    714715    foreach (T a; array) 
    715716        if (a<m) 
    716             m=a;    
     717            m=a; 
    717718    return m; 
    718719} 
     
    726727/** 
    727728 * Is the array ordered? 
    728  */  
     729 */ 
    729730template isOrdered_( T, Pred = IsMoreEqual!(T) ) 
    730731{ 
    731732    static assert( isCallableType!(Pred) ); 
    732      
     733 
    733734    bool fn (T[] array, Pred pred = Pred.init ) 
    734     {   
     735    { 
    735736        if (array.length <= 1) 
    736737            return true; 
    737          
     738 
    738739        for (int i=0; i<array.length-1; i++) 
    739740            if( !pred(array[i+1], array[i]) ) 
     
    746747{ 
    747748    bool isOrdered (T[] array ) 
    748     {   
     749    { 
    749750        return isOrdered_!(T).fn(array); 
    750     }   
     751    } 
    751752} 
    752753template isOrdered( T, Pred ) 
    753754{ 
    754755    bool isOrdered (T[] array, Pred pred ) 
    755     {   
     756    { 
    756757        return isOrdered_!(T, Pred).fn(array, pred); 
    757     }     
     758    } 
    758759} 
    759760debug( UnitTest ) 
     
    774775    Examples: 
    775776    --- 
    776         randomValue(["a","b","c"]);         
     777        randomValue(["a","b","c"]); 
    777778    --- 
    778779*/ 
     
    780781T randomValue(T)(T[] arr) 
    781782{ 
    782     return arr[ Random.shared.next(0, arr.length) ]; 
     783    return arr[ Kiss().next(0, arr.length) ]; 
    783784} 
    784785*/ 
    785786 
    786787//////////////////////////////////////////////////////////////////////////////// 
    787 // push  
     788// push 
    788789//////////////////////////////////////////////////////////////////////////////// 
    789790/*********************************************************************************** 
     
    792793int push (Elem) (ref Elem[] buf, Elem[] bale ...) 
    793794{ 
    794     //cashew.utils.Array     
     795    //cashew.utils.Array 
    795796    buf ~= bale; 
    796797    return buf.length; 
     
    800801    unittest 
    801802    { 
    802    
     803 
    803804        int[] foo = [1, 2, 3]; 
    804805        foo.push(4, 5); 
    805806        assert(foo == [1, 2, 3, 4, 5]); 
    806    
    807     } 
    808 } 
    809 // 
     807 
     808    } 
     809} 
     810// 
  • trunk/io/ContentScan.d

    r154 r217  
    22 
    33/******************************************************************************* 
    4          
     4 
    55        Copyright:      Copyright (c) 2007  (yidabu  g m a i l at com) All rights reserved 
    66 
     
    2424 
    2525/******************************************************************************* 
    26      
     26 
    2727    tango.text.Regex is simple, not powerful, may instead of pcre in the future. 
    28      
     28 
    2929    Example: 
    3030    --- 
     
    3535    //scan.contain = r"\lab\"; 
    3636    auto result = scan.scan(path); 
    37      
     37 
    3838    auto contentScan = new ContentScan(); 
    3939    contentScan.regexContain = r"[aA]uthors?:[^\r\n]+?yidabu[^\r\n]+"; 
    4040    contentScan.replaceWith = "Authors:        yidabu ( D Programming Language China : http://www.d-programming-language-china.org/ )"; 
    4141    contentScan.scan(result.files); 
    42      
    43     Stdout.formatln ("\n{} Relpaced Files", contentScan.find.length);        
     42 
     43    Stdout.formatln ("\n{} Relpaced Files", contentScan.find.length); 
    4444    foreach(file; contentScan.find) 
    4545    { 
    4646        Stdout(file).newline; 
    4747    } 
    48      
    49     Stdout.formatln ("\n{} Files no Replaced", contentScan.notfind.length);        
     48 
     49    Stdout.formatln ("\n{} Files no Replaced", contentScan.notfind.length); 
    5050    foreach(file; contentScan.notfind) 
    5151    { 
    5252        Stdout(file).newline; 
    53     }   
    54      
     53    } 
     54 
    5555    --- 
    5656 
     
    5858 
    5959 
    60 class ContentScan  
     60class ContentScan 
    6161{ 
    6262    /// exactly string 
     
    6464    /// exactly excluded string 
    6565    char[] exclude; 
    66          
     66 
    6767    /// See_Also: tango.text.Regex 
    6868    char[] regexContain; 
    6969    char[] regexExclude; 
    70      
     70 
    7171    Regex regexContain_; 
    7272    Regex regexExclude_; 
    73      
     73 
    7474    char[] replaceWith; 
    75      
     75 
    7676    FilePath[] find; 
    7777    FilePath[] notfind; 
    78      
     78 
    7979    ContentScan scan(FilePath[] files) 
    8080    { 
    8181        if(!files.length) 
    8282            return this; 
    83          
     83 
    8484        if(regexContain.length) 
    8585            regexContain_ = Regex(regexContain); 
    8686        if(regexExclude.length) 
    8787            regexExclude_ = Regex(regexExclude); 
    88          
     88 
    8989        foreach(file; files) 
    9090        { 
    91             char[] src = cast(char[]) ( (new File(file)).read ); 
    92              
     91            char[] src = cast(char[]) ( (new File(file.dup.native.toString)).read ); 
     92 
    9393            if( (contain.length && !src.containsPattern(contain))   || 
    9494                (exclude.length && src.containsPattern(exclude))    || 
    9595                (regexContain_  && !regexContain_.test(src))        || 
    96                 (regexExclude_  && regexExclude_.test(src))  
     96                (regexExclude_  && regexExclude_.test(src)) 
    9797            ) 
    9898            { 
     
    100100                continue; 
    101101            } 
    102              
     102 
    103103            find ~= file.dup.native; 
    104              
     104 
    105105            if( replaceWith.length && (regexContain.length || contain.length) ) 
    106106            { 
     
    109109                else if( contain.length ) 
    110110                    src = substitute(src, contain, replaceWith); 
    111                 (new File(file)).write(src); 
     111                (new File(file.dup.native.toString)).write(src); 
    112112            } 
    113113        }//foreach 
    114          
     114 
    115115        return this; 
    116116    }//scan 
    117      
     117 
    118118}//ContentScan 
  • trunk/io/Digest.d

    r154 r217  
    33 
    44/******************************************************************************* 
    5          
     5 
    66        Copyright:      Copyright (c) 2007  (yidabu  g m a i l at com) All rights reserved 
    77 
     
    2626                tango.io.FilePath, 
    2727                tango.io.File; 
    28      
     28 
    2929 
    3030//MySQL提䟛了4䞪凜数甚于哈垌加密PASSWORD, ENCRYPT, SHA1和MD5, 所以这里至少芁提䟛sha1和md5的实现 
     
    3535    if(!path.exists) 
    3636        return null; 
    37     ubyte[] result = cast(ubyte[]) (new File(path)).read; 
     37    ubyte[] result = cast(ubyte[]) (new File(path.dup.native.toString())).read; 
    3838    return getMd5( result ); 
    3939} 
     
    5353debug(UnitTest) unittest 
    5454{ 
    55      
     55 
    5656        static char[][] strings = 
    5757        [ 
     
    7575                "57edf4a22be3c955ac49da2e2107b67a" 
    7676        ]; 
    77      
     77 
    7878        foreach(k,v; strings) 
    7979        { 
    8080            assert(getMd5(v).hexDigest == results[k] ); 
    8181        } 
    82          
     82 
    8383} 
    8484//getMd5 
     
    9090    if(!path.exists) 
    9191        return null; 
    92     ubyte[] result = cast(ubyte[]) (new File(path)).read; 
     92    ubyte[] result = cast(ubyte[]) (new File(path.dup.native.toString)).read; 
    9393    return getCrc32( result ); 
    9494} 
     
    113113    if(!path.exists) 
    114114        return null; 
    115     ubyte[] result = cast(ubyte[]) (new File(path)).read; 
     115    ubyte[] result = cast(ubyte[]) (new File(path.dup.native.toString)).read; 
    116116    return getTiger( result ); 
    117117} 
     
    154154        foreach(k,v; strings) 
    155155            assert(getTiger(v).hexDigest == results[k]); 
    156      
     156 
    157157} 
    158158//getTiger 
     
    164164    if(!path.exists) 
    165165        return null; 
    166     ubyte[] result = cast(ubyte[]) (new File(path)).read; 
     166    ubyte[] result = cast(ubyte[]) (new File(path.dup.native.toString)).read; 
    167167    return getSha1( result ); 
    168168} 
     
    183183{ 
    184184 
    185      
     185 
    186186} 
    187187//getSha1 
     
    192192    if(!path.exists) 
    193193        return null; 
    194     ubyte[] result = cast(ubyte[]) (new File(path)).read; 
     194    ubyte[] result = cast(ubyte[]) (new File(path.dup.native.toString)).read; 
    195195    return getSha256( result ); 
    196196} 
     
    224224        foreach(k,v; strings) 
    225225            assert(getSha256(v).hexDigest == results[k]); 
    226      
     226 
    227227} 
    228228//getSha256 
     
    235235    if(!path.exists) 
    236236        return null; 
    237     ubyte[] result = cast(ubyte[]) (new File(path)).read; 
     237    ubyte[] result = cast(ubyte[]) (new File(path.dup.native.toString)).read; 
    238238    return getSha512( result ); 
    239239} 
     
    269269        foreach(k,v; strings) 
    270270            assert(getSha512(v).hexDigest == results[k]); 
    271      
     271 
    272272} 
    273273//getSha512 
  • trunk/io/Path.d

    r172 r217  
    33 
    44/******************************************************************************* 
    5          
     5 
    66        copyright:      Copyright (c) 2007  (yidabu  g m a i l at com) All rights reserved 
    77 
     
    1414*******************************************************************************/ 
    1515 
    16 module dwin.io.FilePath; 
     16module dwin.io.Path; 
    1717 
    1818 
    1919import tango.io.FilePath; 
    20      
     20 
    2121version(Win32): 
    2222 
     
    2929 
    3030*/ 
    31 bool removeDirTree(char[] dir)    
    32 {        
     31bool removeDirTree(char[] dir) 
     32{ 
    3333    alias SHFILEOPSTRUCTW SHFILEOPSTRUCT; 
    34     SHFILEOPSTRUCT FileOp;  
    35      
    36     FileOp.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;  
    37     FileOp.hNameMappings = null;  
    38     FileOp.hwnd = null;  
    39     FileOp.lpszProgressTitle = null;  
    40     FileOp.pFrom = toString16zz(dir);  
    41     FileOp.pTo = null;  
    42     FileOp.wFunc = FO_DELETE;      
    43     //FileOp.fAnyOperationsAborted = FALSE;   
    44      
     34    SHFILEOPSTRUCT FileOp; 
     35 
     36    FileOp.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI; 
     37    FileOp.hNameMappings = null; 
     38    FileOp.hwnd = null; 
     39    FileOp.lpszProgressTitle = null; 
     40    FileOp.pFrom = toString16zz(dir); 
     41    FileOp.pTo = null; 
     42    FileOp.wFunc = FO_DELETE; 
     43    //FileOp.fAnyOperationsAborted = FALSE; 
     44 
    4545    bool result; 
    4646    if( SHFileOperationW(&FileOp) == 0 ) 
    4747        if( FileOp.fAnyOperationsAborted == FALSE ) 
    48             result = true;             
     48            result = true; 
    4949    return result; 
    50      
    51 }    
     50 
     51} 
    5252 
    5353/** 
     
    6060    Tango solution: 
    6161    p = p.pop.replace('\\', '/'); 
    62