Differences From Artifact [affffc4f40848d74]:
- File
src/util.d
- 2015-04-30 23:29:51 - part of checkin [ab3b073ef6] on branch trunk - private import => import (since in the latest D it is the default.) (user: kinaba) [annotate]
To Artifact [f4a72491493dc9ab]:
- File
src/util.d
-
2015-05-05 06:49:05
- part of checkin
[9b639cf2d6]
on branch trunk
- Working version for update to 2.067.
The problem was __gshared. Replacing it with TLS fixed the issue. Remaining problem is that "hack.d"'s CloseHandle hack is not working anymore.
(user: kinaba) [annotate]
-
2015-05-05 06:49:05
- part of checkin
[9b639cf2d6]
on branch trunk
- Working version for update to 2.067.
1 1 import win32.windows;
2 2 import std.string;
3 3 import std.file;
4 4
5 5 char lastChar( string s )
6 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 12 string[] cmd_parse( string str, bool in_resp=false )
75 13 {
76 14 string[] ans;
................................................................................
108 46 i = j;
109 47 }
110 48
111 49 // レスポンスファイル関連の処理
112 50 if( !in_resp && param[0]==resp_char )
113 51 {
114 52 try {
115 - string rsp = cast(string) std.file.read( param[1 .. param.length] );
53 + string rsp = cast(string) std.file.read( param[1..$] );
116 54 ans ~= cmd_parse(rsp,true);
117 55 } catch( FileException e ) {}
118 56 }
119 57 else if( param.length>=2 && param[0..2]=="--" )
120 58 {
121 59 resp_char = (param.length==2 ? '\0' : param[2]);
122 60 }