Skip to content

Commit a4519ea

Browse files
Size changes for 64bit
Compiles but no testing done for 32 or 64bit Fixes issue #16
1 parent 9fa9107 commit a4519ea

16 files changed

Lines changed: 400 additions & 360 deletions

File tree

source/juno/base/collections.d

Lines changed: 90 additions & 87 deletions
Large diffs are not rendered by default.

source/juno/base/string.d

Lines changed: 75 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ alias const(wchar*) wstringz;
4242
* if the string length is already known. Or the string
4343
* is not null teminated.
4444
*/
45-
const(T)[] toArray(T)(in T* s, size_t len = 0) if(isSomeChar!T
45+
const(T)[] toArray(T)(in T* s, sizediff_t len = 0) if(isSomeChar!T
4646
&& !is(T == dchar)) {
4747
if(len)
4848
return s[0..len];
@@ -105,11 +105,15 @@ int compare(string stringA, string stringB) {
105105

106106
/**
107107
* Compares two specified strings, ignoring or honouring their case.
108+
*
109+
* TODO: deprecated and provide a function which enables selection
110+
* of the same compare options as the Win32 function.
111+
*
108112
* Params:
109113
* stringA = The first string.
110-
* indexA = The position of the substring withing stringA.
114+
* indexA = The position of the substring within stringA.
111115
* stringB = The second string.
112-
* indexB = The position of the substring withing stringB.
116+
* indexB = The position of the substring within stringB.
113117
* ignoreCase = A value indicating a case- sensitive or insensitive comparison.
114118
* Returns: An integer indicating the lexical relationship between the two strings (less than zero if the substring in stringA is less then the substring in stringB; zero if the substrings are equal; greater than zero if the substring in stringA is greater than the substring in stringB).
115119
*/
@@ -120,9 +124,9 @@ int compare(string stringA, int indexA, string stringB, int indexB, int length,
120124
if (length != 0 && (stringA != stringB || indexA != indexB)) {
121125
int lengthA = length, lengthB = length;
122126
if (stringA.length - indexA < lengthA)
123-
lengthA = stringA.length - indexA;
127+
lengthA = cast(int)stringA.length - indexA;
124128
if (stringB.length - indexB < lengthB)
125-
lengthB = stringB.length - indexB;
129+
lengthB = cast(int)stringB.length - indexB;
126130

127131
return culture.collator.compare(stringA, indexA, lengthA, stringB, indexB, lengthB, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
128132
}
@@ -163,28 +167,29 @@ bool contains(string s, string value) {
163167

164168
/**
165169
* Retrieves the index of the first occurrence of the specified character within the specified string.
170+
*
171+
* TODO: deprecated
172+
*
166173
* Params:
167174
* s = The string to search within.
168175
* value = The character to find.
169176
* index = The start position of the search.
170177
* count = The number of characters to examine.
171178
* Returns: The index of value if that character is found, or -1 if it is not.
172179
*/
173-
int indexOf(string s, char value, int index = 0, int count = -1) {
180+
sizediff_t indexOf(string s, char value, size_t index = 0, size_t count = -1) {
174181
if (count == -1)
175182
count = s.length - index;
176183

177-
int end = index + count;
178-
for (int i = index; i < end; i++) {
179-
if (s[i] == value)
180-
return i;
181-
}
182-
183-
return -1;
184+
return std.string.indexOf(s[index..index+count], value) + index;
184185
}
185186

186187
/**
187188
* Retrieves the index of the first occurrence of the specified value in the specified string s.
189+
*
190+
* TODO: deprecated and provide a function which enables selection
191+
* of the same compare options as the Win32 function.
192+
*
188193
* Params:
189194
* s = The string to search within.
190195
* value = The string to find.
@@ -203,19 +208,21 @@ int indexOf(string s, string value, int index, int count, bool ignoreCase = fals
203208
* ditto
204209
*/
205210
int indexOf(string s, string value, int index, bool ignoreCase = false, Culture culture = null) {
206-
return indexOf(s, value, index, s.length - index, ignoreCase, culture);
211+
return indexOf(s, value, index, to!int(s.length - index),
212+
ignoreCase, culture);
207213
}
208214

209215
/**
210216
* ditto
211217
*/
212218
int indexOf(string s, string value, bool ignoreCase = false, Culture culture = null) {
213-
return indexOf(s, value, 0, s.length, ignoreCase, culture);
219+
return indexOf(s, value, 0, to!int(s.length), ignoreCase, culture);
214220
}
215221

222+
deprecated
216223
int indexOfAny(string s, in char[] anyOf, int index = 0, int count = -1) {
217224
if (count == -1)
218-
count = s.length - index;
225+
count = to!int(s.length - index);
219226

220227
int end = index + count;
221228
for (int i = index; i < end; i++) {
@@ -235,28 +242,22 @@ int indexOfAny(string s, in char[] anyOf, int index = 0, int count = -1) {
235242

236243
/**
237244
* Retrieves the index of the last occurrence of the specified character within the specified string.
245+
*
246+
* TODO: deprecated and provide a function which enables selection
247+
* of the same compare options as the Win32 function.
248+
*
238249
* Params:
239250
* s = The string to search within.
240251
* value = The character to find.
241252
* index = The start position of the search.
242253
* count = The number of characters to examine.
243254
* Returns: The index of value if that character is found, or -1 if it is not.
244255
*/
245-
int lastIndexOf(string s, char value, int index = 0, int count = -1) {
246-
if (s.length == 0)
247-
return -1;
248-
if (count == -1) {
249-
index = s.length - 1;
250-
count = s.length;
251-
}
252-
253-
int end = index - count + 1;
254-
for (int i = index; i >= end; i--) {
255-
if (s[i] == value)
256-
return i;
257-
}
256+
sizediff_t lastIndexOf(string s, char value, sizediff_t index = 0, sizediff_t count = -1) {
257+
if (count == -1)
258+
count = index+1;
258259

259-
return -1;
260+
return std.string.lastIndexOf(s[index-count..index+1], value) + index;
260261
}
261262

262263
/**
@@ -300,19 +301,21 @@ int lastIndexOf(string s, string value, int index, bool ignoreCase = false, Cult
300301
* ditto
301302
*/
302303
int lastIndexOf(string s, string value, bool ignoreCase = false, Culture culture = null) {
303-
return lastIndexOf(s, value, s.length - 1, s.length, ignoreCase, culture);
304+
return lastIndexOf(s, value, to!int(s.length - 1), to!int(s.length),
305+
ignoreCase, culture);
304306
}
305307

306-
int lastIndexOfAny(string s, in char[] anyOf, int index = -1, int count = -1) {
308+
deprecated
309+
sizediff_t lastIndexOfAny(string s, in char[] anyOf, sizediff_t index = -1, sizediff_t count = -1) {
307310
if (s.length == 0)
308311
return -1;
309312
if (count == -1) {
310313
index = s.length - 1;
311314
count = s.length;
312315
}
313316

314-
int end = index - count + 1;
315-
for (int i = index; i >= end; i--) {
317+
auto end = index - count + 1;
318+
for (auto i = index; i >= end; i--) {
316319
int k = -1;
317320
for (int j = 0; j < anyOf.length; j++) {
318321
if (s[i] == anyOf[j]) {
@@ -369,12 +372,12 @@ bool endsWith(string s, string value, bool ignoreCase = false, Culture culture =
369372
* Returns: A new string with value inserted at index.
370373
*/
371374
//@@TODO@@ The currently disabled std.array.insert is pretty much the same as this
372-
string insert(string s, size_t index, string value) {
375+
string insert(string s, sizediff_t index, string value) {
373376
if (value.length == 0 || s.length == 0) {
374377
return s.idup;
375378
}
376379

377-
size_t newLength = s.length + value.length;
380+
sizediff_t newLength = s.length + value.length;
378381
char[] newString = new char[newLength];
379382

380383
newString[0 .. index] = s[0 .. index];
@@ -391,7 +394,7 @@ string insert(string s, size_t index, string value) {
391394
* count = The number of characters to delete.
392395
* Returns: A new string equivalent to s less count number of characters.
393396
*/
394-
string remove(string s, int index, int count) {
397+
string remove(string s, size_t index, size_t count) {
395398
char[] ret = new char[s.length - count];
396399
memcpy(ret.ptr, s.ptr, index);
397400
memcpy(ret.ptr + index, s.ptr + (index + count), s.length - (index + count));
@@ -474,6 +477,9 @@ string[] split(string s, char[] separator...) {
474477

475478
/**
476479
* Returns a string array containing the substrings in s that are delimited by elements of the specified string array.
480+
*
481+
* TODO: deprecated
482+
*
477483
* Params:
478484
* s = The string to _split.
479485
* separator = An array of strings that delimit the substrings in s.
@@ -483,7 +489,7 @@ string[] split(string s, char[] separator...) {
483489
*/
484490
string[] split(string s, string[] separator, int count = int.max, bool removeEmptyEntries = false) {
485491

486-
int createSeparatorList(ref int[] sepList, ref int[] lengthList) {
492+
int createSeparatorList(ref int[] sepList, ref sizediff_t[] lengthList) {
487493
int foundCount;
488494

489495
for (int i = 0; i < s.length && foundCount < sepList.length; i++) {
@@ -508,8 +514,8 @@ string[] split(string s, string[] separator, int count = int.max, bool removeEmp
508514
if (count == 0 || (removeEmptyEntries && s.length == 0))
509515
return new string[0];
510516

511-
int[] sepList = new int[s.length];
512-
int[] lengthList = new int[s.length];
517+
auto sepList = new int[s.length];
518+
auto lengthList = new sizediff_t[s.length];
513519
int replaceCount = createSeparatorList(sepList, lengthList);
514520

515521
if (replaceCount == 0 || count == 1)
@@ -525,9 +531,9 @@ string[] split(string s, string[] separator, bool removeEmptyEntries) {
525531
return split(s, separator, int.max, removeEmptyEntries);
526532
}
527533

528-
private string[] splitImpl(string s, int[] sepList, int[] lengthList, int replaceCount, int count, bool removeEmptyEntries) {
534+
private string[] splitImpl(string s, int[] sepList, sizediff_t[] lengthList, int replaceCount, int count, bool removeEmptyEntries) {
529535
string[] splitStrings;
530-
int arrayIndex, currentIndex;
536+
sizediff_t arrayIndex, currentIndex;
531537

532538
if (removeEmptyEntries) {
533539
int max = (replaceCount < count) ? replaceCount + 1 : count;
@@ -575,22 +581,25 @@ private string[] splitImpl(string s, int[] sepList, int[] lengthList, int replac
575581

576582
/**
577583
* Concatenates separator between each element of value, returning a single concatenated string.
584+
*
585+
* TODO: deprecated
586+
*
578587
* Params:
579588
* separator = A string.
580589
* value = An array of strings.
581590
* index = The first element in value to use.
582591
* count = The number of elements of value to use.
583592
* Returns: A string containing the strings in value joined by separator.
584593
*/
585-
string join(string separator, string[] value, int index = 0, int count = -1) {
594+
string join(string separator, string[] value, sizediff_t index = 0, sizediff_t count = -1) {
586595
if (count == -1)
587596
count = value.length;
588597
if (count == 0)
589598
return "";
590599

591-
int end = index + count - 1;
600+
auto end = index + count - 1;
592601
string ret = value[index];
593-
for (int i = index + 1; i <= end; i++) {
602+
for (sizediff_t i = index + 1; i <= end; i++) {
594603
ret ~= separator;
595604
ret ~= value[i];
596605
}
@@ -600,13 +609,16 @@ string join(string separator, string[] value, int index = 0, int count = -1) {
600609
/**
601610
* Replaces all instances of oldChar with newChar in s.
602611
* Params:
612+
*
613+
* TODO: deprecated
614+
*
603615
* s = A string containing oldChar.
604616
* oldChar = The character to be replaced.
605617
* newChar = The character to replace all instances of oldChar.
606618
* Returns: A string equivalent to s but with all instances of oldChar replaced with newChar.
607619
*/
608620
string replace(string s, char oldChar, char newChar) {
609-
int len = s.length;
621+
sizediff_t len = s.length;
610622
int firstFound = -1;
611623
for (int i = 0; i < len; i++) {
612624
if (oldChar == s[i]) {
@@ -620,24 +632,27 @@ string replace(string s, char oldChar, char newChar) {
620632

621633
char[] ret = s[0 .. firstFound].dup;
622634
ret.length = len;
623-
for (int i = firstFound; i < len; i++)
635+
for (sizediff_t i = firstFound; i < len; i++)
624636
ret[i] = (s[i] == oldChar) ? newChar : s[i];
625637
return assumeUnique(ret);
626638
}
627639

628640
/**
629641
* Replaces all instances of oldValue with newValue in s.
630642
* Params:
643+
*
644+
* TODO: deprecated
645+
*
631646
* s = A string containing oldValue.
632647
* oldValue = The string to be replaced.
633648
* newValue = The string to replace all instances of oldValue.
634649
* Returns: A string equivalent to s but with all instances of oldValue replaced with newValue.
635650
*/
636651
string replace(string s, string oldValue, string newValue) {
637-
int[] indices = new int[s.length + oldValue.length];
652+
auto indices = new int[s.length + oldValue.length];
638653

639654
int index, count;
640-
while (((index = indexOf(s, oldValue, index, s.length)) > -1) &&
655+
while (((index = indexOf(s, oldValue, index, to!int(s.length))) > -1) &&
641656
(index <= s.length - oldValue.length)) {
642657
indices[count++] = index;
643658
index += oldValue.length;
@@ -727,6 +742,9 @@ string trimStart(string s, char[] trimChars ...) {
727742

728743
/**
729744
* Removes all trailing occurrences of a set of characters specified in trimChars from s.
745+
*
746+
* TODO: deprecated
747+
*
730748
* Returns: The string that remains after all occurrences of the characters in trimChars are removed from the end of s.
731749
*/
732750
string trimEnd(string s, char[] trimChars ...) {
@@ -737,8 +755,8 @@ string trimEnd(string s, char[] trimChars ...) {
737755

738756
@safe nothrow pure
739757
private string trimHelper(string s, in char[] trimChars, Trim trimType) {
740-
int right = s.length - 1;
741-
int left;
758+
size_t right = s.length - 1;
759+
size_t left;
742760

743761
// Trim head
744762
if (trimType != Trim.Tail) {
@@ -769,7 +787,7 @@ private string trimHelper(string s, in char[] trimChars, Trim trimType) {
769787
}
770788
}
771789

772-
int len = right - left + 1;
790+
size_t len = right - left + 1;
773791
if (len == s.length)
774792
return s;
775793
if (len == 0)
@@ -1033,9 +1051,9 @@ private struct ArgumentList {
10331051
}
10341052

10351053
pure
1036-
private void append(ref string s, char value, int count) {
1054+
private void append(ref string s, char value, size_t count) {
10371055
char[] d = s.dup;
1038-
int n = d.length;
1056+
size_t n = d.length;
10391057
d.length = d.length + count;
10401058
d[n..$] = value;
10411059

@@ -1081,11 +1099,11 @@ string format(IFormatProvider provider, string format, ...) {
10811099

10821100
string result;
10831101
char[] chars = format.dup;
1084-
int pos, len = format.length;
1102+
size_t pos, len = format.length;
10851103
char c;
10861104

10871105
while (true) {
1088-
int p = pos, i = pos;
1106+
size_t p = pos, i = pos;
10891107
while (pos < len) {
10901108
c = chars[pos];
10911109
pos++;
@@ -1192,7 +1210,7 @@ string format(IFormatProvider provider, string format, ...) {
11921210

11931211
string s = arg.toString(fmt, provider);
11941212

1195-
int padding = width - s.length;
1213+
size_t padding = width - s.length;
11961214
if (!leftAlign && padding > 0)
11971215
append(result, ' ', padding);
11981216

0 commit comments

Comments
 (0)