Mercurial > projects > dwt-mac
annotate dwt/dwthelper/array.d @ 156:969e7de37c3d default tip
Fixes to get dwt to work with dmd and ldc
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 08 Jul 2009 21:56:44 +0200 |
parents | 3d4579727e0e |
children |
rev | line source |
---|---|
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
1 /** |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
2 * Copyright: Copyright (c) 2008 Jacob Carlborg. All rights reserved. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
3 * Authors: Jacob Carlborg |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
4 * Version: Initial created: 2008 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
5 * License: $(LINK2 http://opensource.org/licenses/bsd-license.php, BSD Style) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
6 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
7 */ |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
8 module dwt.dwthelper.array; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
9 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
10 version (Tango) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
11 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
12 static import tango.text.Util; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
13 static import tango.core.Array; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
14 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
15 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
16 else |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
17 version = Phobos; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
18 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
19 /** |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
20 * Appends the specified element to the end of the array. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
21 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
22 * Params: |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
23 * arr = the array to add the element to |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
24 * element = element to be appended to this list |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
25 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
26 * Returns: the modified array |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
27 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
28 */ |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
29 T[] add (T) (ref T[] arr, T element) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
30 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
31 return arr ~= element; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
32 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
33 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
34 /** |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
35 * Appends the specified element to the end of the array. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
36 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
37 * Params: |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
38 * arr = the array to add the element to |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
39 * element = element to be appended to this list |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
40 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
41 * Returns: the modified array |
129 | 42 * |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
43 */ |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
44 alias add addElement; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
45 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
46 /** |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
47 * Gets the element at the specified index |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
48 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
49 * Params: |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
50 * arr = the array to get the element from |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
51 * index = the index of the element to get |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
52 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
53 * Returns: the element at the specified index |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
54 */ |
122
2e671fa40eec
Ported dwt.dnd, dwt.opengl, dwt.printing and dwt.program
Jacob Carlborg <doob@me.com>
parents:
99
diff
changeset
|
55 T elementAt (T) (T[] arr, int index) |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
56 in |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
57 { |
122
2e671fa40eec
Ported dwt.dnd, dwt.opengl, dwt.printing and dwt.program
Jacob Carlborg <doob@me.com>
parents:
99
diff
changeset
|
58 assert(index > -1 && index < arr.length); |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
59 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
60 body |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
61 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
62 return arr[index]; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
63 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
64 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
65 /** |
123 | 66 * Gets the element at the specified index |
99 | 67 * |
68 * Params: | |
69 * arr = the array to get the element from | |
70 * index = the index of the element to get | |
71 * | |
123 | 72 * Returns: the element at the specified index |
99 | 73 */ |
74 alias elementAt get; | |
75 | |
76 /** | |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
77 * Returns the number of elements in the specified array. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
78 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
79 * Params: |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
80 * arr = the array to get the number of elements from |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
81 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
82 * Returns: the number of elements in this list |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
83 */ |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
84 size_t size (T) (T[] arr) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
85 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
86 return arr.length; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
87 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
88 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
89 /** |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
90 * Removes the element at the specified position in the array |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
91 * if it could find it and returns it. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
92 * Shifts any subsequent elements to the left. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
93 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
94 * Params: |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
95 * arr = the array to remove the element from |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
96 * index = the index of the element to be removed |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
97 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
98 * Returns: the element that was removed or $(D_CODE null) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
99 * |
123 | 100 * Throws: AssertException if the $(D_CODE index) argument is |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
101 * negative or not less than the length of this array. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
102 */ |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
103 T remove (T) (ref T[] arr, int index) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
104 in |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
105 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
106 assert(index > -1 && index < arr.length); |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
107 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
108 body |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
109 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
110 T ret = arr[index]; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
111 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
112 // NOTE: Indexes are passed instead of references because DMD does |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
113 // not inline the reference-based version. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
114 void exch (size_t p1, size_t p2) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
115 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
116 T t = arr[p1]; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
117 arr[p1] = arr[p2]; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
118 arr[p2] = t; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
119 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
120 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
121 size_t cnt = 0; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
122 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
123 for (size_t pos = 0, len = arr.length; pos < len; ++pos) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
124 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
125 if (pos == index) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
126 ++cnt; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
127 else |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
128 exch(pos, pos - cnt); |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
129 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
130 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
131 arr = arr[0 .. $ - cnt]; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
132 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
133 return ret; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
134 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
135 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
136 /** |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
137 * Removes the specified element from the array |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
138 * if it could find it and returns it. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
139 * Shifts any subsequent elements to the left. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
140 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
141 * Params: |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
142 * arr = the array to remove the element from |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
143 * element = the element to be removed |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
144 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
145 * Returns: the element that was removed or $(null null) |
129 | 146 * |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
147 */ |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
148 T remove (T) (ref T[] arr, T element) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
149 out (result) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
150 { |
129 | 151 assert(result is element); |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
152 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
153 body |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
154 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
155 int index = arr.indexOf(element); |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
156 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
157 if (index == -1) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
158 return null; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
159 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
160 return arr.remove(index); |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
161 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
162 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
163 /** |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
164 * Removes the specified element from the array |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
165 * if it could find it and returns it. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
166 * Shifts any subsequent elements to the left. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
167 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
168 * Params: |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
169 * arr = the array to remove the element from |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
170 * element = the element to be removed |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
171 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
172 * Returns: the element that was removed or $(null null) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
173 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
174 * Throws: AssertException if the length of the array is 0 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
175 */ |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
176 alias remove removeElement; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
177 |
126
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
178 T[] arrayIndexRemove(T, U = size_t)(T[] arr, U n) { |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
179 if (n is 0) |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
180 return arr[1..$]; |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
181 if (n > arr.length) |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
182 return arr; |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
183 if (n is arr.length-1) |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
184 return arr[0..n-1]; |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
185 // else |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
186 return arr[0..n] ~ arr[n+1..$]; |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
187 } |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
188 |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
189 /** |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
190 * Returns the index of the first occurrence of the specified element |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
191 * in the array, or -1 if the array does not contain the element. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
192 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
193 * Params: |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
194 * arr = the array to get the index of the element from |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
195 * element = the element to find |
126
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
196 * start = the index of where to start searching from |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
197 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
198 * Returns: the index of the element or -1 if it's not in the array |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
199 * |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
200 * Throws: AssertException if the return value is less than -1 or |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
201 * greater than the length of the array - 1. |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
202 */ |
126
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
203 size_t indexOf (T, U = size_t) (T[] arr, T[] match, U start = 0) |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
204 in |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
205 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
206 assert(start >= 0); |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
207 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
208 body |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
209 { |
126
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
210 size_t index = tango.text.Util.locatePattern(arr, match, start); |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
211 |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
212 if (index != arr.length) |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
213 return index; |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
214 |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
215 else |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
216 return -1; |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
217 } |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
218 |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
219 /** |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
220 * Returns the index of the first occurrence of the specified element |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
221 * in the array, or -1 if the array does not contain the element. |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
222 * |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
223 * Params: |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
224 * arr = the array to get the index of the element from |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
225 * element = the element to find |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
226 * start = the index of where to start searching from |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
227 * |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
228 * Returns: the index of the element or -1 if it's not in the array |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
229 * |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
230 * Throws: AssertException if the return value is less than -1 or |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
231 * greater than the length of the array - 1. |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
232 */ |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
233 size_t indexOf (T, U = size_t) (T[] arr, T element, U start = 0) |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
234 in |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
235 { |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
236 assert(start >= 0); |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
237 } |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
238 body |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
239 { |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
240 size_t index; |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
241 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
242 version (Tango) |
126
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
243 index = cast(size_t) tango.text.Util.locate(arr, element, start); |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
244 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
245 else |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
246 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
247 if (start > arr.length) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
248 start = arr.length; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
249 |
126
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
250 index = cast(size_t) privateIndexOf(arr.ptr, element, arr.length - start) + start; |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
251 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
252 |
126
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
253 if (index != arr.length) |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
254 return index; |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
255 else |
38807a925e24
Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents:
123
diff
changeset
|
256 return -1; |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
257 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
258 version (Phobos) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
259 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
260 // tango.text.Util.locate |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
261 uint privateIndexOf (T* str, T match, uint length) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
262 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
263 version (D_InlineAsm_X86) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
264 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
265 static if (T.sizeof == 1) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
266 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
267 asm |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
268 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
269 mov EDI, str; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
270 mov ECX, length; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
271 movzx EAX, match; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
272 mov ESI, ECX; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
273 and ESI, ESI; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
274 jz end; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
275 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
276 cld; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
277 repnz; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
278 scasb; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
279 jnz end; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
280 sub ESI, ECX; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
281 dec ESI; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
282 end:; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
283 mov EAX, ESI; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
284 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
285 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
286 else static if (T.sizeof == 2) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
287 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
288 asm |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
289 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
290 mov EDI, str; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
291 mov ECX, length; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
292 movzx EAX, match; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
293 mov ESI, ECX; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
294 and ESI, ESI; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
295 jz end; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
296 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
297 cld; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
298 repnz; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
299 scasw; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
300 jnz end; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
301 sub ESI, ECX; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
302 dec ESI; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
303 end:; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
304 mov EAX, ESI; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
305 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
306 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
307 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
308 else static if (T.sizeof == 4) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
309 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
310 asm |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
311 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
312 mov EDI, str; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
313 mov ECX, length; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
314 mov EAX, match; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
315 mov ESI, ECX; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
316 and ESI, ESI; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
317 jz end; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
318 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
319 cld; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
320 repnz; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
321 scasd; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
322 jnz end; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
323 sub ESI, ECX; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
324 dec ESI; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
325 end:; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
326 mov EAX, ESI; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
327 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
328 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
329 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
330 else |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
331 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
332 auto len = length; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
333 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
334 for (auto p = str - 1; len--; ) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
335 if (*++p is match) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
336 return p - str; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
337 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
338 return length; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
339 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
340 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
341 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
342 else |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
343 { |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
344 auto len = length; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
345 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
346 for (auto p = str - 1; len--; ) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
347 if (*++p is match) |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
348 return p - str; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
349 |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
350 return length; |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
351 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
352 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
353 } |
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
354 } |