Diff

Not logged in

Differences From Artifact [affffc4f40848d74]:

To Artifact [f4a72491493dc9ab]:


1 import win32.windows; 1 import win32.windows; 2 import std.string; 2 import std.string; 3 import std.file; 3 import std.file; 4 4 5 char lastChar( string s ) 5 char lastChar( string s ) 6 { return *CharPrevA(cast(char*)s.ptr, cast(char*)s.ptr+s.length); } 6 { return *CharPrevA(cast(char*)s.ptr, cast(char*)s.ptr+s.length); } 7 7 8 //---------------------------------------------------------------- < 9 // int do_opApply!(E, C)( collection, delegate ); < 10 // int do_opApply!(E) ( array, delegate ); < 11 // forwarding the opApply call to another collection < 12 //---------------------------------------------------------------- < 13 < 14 template do_opApply( Elem, Collection ) < 15 { < 16 int do_opApply( Collection c, int delegate(inout Elem) dg ) < 17 { < 18 int result = 0; < 19 foreach( Elem x ; c ) < 20 if( 0 != (result=dg(x)) ) < 21 break; < 22 return result; < 23 } < 24 } < 25 < 26 template do_opApply( E ) < 27 { < 28 int do_opApply( E[] c, int delegate(inout E) dg ) < 29 { < 30 return .do_opApply!(E,E[])( c, dg ); < 31 } < 32 } < 33 < 34 //---------------------------------------------------------------- < 35 // class set!(T) < 36 // add : T -> void < 37 // remove : T -> void < 38 // has : T -> bool < 39 // elems : () -> T[] < 40 // length : () -> int < 41 //---------------------------------------------------------------- < 42 < 43 class set(T) < 44 { < 45 void add ( T x ) { data[x]; } < 46 void remove( T x ) { delete data[x]; } < 47 bool has ( T x ) { return x in data; } < 48 T[] elems () { return data.keys; } < 49 int opApply( int delegate(inout T) dg ) < 50 { return do_opApply!(T)( elems, dg ); } < 51 int length() { return data.length; } < 52 private void[T] data; < 53 } < 54 < 55 unittest < 56 { < 57 set!(int) x = new set!(int); < 58 x.add(1); < 59 x.add(2); < 60 x.add(3); < 61 assert( x.elems[0] + x.elems[1] + x.elems[2] == 6 ); < 62 assert( x.length == 3 ); < 63 x.remove(4); < 64 x.remove(3); < 65 x.remove(1); < 66 assert( x.length == 1 ); < 67 foreach( int t ; x ) assert( t==2 ); < 68 } < 69 < 70 //---------------------------------------------------------------- 8 //---------------------------------------------------------------- 71 // コマンドライン解析 9 // コマンドライン解析 72 //---------------------------------------------------------------- 10 //---------------------------------------------------------------- 73 11 74 string[] cmd_parse( string str, bool in_resp=false ) 12 string[] cmd_parse( string str, bool in_resp=false ) 75 { 13 { 76 string[] ans; 14 string[] ans; ................................................................................................................................................................................ 108 i = j; 46 i = j; 109 } 47 } 110 48 111 // レスポンスファイル関連の処理 49 // レスポンスファイル関連の処理 112 if( !in_resp && param[0]==resp_char ) 50 if( !in_resp && param[0]==resp_char ) 113 { 51 { 114 try { 52 try { 115 string rsp = cast(string) std.file.read( param[1 | 53 string rsp = cast(string) std.file.read( param[1 116 ans ~= cmd_parse(rsp,true); 54 ans ~= cmd_parse(rsp,true); 117 } catch( FileException e ) {} 55 } catch( FileException e ) {} 118 } 56 } 119 else if( param.length>=2 && param[0..2]=="--" ) 57 else if( param.length>=2 && param[0..2]=="--" ) 120 { 58 { 121 resp_char = (param.length==2 ? '\0' : param[2]); 59 resp_char = (param.length==2 ? '\0' : param[2]); 122 } 60 }