annotate dwt/dwthelper/array.d @ 126:38807a925e24

Fixed compile errors, support for SWT language files
author Jacob Carlborg <doob@me.com>
date Fri, 16 Jan 2009 23:35:40 +0100
parents 63a09873578e
children ad4e1fe71a5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 * Throws: AssertException if the length of the array is 0
123
63a09873578e Fixed compile errors
Jacob Carlborg <doob@me.com>
parents: 122
diff changeset
29 * Throws: AssertException if the element is null
60
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 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
32 in
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 assert(arr.length > 0);
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
35 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
36 body
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
37 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
38 return arr ~= element;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
39 }
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 /**
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
42 * 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
43 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
44 * Params:
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
45 * 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
46 * 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
47 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
48 * Returns: the modified array
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
49 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
50 * Throws: AssertException if the length of the array is 0
123
63a09873578e Fixed compile errors
Jacob Carlborg <doob@me.com>
parents: 122
diff changeset
51 * Throws: AssertException if the element is null
60
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 alias add addElement;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
54
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
55 /**
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
56 * Gets the element at the specified index
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
57 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
58 * Params:
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
59 * 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
60 * 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
61 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
62 * Returns: the element at the specified index
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
63 */
122
2e671fa40eec Ported dwt.dnd, dwt.opengl, dwt.printing and dwt.program
Jacob Carlborg <doob@me.com>
parents: 99
diff changeset
64 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
65 in
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
66 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
67 assert(arr.length > 0);
122
2e671fa40eec Ported dwt.dnd, dwt.opengl, dwt.printing and dwt.program
Jacob Carlborg <doob@me.com>
parents: 99
diff changeset
68 assert(index > -1 && index < arr.length);
60
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
69 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
70 body
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
71 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
72 return arr[index];
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
73 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
74
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
75 /**
123
63a09873578e Fixed compile errors
Jacob Carlborg <doob@me.com>
parents: 122
diff changeset
76 * Gets the element at the specified index
99
d32621bf0f90 Ported dwt.dnd.DropTarget
Jacob Carlborg <doob@me.com>
parents: 60
diff changeset
77 *
d32621bf0f90 Ported dwt.dnd.DropTarget
Jacob Carlborg <doob@me.com>
parents: 60
diff changeset
78 * Params:
d32621bf0f90 Ported dwt.dnd.DropTarget
Jacob Carlborg <doob@me.com>
parents: 60
diff changeset
79 * arr = the array to get the element from
d32621bf0f90 Ported dwt.dnd.DropTarget
Jacob Carlborg <doob@me.com>
parents: 60
diff changeset
80 * index = the index of the element to get
d32621bf0f90 Ported dwt.dnd.DropTarget
Jacob Carlborg <doob@me.com>
parents: 60
diff changeset
81 *
123
63a09873578e Fixed compile errors
Jacob Carlborg <doob@me.com>
parents: 122
diff changeset
82 * Returns: the element at the specified index
99
d32621bf0f90 Ported dwt.dnd.DropTarget
Jacob Carlborg <doob@me.com>
parents: 60
diff changeset
83 */
d32621bf0f90 Ported dwt.dnd.DropTarget
Jacob Carlborg <doob@me.com>
parents: 60
diff changeset
84 alias elementAt get;
d32621bf0f90 Ported dwt.dnd.DropTarget
Jacob Carlborg <doob@me.com>
parents: 60
diff changeset
85
d32621bf0f90 Ported dwt.dnd.DropTarget
Jacob Carlborg <doob@me.com>
parents: 60
diff changeset
86 /**
60
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
87 * 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
88 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
89 * Params:
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
90 * 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
91 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
92 * 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
93 */
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
94 size_t size (T) (T[] arr)
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
95 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
96 return arr.length;
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
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
99 /**
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
100 * 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
101 * 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
102 * Shifts any subsequent elements to the left.
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
103 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
104 * Params:
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
105 * 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
106 * 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
107 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
108 * 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
109 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
110 * Throws: AssertException if the length of the array is 0
123
63a09873578e Fixed compile errors
Jacob Carlborg <doob@me.com>
parents: 122
diff changeset
111 * 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
112 * 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
113 */
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
114 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
115 in
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
116 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
117 assert(arr.length > 0);
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
118 assert(index > -1 && index < arr.length);
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 body
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
121 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
122 T ret = arr[index];
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
123
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
124 // 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
125 // not inline the reference-based version.
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
126 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
127 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
128 T t = arr[p1];
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
129 arr[p1] = arr[p2];
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
130 arr[p2] = t;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
131 }
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 size_t cnt = 0;
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 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
136 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
137 if (pos == index)
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
138 ++cnt;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
139 else
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
140 exch(pos, pos - cnt);
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
141 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
142
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
143 arr = arr[0 .. $ - cnt];
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 return ret;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
146 }
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 /**
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
149 * Removes the specified element from the array
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
150 * 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
151 * Shifts any subsequent elements to the left.
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 * Params:
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
154 * 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
155 * element = the element to be removed
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 * 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
158 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
159 * 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
160 */
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
161 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
162 in
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 assert(arr.length > 0);
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
165 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
166 out (result)
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 assert(result is element || result is null);
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
169 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
170 body
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 int index = arr.indexOf(element);
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 if (index == -1)
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
175 return null;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
176
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
177 return arr.remove(index);
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
178 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
179
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
180 /**
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
181 * Removes the specified element from the array
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
182 * 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
183 * Shifts any subsequent elements to the left.
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
184 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
185 * Params:
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
186 * 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
187 * element = the element to be removed
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
188 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
189 * 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
190 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
191 * 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
192 */
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
193 alias remove removeElement;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
194
126
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
195 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
196 if (n is 0)
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
197 return arr[1..$];
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
198 if (n > arr.length)
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
199 return arr;
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
200 if (n is arr.length-1)
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
201 return arr[0..n-1];
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
202 // else
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
203 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
204 }
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
205
60
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
206 /**
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
207 * 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
208 * 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
209 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
210 * Params:
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
211 * 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
212 * element = the element to find
126
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
213 * 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
214 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
215 * 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
216 *
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
217 * 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
218 * 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
219 * 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
220 */
126
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
221 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
222 in
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
223 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
224 assert(arr.length > 0);
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
225 assert(start >= 0);
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
226 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
227 out (result)
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
228 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
229 assert(result >= -1 && result < arr.length);
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
230 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
231 body
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
232 {
126
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
233 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
234
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
235 if (index != arr.length)
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
236 return index;
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 else
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
239 return -1;
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
240 }
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
241
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
242 /**
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
243 * 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
244 * 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
245 *
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
246 * Params:
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
247 * 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
248 * element = the element to find
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
249 * 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
250 *
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
251 * 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
252 *
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
253 * Throws: AssertException if the length of the array is 0
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
254 * 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
255 * 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
256 */
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
257 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
258 in
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
259 {
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
260 assert(arr.length > 0);
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
261 assert(start >= 0);
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
262 }
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
263 out (result)
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
264 {
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
265 assert(result >= -1 && result < arr.length);
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
266 }
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
267 body
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
268 {
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
269 size_t index;
60
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
270
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
271 version (Tango)
126
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
272 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
273
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
274 else
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 if (start > arr.length)
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
277 start = arr.length;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
278
126
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
279 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
280 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
281
126
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
282 if (index != arr.length)
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
283 return index;
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
284 else
38807a925e24 Fixed compile errors, support for SWT language files
Jacob Carlborg <doob@me.com>
parents: 123
diff changeset
285 return -1;
60
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
286
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
287 version (Phobos)
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
288 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
289 // tango.text.Util.locate
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
290 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
291 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
292 version (D_InlineAsm_X86)
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
293 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
294 static if (T.sizeof == 1)
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
295 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
296 asm
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
297 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
298 mov EDI, str;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
299 mov ECX, length;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
300 movzx EAX, match;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
301 mov ESI, ECX;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
302 and ESI, ESI;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
303 jz end;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
304
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
305 cld;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
306 repnz;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
307 scasb;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
308 jnz end;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
309 sub ESI, ECX;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
310 dec ESI;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
311 end:;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
312 mov EAX, ESI;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
313 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
314 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
315 else static if (T.sizeof == 2)
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
316 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
317 asm
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 mov EDI, str;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
320 mov ECX, length;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
321 movzx EAX, match;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
322 mov ESI, ECX;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
323 and ESI, ESI;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
324 jz end;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
325
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
326 cld;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
327 repnz;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
328 scasw;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
329 jnz end;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
330 sub ESI, ECX;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
331 dec ESI;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
332 end:;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
333 mov EAX, ESI;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
334 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
335 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
336
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
337 else static if (T.sizeof == 4)
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
338 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
339 asm
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 mov EDI, str;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
342 mov ECX, length;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
343 mov EAX, match;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
344 mov ESI, ECX;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
345 and ESI, ESI;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
346 jz end;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
347
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
348 cld;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
349 repnz;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
350 scasd;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
351 jnz end;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
352 sub ESI, ECX;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
353 dec ESI;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
354 end:;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
355 mov EAX, ESI;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
356 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
357 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
358
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
359 else
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
360 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
361 auto len = length;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
362
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
363 for (auto p = str - 1; len--; )
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
364 if (*++p is match)
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
365 return p - str;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
366
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
367 return length;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
368 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
369 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
370
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
371 else
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
372 {
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
373 auto len = length;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
374
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
375 for (auto p = str - 1; len--; )
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
376 if (*++p is match)
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
377 return p - str;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
378
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
379 return length;
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
380 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
381 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
382 }
62202ce0039f Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
diff changeset
383 }