diff --git a/source/juno/base/collections.d b/source/juno/base/collections.d
index 0aabfcc..5e289e6 100644
--- a/source/juno/base/collections.d
+++ b/source/juno/base/collections.d
@@ -4,13 +4,14 @@
* License: See $(LINK2 ..\..\licence.txt, licence.txt) for use and distribution terms.
*/
module juno.base.collections;
- deprecated:
import juno.base.core,
juno.locale.core,
std.math;
import std.c.string : memmove, memset;
+import std.conv;
+
/**
* bool delegate(T a, T b)
*/
@@ -253,13 +254,13 @@ abstract class Comparer(T) : IComparer!(T) {
* length = The number of elements in the range to _sort.
* comparison = The Comparison(T) to use when comparing element.
*/
-void sort(T, TIndex = int, TLength = TIndex)(T[] array, TIndex index, TLength length, int delegate(T, T) comparison = null) {
+void sort(T, TIndex = size_t, TLength = TIndex)(T[] array, TIndex index, TLength length, int delegate(T, T) comparison = null) {
- void quickSortImpl(int left, int right) {
+ void quickSortImpl(size_t left, size_t right) {
if (left >= right)
return;
- int i = left, j = right;
+ TLength i = left, j = right;
T pivot = array[i + ((j - i) >> 1)];
do {
@@ -303,24 +304,26 @@ void sort(T)(T[] array, int delegate(T, T) comparison = null) {
/**
* Searches a range of elements in an _array for a value using the specified Comparison(T).
+ *
+ * TODO: deprecated use std.algorithms.binarySearch
* Params:
* array = The _array to search.
* index = The starting _index of the range to search.
* length = The number of elements in the range to search.
* comparison = The Comparison(T) to use when comparing elements.
*/
-int binarySearch(T, TIndex = int, TLength = TIndex)(T[] array, TIndex index, TLength length, T value, int delegate(T, T) comparison = null) {
+sizediff_t binarySearch(T, TIndex = size_t, TLength = TIndex)(T[] array, TIndex index, TLength length, T value, int delegate(T, T) comparison = null) {
if (comparison is null) {
comparison = (T a, T b) {
return comparisonImpl(a, b);
};
}
- int lo = cast(int)index;
- int hi = cast(int)(index + length - 1);
+ auto lo = to!(sizediff_t)(index);
+ auto hi = to!(sizediff_t)((index + length - 1));
while (lo <= hi) {
- int i = lo + ((hi - lo) >> 1);
- int order = comparison(array[i], value);
+ auto i = lo + ((hi - lo) >> 1);
+ auto order = comparison(array[i], value);
if (order == 0)
return i;
if (order < 0)
@@ -410,7 +413,7 @@ interface ICollection(T) : IEnumerable!(T) {
/**
* $(I Property.) Gets the number of elements in the collection.
*/
- @property int count();
+ @property size_t count();
}
@@ -419,7 +422,7 @@ interface ICollection(T) : IEnumerable!(T) {
*/
interface IList(T) : ICollection!(T) {
- int indexOf(T item);
+ size_t indexOf(T item);
/**
* Inserts an _item at the specified _index.
@@ -427,13 +430,13 @@ interface IList(T) : ICollection!(T) {
* index = The _index at which item should be inserted.
* item = The object to insert.
*/
- void insert(int index, T item);
+ void insert(size_t index, T item);
/**
* Removes the item at the specified _index.
* Params: index = The _index of the item to remove.
*/
- void removeAt(int index);
+ void removeAt(size_t index);
/**
* Gets or sets the object at the specified _index.
@@ -441,12 +444,12 @@ interface IList(T) : ICollection!(T) {
* value = The item at the specified _index.
* index = The _index of the item to get or set.
*/
- void opIndexAssign(T value, int index);
+ void opIndexAssign(T value, size_t index);
/**
* ditto
*/
- T opIndex(int index);
+ T opIndex(size_t index);
}
@@ -455,18 +458,18 @@ interface IList(T) : ICollection!(T) {
*/
class List(T) : IList!(T) {
- private enum DEFAULT_CAPACITY = 4;
+ private const int DEFAULT_CAPACITY = 4;
private T[] items_;
- private int size_;
+ private size_t size_;
- private int index_;
+ private size_t index_;
/**
* Initializes a new instance with the specified _capacity.
* Params: capacity = The number of elements the new list can store.
*/
- this(int capacity = 0) {
+ this(size_t capacity = 0) {
items_.length = capacity;
}
@@ -519,7 +522,7 @@ class List(T) : IList!(T) {
* index = The _index at which item should be inserted.
* item = The element to insert.
*/
- final void insert(int index, T item) {
+ final void insert(size_t index, T item) {
if (size_ == items_.length)
ensureCapacity(size_ + 1);
@@ -536,7 +539,7 @@ class List(T) : IList!(T) {
* index = The _index at which the new elements should be inserted.
* range = The _range whose elements should be inserted into the list.
*/
- final void insertRange(int index, T[] range) {
+ final void insertRange(size_t index, T[] range) {
foreach (item; range) {
insert(index++, item);
}
@@ -545,7 +548,7 @@ class List(T) : IList!(T) {
/**
* ditto
*/
- final void insertRange(int index, IEnumerable!(T) range) {
+ final void insertRange(size_t index, IEnumerable!(T) range) {
foreach (item; range) {
insert(index++, item);
}
@@ -554,7 +557,7 @@ class List(T) : IList!(T) {
/**
*/
final bool remove(T item) {
- int index = indexOf(item);
+ size_t index = indexOf(item);
if (index < 0)
return false;
@@ -563,7 +566,7 @@ class List(T) : IList!(T) {
return true;
}
- final void removeAt(int index) {
+ final void removeAt(size_t index) {
size_--;
if (index < size_)
.copy(items_, index + 1, items_, index, size_ - index);
@@ -572,7 +575,7 @@ class List(T) : IList!(T) {
/**
*/
- final void removeRange(int index, int count) {
+ final void removeRange(size_t index, size_t count) {
if (count > 0) {
size_ -= count;
if (index < size_)
@@ -602,13 +605,13 @@ class List(T) : IList!(T) {
/**
*/
- final int indexOf(T item) {
+ final size_t indexOf(T item) {
return indexOf(item, null);
}
/**
*/
- final int indexOf(T item, EqualityComparison!(T) comparison) {
+ final size_t indexOf(T item, EqualityComparison!(T) comparison) {
if (comparison is null) {
comparison = (T a, T b) {
return equalityComparisonImpl(a, b);
@@ -625,7 +628,7 @@ class List(T) : IList!(T) {
/**
*/
- final int lastIndexOf(T item, EqualityComparison!(T) comparison = null) {
+ final size_t lastIndexOf(T item, EqualityComparison!(T) comparison = null) {
if (comparison is null) {
comparison = (T a, T b) {
return equalityComparisonImpl(a, b);
@@ -648,7 +651,7 @@ class List(T) : IList!(T) {
/**
*/
- final int binarySearch(T item, Comparison!(T) comparison = null) {
+ final sizediff_t binarySearch(T item, Comparison!(T) comparison = null) {
return .binarySearch(items_, 0, size_, item, comparison);
}
@@ -697,7 +700,7 @@ class List(T) : IList!(T) {
/**
*/
- final int findIndex(Predicate!(T) match) {
+ final size_t findIndex(Predicate!(T) match) {
for (auto i = 0; i < size_; i++) {
if (match(items_[i]))
return i;
@@ -707,7 +710,7 @@ class List(T) : IList!(T) {
/**
*/
- final int findLastIndex(Predicate!(T) match) {
+ final size_t findLastIndex(Predicate!(T) match) {
for (auto i = size_ - 1; i >= 0; i--) {
if (match(items_[i]))
return i;
@@ -741,7 +744,7 @@ class List(T) : IList!(T) {
/**
*/
- final List!(T) getRange(int index, int count) {
+ final List!(T) getRange(size_t index, size_t count) {
auto list = new List!(T)(count);
list.items_[0 .. count] = items_[index .. index + count];
list.size_ = count;
@@ -759,24 +762,24 @@ class List(T) : IList!(T) {
return list;
}
- final int count() {
+ final size_t count() {
return size_;
}
- final @property void capacity(int value) {
+ final @property void capacity(size_t value) {
items_.length = value;
}
- final @property int capacity() {
+ final @property size_t capacity() {
return items_.length;
}
- final void opIndexAssign(T value, int index) {
+ final void opIndexAssign(T value, size_t index) {
if (index >= size_)
throw new ArgumentOutOfRangeException("index");
items_[index] = value;
}
- final T opIndex(int index) {
+ final T opIndex(size_t index) {
if (index >= size_)
throw new ArgumentOutOfRangeException("index");
@@ -831,9 +834,9 @@ class List(T) : IList!(T) {
return contains(item);
}
- private void ensureCapacity(int min) {
+ private void ensureCapacity(size_t min) {
if (items_.length < min) {
- int n = (items_.length == 0) ? DEFAULT_CAPACITY : items_.length * 2;
+ size_t n = (items_.length == 0) ? DEFAULT_CAPACITY : items_.length * 2;
if (n < min)
n = min;
this.capacity = n;
@@ -852,7 +855,7 @@ class ReadOnlyList(T) : IList!(T) {
list_ = list;
}
- final int indexOf(T item) {
+ final size_t indexOf(T item) {
return list_.indexOf(item);
}
@@ -864,11 +867,11 @@ class ReadOnlyList(T) : IList!(T) {
list_.clear();
}
- final int count() {
+ final size_t count() {
return list_.count;
}
- final T opIndex(int index) {
+ final T opIndex(size_t index) {
return list_[index];
}
@@ -895,7 +898,7 @@ class ReadOnlyList(T) : IList!(T) {
throw new NotSupportedException;
}
- protected void insert(int index, T item) {
+ protected void insert(size_t index, T item) {
throw new NotSupportedException;
}
@@ -903,11 +906,11 @@ class ReadOnlyList(T) : IList!(T) {
throw new NotSupportedException;
}
- protected void removeAt(int index) {
+ protected void removeAt(size_t index) {
throw new NotSupportedException;
}
- protected void opIndexAssign(T item, int index) {
+ protected void opIndexAssign(T item, size_t index) {
throw new NotSupportedException;
}
@@ -933,19 +936,19 @@ class Collection(T) : IList!(T) {
insertItem(items_.count, item);
}
- final void insert(int index, T item) {
+ final void insert(size_t index, T item) {
insertItem(index, item);
}
final bool remove(T item) {
- int index = items_.indexOf(item);
+ size_t index = items_.indexOf(item);
if (index < 0)
return false;
removeItem(index);
return true;
}
- final void removeAt(int index) {
+ final void removeAt(size_t index) {
removeItem(index);
}
@@ -953,7 +956,7 @@ class Collection(T) : IList!(T) {
clearItems();
}
- final int indexOf(T item) {
+ final size_t indexOf(T item) {
return items_.indexOf(item);
}
@@ -961,14 +964,14 @@ class Collection(T) : IList!(T) {
return items_.contains(item);
}
- @property final int count() {
+ @property final size_t count() {
return items_.count;
}
- final void opIndexAssign(T value, int index) {
+ final void opIndexAssign(T value, size_t index) {
setItem(index, value);
}
- final T opIndex(int index) {
+ final T opIndex(size_t index) {
return items_[index];
}
@@ -991,11 +994,11 @@ class Collection(T) : IList!(T) {
}
}
- protected void insertItem(int index, T item) {
+ protected void insertItem(size_t index, T item) {
items_.insert(index, item);
}
- protected void removeItem(int index) {
+ protected void removeItem(size_t index) {
items_.removeAt(index);
}
@@ -1003,7 +1006,7 @@ class Collection(T) : IList!(T) {
items_.clear();
}
- protected void setItem(int index, T value) {
+ protected void setItem(size_t index, T value) {
items_[index] = value;
}
@@ -1130,7 +1133,7 @@ class Dictionary(K, V) : IDictionary!(K, V) {
/**
*/
- int count() {
+ size_t count() {
return this.outer.count;
}
@@ -1191,7 +1194,7 @@ class Dictionary(K, V) : IDictionary!(K, V) {
/**
*/
- int count() {
+ size_t count() {
return this.outer.count;
}
@@ -1247,7 +1250,7 @@ class Dictionary(K, V) : IDictionary!(K, V) {
private IEqualityComparer!(K) comparer_;
private int[] buckets_;
private Entry[] entries_;
- private int count_;
+ private size_t count_;
private int freeList_;
private int freeCount_;
@@ -1260,7 +1263,7 @@ class Dictionary(K, V) : IDictionary!(K, V) {
/**
*/
- this(int capacity = 0, IEqualityComparer!(K) comparer = null) {
+ this(size_t capacity = 0, IEqualityComparer!(K) comparer = null) {
if (capacity > 0)
initialize(capacity);
if (comparer is null)
@@ -1337,7 +1340,7 @@ class Dictionary(K, V) : IDictionary!(K, V) {
/**
*/
final bool tryGetValue(K key, out V value) {
- int index = findEntry(key);
+ size_t index = findEntry(key);
if (index >= 0) {
value = entries_[index].value;
return true;
@@ -1364,7 +1367,7 @@ class Dictionary(K, V) : IDictionary!(K, V) {
/**
*/
- final int count() {
+ final size_t count() {
return count_ - freeCount_;
}
@@ -1377,7 +1380,7 @@ class Dictionary(K, V) : IDictionary!(K, V) {
* ditto
*/
final V opIndex(K key) {
- int index = findEntry(key);
+ size_t index = findEntry(key);
if (index >= 0)
return entries_[index].value;
throw new KeyNotFoundException;
@@ -1415,7 +1418,7 @@ class Dictionary(K, V) : IDictionary!(K, V) {
}
}
- private void initialize(int capacity) {
+ private void initialize(size_t capacity) {
buckets_.length = entries_.length = getPrime(capacity);
buckets_[] = -1;
}
@@ -1431,7 +1434,7 @@ class Dictionary(K, V) : IDictionary!(K, V) {
}
}
- int index;
+ size_t index;
if (freeCount_ > 0) {
index = freeList_;
freeList_ = entries_[index].next;
@@ -1486,7 +1489,7 @@ class Dictionary(K, V) : IDictionary!(K, V) {
}
protected bool remove(KeyValuePair!(K, V) pair) {
- int index = findEntry(pair.key);
+ size_t index = findEntry(pair.key);
if (index >= 0 && EqualityComparer!(V).instance.equals(entries_[index].value, pair.value)) {
remove(pair.key);
return true;
@@ -1495,7 +1498,7 @@ class Dictionary(K, V) : IDictionary!(K, V) {
}
protected bool contains(KeyValuePair!(K, V) pair) {
- int index = findEntry(pair.key);
+ size_t index = findEntry(pair.key);
return index >= 0 && EqualityComparer!(V).instance.equals(entries_[index].value, pair.value);
}
@@ -1505,20 +1508,20 @@ class Dictionary(K, V) : IDictionary!(K, V) {
*/
class Queue(T) : IEnumerable!(T) {
- private const int DEFAULT_CAPACITY = 4;
+ private const ubyte DEFAULT_CAPACITY = 4;
private T[] array_;
private int head_;
private int tail_;
- private int size_;
+ private size_t size_;
version (UseRanges) {
- private int currentIndex_ = -2;
+ private size_t currentIndex_ = -2;
}
/**
*/
- this(int capacity = 0) {
+ this(size_t capacity = 0) {
array_.length = capacity;
}
@@ -1574,8 +1577,8 @@ class Queue(T) : IEnumerable!(T) {
/**
*/
final bool contains(T item) {
- int index = head_;
- int count = size_;
+ size_t index = head_;
+ size_t count = size_;
auto comparer = EqualityComparer!(T).instance;
while (count-- > 0) {
@@ -1606,7 +1609,7 @@ class Queue(T) : IEnumerable!(T) {
/**
* $(I Property.)
*/
- final int count() {
+ final size_t count() {
return size_;
}
@@ -1648,7 +1651,7 @@ class Queue(T) : IEnumerable!(T) {
}
}
- private void setCapacity(int capacity) {
+ private void setCapacity(size_t capacity) {
T[] newArray = new T[capacity];
if (size_ > 0) {
if (head_ < tail_) {
@@ -1669,36 +1672,36 @@ class Queue(T) : IEnumerable!(T) {
class SortedList(K, V) {
- private const int DEFAULT_CAPACITY = 4;
+ private const ubyte DEFAULT_CAPACITY = 4;
private IComparer!(K) comparer_;
private K[] keys_;
private V[] values_;
- private int size_;
+ private size_t size_;
this() {
comparer_ = Comparer!(K).instance;
}
- this(int capacity) {
+ this(size_t capacity) {
keys_.length = capacity;
values_.length = capacity;
comparer_ = Comparer!(K).instance;
}
final void add(K key, V value) {
- int index = binarySearch!(K)(keys_, 0, size_, key, &comparer_.compare);
+ sizediff_t index = binarySearch!(K)(keys_, 0, size_, key, &comparer_.compare);
insert(~index, key, value);
}
final bool remove(K key) {
- int index = indexOfKey(key);
+ sizediff_t index = indexOfKey(key);
if (index >= 0)
removeAt(index);
return index >= 0;
}
- final void removeAt(int index) {
+ final void removeAt(size_t index) {
size_--;
if (index < size_) {
.copy(keys_, index + 1, keys_, index, size_ - index);
@@ -1714,14 +1717,14 @@ class SortedList(K, V) {
size_ = 0;
}
- final int indexOfKey(K key) {
- int index = binarySearch!(K)(keys_, 0, size_, key, &comparer_.compare);
+ final sizediff_t indexOfKey(K key) {
+ sizediff_t index = binarySearch!(K)(keys_, 0, size_, key, &comparer_.compare);
if (index < 0)
return -1;
return index;
}
- final int indexOfValue(V value) {
+ final size_t indexOfValue(V value) {
foreach (i, v; values_) {
if (equalityComparisonImpl(v, value))
return i;
@@ -1737,7 +1740,7 @@ class SortedList(K, V) {
return indexOfValue(value) >= 0;
}
- final int count() {
+ final size_t count() {
return size_;
}
@@ -1760,13 +1763,13 @@ class SortedList(K, V) {
}
final V opIndex(K key) {
- int index = indexOfKey(key);
+ sizediff_t index = indexOfKey(key);
if (index >= 0)
return values_[index];
return V.init;
}
- private void insert(int index, K key, V value) {
+ private void insert(size_t index, K key, V value) {
if (size_ == keys_.length)
ensureCapacity(size_ + 1);
@@ -1780,7 +1783,7 @@ class SortedList(K, V) {
size_++;
}
- private void ensureCapacity(int min) {
+ private void ensureCapacity(size_t min) {
int n = (keys_.length == 0) ? DEFAULT_CAPACITY : keys_.length * 2;
if (n < min)
n = min;
diff --git a/source/juno/base/string.d b/source/juno/base/string.d
index 876cca3..3dbc750 100644
--- a/source/juno/base/string.d
+++ b/source/juno/base/string.d
@@ -42,7 +42,7 @@ alias const(wchar*) wstringz;
* if the string length is already known. Or the string
* is not null teminated.
*/
-const(T)[] toArray(T)(in T* s, size_t len = 0) if(isSomeChar!T
+const(T)[] toArray(T)(in T* s, sizediff_t len = 0) if(isSomeChar!T
&& !is(T == dchar)) {
if(len)
return s[0..len];
@@ -64,106 +64,6 @@ unittest {
assert(is(typeof(toArray(test2)) == const(wchar)[]));
}
-deprecated
-string toUtf8(in char* s, int index = 0, int count = -1) {
- if (s == null)
- return "";
- if (count == -1)
- count = strlen(s);
- if (count == 0)
- return "";
-
- return s[index .. count].idup;
-}
-
-deprecated
-string toUtf8(in wchar* s, int index = 0, int count = -1) {
- if (s == null)
- return "";
- if (count == -1)
- count = wcslen(s);
- if (count == 0)
- return "";
- return s[index .. count].toUTF8();
-}
-
-deprecated
-stringz toUtf8z(in char[] s, int index = 0, int count = -1) {
- if (s == null)
- return "";
- if (count == -1)
- count = s.length;
- if (count == 0)
- return "";
- return s[index .. count].toStringz();
-}
-
-deprecated
-stringz toUtf8z(string s, int index = 0, int count = -1) {
- if (s == null)
- return "";
- if (count == -1)
- count = s.length;
- if (count == 0)
- return "";
- return s[index .. count].toStringz();
-}
-
-deprecated
-string toUtf8(in wchar[] s, int index = 0, int count = -1) {
- if (s == null)
- return "";
- if (count == -1)
- count = s.length;
- if (count == 0)
- return "";
- return s[index .. count].toUTF8();
-}
-
-deprecated
-string toUtf8(string s, int index = 0, int count = -1) {
- if (s == null)
- return "";
- if (count == -1)
- count = s.length;
- if (count == 0)
- return "";
- return s[index .. count].toUTF8();
-}
-
-deprecated
-wstring toUtf16(string s, int index = 0, int count = -1) {
- if (s == null)
- return "";
- if (count == -1)
- count = s.length;
- if (count == 0)
- return "";
- return s[index .. count].toUTF16();
-}
-
-deprecated
-wstringz toUtf16z(in char[] s, int index = 0, int count = -1) {
- if (s == null)
- return "";
- if (count == -1)
- count = s.length;
- if (count == 0)
- return "";
- return s[index .. count].toUTF16z();
-}
-
-deprecated
-wstringz toUtf16z(string s, int index = 0, int count = -1) {
- if (s == null)
- return "";
- if (count == -1)
- count = s.length;
- if (count == 0)
- return "";
- return s[index .. count].toUTF16z();
-}
-
/**
* Compares two specified strings, ignoring or honouring their case.
* Params:
@@ -205,11 +105,15 @@ int compare(string stringA, string stringB) {
/**
* Compares two specified strings, ignoring or honouring their case.
+ *
+ * TODO: deprecated and provide a function which enables selection
+ * of the same compare options as the Win32 function.
+ *
* Params:
* stringA = The first string.
- * indexA = The position of the substring withing stringA.
+ * indexA = The position of the substring within stringA.
* stringB = The second string.
- * indexB = The position of the substring withing stringB.
+ * indexB = The position of the substring within stringB.
* ignoreCase = A value indicating a case- sensitive or insensitive comparison.
* 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).
*/
@@ -220,9 +124,9 @@ int compare(string stringA, int indexA, string stringB, int indexB, int length,
if (length != 0 && (stringA != stringB || indexA != indexB)) {
int lengthA = length, lengthB = length;
if (stringA.length - indexA < lengthA)
- lengthA = stringA.length - indexA;
+ lengthA = cast(int)stringA.length - indexA;
if (stringB.length - indexB < lengthB)
- lengthB = stringB.length - indexB;
+ lengthB = cast(int)stringB.length - indexB;
return culture.collator.compare(stringA, indexA, lengthA, stringB, indexB, lengthB, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
}
@@ -263,6 +167,9 @@ bool contains(string s, string value) {
/**
* Retrieves the index of the first occurrence of the specified character within the specified string.
+ *
+ * TODO: deprecated
+ *
* Params:
* s = The string to search within.
* value = The character to find.
@@ -270,21 +177,19 @@ bool contains(string s, string value) {
* count = The number of characters to examine.
* Returns: The index of value if that character is found, or -1 if it is not.
*/
-int indexOf(string s, char value, int index = 0, int count = -1) {
+sizediff_t indexOf(string s, char value, size_t index = 0, size_t count = -1) {
if (count == -1)
count = s.length - index;
- int end = index + count;
- for (int i = index; i < end; i++) {
- if (s[i] == value)
- return i;
- }
-
- return -1;
+ return std.string.indexOf(s[index..index+count], value) + index;
}
/**
* Retrieves the index of the first occurrence of the specified value in the specified string s.
+ *
+ * TODO: deprecated and provide a function which enables selection
+ * of the same compare options as the Win32 function.
+ *
* Params:
* s = The string to search within.
* value = The string to find.
@@ -303,19 +208,21 @@ int indexOf(string s, string value, int index, int count, bool ignoreCase = fals
* ditto
*/
int indexOf(string s, string value, int index, bool ignoreCase = false, Culture culture = null) {
- return indexOf(s, value, index, s.length - index, ignoreCase, culture);
+ return indexOf(s, value, index, to!int(s.length - index),
+ ignoreCase, culture);
}
/**
* ditto
*/
int indexOf(string s, string value, bool ignoreCase = false, Culture culture = null) {
- return indexOf(s, value, 0, s.length, ignoreCase, culture);
+ return indexOf(s, value, 0, to!int(s.length), ignoreCase, culture);
}
+deprecated
int indexOfAny(string s, in char[] anyOf, int index = 0, int count = -1) {
if (count == -1)
- count = s.length - index;
+ count = to!int(s.length - index);
int end = index + count;
for (int i = index; i < end; i++) {
@@ -335,6 +242,10 @@ int indexOfAny(string s, in char[] anyOf, int index = 0, int count = -1) {
/**
* Retrieves the index of the last occurrence of the specified character within the specified string.
+ *
+ * TODO: deprecated and provide a function which enables selection
+ * of the same compare options as the Win32 function.
+ *
* Params:
* s = The string to search within.
* value = The character to find.
@@ -342,21 +253,11 @@ int indexOfAny(string s, in char[] anyOf, int index = 0, int count = -1) {
* count = The number of characters to examine.
* Returns: The index of value if that character is found, or -1 if it is not.
*/
-int lastIndexOf(string s, char value, int index = 0, int count = -1) {
- if (s.length == 0)
- return -1;
- if (count == -1) {
- index = s.length - 1;
- count = s.length;
- }
-
- int end = index - count + 1;
- for (int i = index; i >= end; i--) {
- if (s[i] == value)
- return i;
- }
+sizediff_t lastIndexOf(string s, char value, sizediff_t index = 0, sizediff_t count = -1) {
+ if (count == -1)
+ count = index+1;
- return -1;
+ return std.string.lastIndexOf(s[index-count..index+1], value) + index;
}
/**
@@ -400,10 +301,12 @@ int lastIndexOf(string s, string value, int index, bool ignoreCase = false, Cult
* ditto
*/
int lastIndexOf(string s, string value, bool ignoreCase = false, Culture culture = null) {
- return lastIndexOf(s, value, s.length - 1, s.length, ignoreCase, culture);
+ return lastIndexOf(s, value, to!int(s.length - 1), to!int(s.length),
+ ignoreCase, culture);
}
-int lastIndexOfAny(string s, in char[] anyOf, int index = -1, int count = -1) {
+deprecated
+sizediff_t lastIndexOfAny(string s, in char[] anyOf, sizediff_t index = -1, sizediff_t count = -1) {
if (s.length == 0)
return -1;
if (count == -1) {
@@ -411,8 +314,8 @@ int lastIndexOfAny(string s, in char[] anyOf, int index = -1, int count = -1) {
count = s.length;
}
- int end = index - count + 1;
- for (int i = index; i >= end; i--) {
+ auto end = index - count + 1;
+ for (auto i = index; i >= end; i--) {
int k = -1;
for (int j = 0; j < anyOf.length; j++) {
if (s[i] == anyOf[j]) {
@@ -469,12 +372,12 @@ bool endsWith(string s, string value, bool ignoreCase = false, Culture culture =
* Returns: A new string with value inserted at index.
*/
//@@TODO@@ The currently disabled std.array.insert is pretty much the same as this
-string insert(string s, size_t index, string value) {
+string insert(string s, sizediff_t index, string value) {
if (value.length == 0 || s.length == 0) {
return s.idup;
}
- size_t newLength = s.length + value.length;
+ sizediff_t newLength = s.length + value.length;
char[] newString = new char[newLength];
newString[0 .. index] = s[0 .. index];
@@ -491,7 +394,7 @@ string insert(string s, size_t index, string value) {
* count = The number of characters to delete.
* Returns: A new string equivalent to s less count number of characters.
*/
-string remove(string s, int index, int count) {
+string remove(string s, size_t index, size_t count) {
char[] ret = new char[s.length - count];
memcpy(ret.ptr, s.ptr, index);
memcpy(ret.ptr + index, s.ptr + (index + count), s.length - (index + count));
@@ -574,6 +477,9 @@ string[] split(string s, char[] separator...) {
/**
* Returns a string array containing the substrings in s that are delimited by elements of the specified string array.
+ *
+ * TODO: deprecated
+ *
* Params:
* s = The string to _split.
* separator = An array of strings that delimit the substrings in s.
@@ -583,7 +489,7 @@ string[] split(string s, char[] separator...) {
*/
string[] split(string s, string[] separator, int count = int.max, bool removeEmptyEntries = false) {
- int createSeparatorList(ref int[] sepList, ref int[] lengthList) {
+ int createSeparatorList(ref int[] sepList, ref sizediff_t[] lengthList) {
int foundCount;
for (int i = 0; i < s.length && foundCount < sepList.length; i++) {
@@ -608,8 +514,8 @@ string[] split(string s, string[] separator, int count = int.max, bool removeEmp
if (count == 0 || (removeEmptyEntries && s.length == 0))
return new string[0];
- int[] sepList = new int[s.length];
- int[] lengthList = new int[s.length];
+ auto sepList = new int[s.length];
+ auto lengthList = new sizediff_t[s.length];
int replaceCount = createSeparatorList(sepList, lengthList);
if (replaceCount == 0 || count == 1)
@@ -625,9 +531,9 @@ string[] split(string s, string[] separator, bool removeEmptyEntries) {
return split(s, separator, int.max, removeEmptyEntries);
}
-private string[] splitImpl(string s, int[] sepList, int[] lengthList, int replaceCount, int count, bool removeEmptyEntries) {
+private string[] splitImpl(string s, int[] sepList, sizediff_t[] lengthList, int replaceCount, int count, bool removeEmptyEntries) {
string[] splitStrings;
- int arrayIndex, currentIndex;
+ sizediff_t arrayIndex, currentIndex;
if (removeEmptyEntries) {
int max = (replaceCount < count) ? replaceCount + 1 : count;
@@ -675,6 +581,9 @@ private string[] splitImpl(string s, int[] sepList, int[] lengthList, int replac
/**
* Concatenates separator between each element of value, returning a single concatenated string.
+ *
+ * TODO: deprecated
+ *
* Params:
* separator = A string.
* value = An array of strings.
@@ -682,15 +591,15 @@ private string[] splitImpl(string s, int[] sepList, int[] lengthList, int replac
* count = The number of elements of value to use.
* Returns: A string containing the strings in value joined by separator.
*/
-string join(string separator, string[] value, int index = 0, int count = -1) {
+string join(string separator, string[] value, sizediff_t index = 0, sizediff_t count = -1) {
if (count == -1)
count = value.length;
if (count == 0)
return "";
- int end = index + count - 1;
+ auto end = index + count - 1;
string ret = value[index];
- for (int i = index + 1; i <= end; i++) {
+ for (sizediff_t i = index + 1; i <= end; i++) {
ret ~= separator;
ret ~= value[i];
}
@@ -700,13 +609,16 @@ string join(string separator, string[] value, int index = 0, int count = -1) {
/**
* Replaces all instances of oldChar with newChar in s.
* Params:
+ *
+ * TODO: deprecated
+ *
* s = A string containing oldChar.
* oldChar = The character to be replaced.
* newChar = The character to replace all instances of oldChar.
* Returns: A string equivalent to s but with all instances of oldChar replaced with newChar.
*/
string replace(string s, char oldChar, char newChar) {
- int len = s.length;
+ sizediff_t len = s.length;
int firstFound = -1;
for (int i = 0; i < len; i++) {
if (oldChar == s[i]) {
@@ -720,7 +632,7 @@ string replace(string s, char oldChar, char newChar) {
char[] ret = s[0 .. firstFound].dup;
ret.length = len;
- for (int i = firstFound; i < len; i++)
+ for (sizediff_t i = firstFound; i < len; i++)
ret[i] = (s[i] == oldChar) ? newChar : s[i];
return assumeUnique(ret);
}
@@ -728,16 +640,19 @@ string replace(string s, char oldChar, char newChar) {
/**
* Replaces all instances of oldValue with newValue in s.
* Params:
+ *
+ * TODO: deprecated
+ *
* s = A string containing oldValue.
* oldValue = The string to be replaced.
* newValue = The string to replace all instances of oldValue.
* Returns: A string equivalent to s but with all instances of oldValue replaced with newValue.
*/
string replace(string s, string oldValue, string newValue) {
- int[] indices = new int[s.length + oldValue.length];
+ auto indices = new int[s.length + oldValue.length];
int index, count;
- while (((index = indexOf(s, oldValue, index, s.length)) > -1) &&
+ while (((index = indexOf(s, oldValue, index, to!int(s.length))) > -1) &&
(index <= s.length - oldValue.length)) {
indices[count++] = index;
index += oldValue.length;
@@ -827,6 +742,9 @@ string trimStart(string s, char[] trimChars ...) {
/**
* Removes all trailing occurrences of a set of characters specified in trimChars from s.
+ *
+ * TODO: deprecated
+ *
* Returns: The string that remains after all occurrences of the characters in trimChars are removed from the end of s.
*/
string trimEnd(string s, char[] trimChars ...) {
@@ -837,8 +755,8 @@ string trimEnd(string s, char[] trimChars ...) {
@safe nothrow pure
private string trimHelper(string s, in char[] trimChars, Trim trimType) {
- int right = s.length - 1;
- int left;
+ size_t right = s.length - 1;
+ size_t left;
// Trim head
if (trimType != Trim.Tail) {
@@ -869,7 +787,7 @@ private string trimHelper(string s, in char[] trimChars, Trim trimType) {
}
}
- int len = right - left + 1;
+ size_t len = right - left + 1;
if (len == s.length)
return s;
if (len == 0)
@@ -1133,9 +1051,9 @@ private struct ArgumentList {
}
pure
-private void append(ref string s, char value, int count) {
+private void append(ref string s, char value, size_t count) {
char[] d = s.dup;
- int n = d.length;
+ size_t n = d.length;
d.length = d.length + count;
d[n..$] = value;
@@ -1181,11 +1099,11 @@ string format(IFormatProvider provider, string format, ...) {
string result;
char[] chars = format.dup;
- int pos, len = format.length;
+ size_t pos, len = format.length;
char c;
while (true) {
- int p = pos, i = pos;
+ size_t p = pos, i = pos;
while (pos < len) {
c = chars[pos];
pos++;
@@ -1292,7 +1210,7 @@ string format(IFormatProvider provider, string format, ...) {
string s = arg.toString(fmt, provider);
- int padding = width - s.length;
+ size_t padding = width - s.length;
if (!leftAlign && padding > 0)
append(result, ' ', padding);
diff --git a/source/juno/base/text.d b/source/juno/base/text.d
index e12526b..bb69bb8 100644
--- a/source/juno/base/text.d
+++ b/source/juno/base/text.d
@@ -180,7 +180,7 @@ abstract final class CMultiLanguage {
extern(Windows)
alias DllImport!("mlang.dll", "ConvertINetString",
- int function(uint* lpdwMode, uint dwSrcEncoding, uint dwDstEncoding, in ubyte* lpSrcStr, uint* lpnSrcSize, ubyte* lpDstStr, uint* lpnDstSize))
+ int function(uint* lpdwMode, uint dwSrcEncoding, uint dwDstEncoding, in ubyte* lpSrcStr, int* lpnSrcSize, ubyte* lpDstStr, int* lpnDstSize))
ConvertINetString;
extern(Windows)
@@ -341,7 +341,7 @@ abstract class Encoding {
* Returns: A byte array containing the results of converting bytes from srcEncoding to destEncoding.
*/
static ubyte[] convert(Encoding sourceEncoding, Encoding destEncoding, in ubyte[] bytes) {
- return convert(sourceEncoding, destEncoding, bytes, 0, bytes.length);
+ return convert(sourceEncoding, destEncoding, bytes, 0, to!int(bytes.length));
}
/**
@@ -366,7 +366,7 @@ abstract class Encoding {
* ditto
*/
int encodeLength(in char[] chars) {
- return encodeLength(chars, 0, chars.length);
+ return encodeLength(chars, 0, to!int(chars.length));
}
/**
@@ -377,7 +377,7 @@ abstract class Encoding {
* ditto
*/
int decodeLength(in ubyte[] bytes) {
- return decodeLength(bytes, 0, bytes.length);
+ return decodeLength(bytes, 0, to!int(bytes.length));
}
abstract int encode(in char[] chars, int charIndex, int charCount, ubyte[] bytes, int byteIndex);
@@ -400,7 +400,7 @@ abstract class Encoding {
* ditto
*/
ubyte[] encode(in char[] chars) {
- return encode(chars, 0, chars.length);
+ return encode(chars, 0, to!int(chars.length));
}
/**
@@ -425,7 +425,7 @@ abstract class Encoding {
* ditto
*/
char[] decode(in ubyte[] bytes) {
- return decode(bytes, 0, bytes.length);
+ return decode(bytes, 0, to!int(bytes.length));
}
/**
@@ -629,8 +629,8 @@ private final class MLangEncoding : Encoding {
throw new ArgumentException("Could not encode.");
uint dwMode;
- uint bytesLength;
- uint charsLength = count;
+ int bytesLength;
+ int charsLength = count;
ConvertINetString(&dwMode, CP_UTF8, codePage_, cast(ubyte*)(chars.ptr + index), &charsLength, null, &bytesLength);
return bytesLength;
}
@@ -640,8 +640,8 @@ private final class MLangEncoding : Encoding {
throw new ArgumentException("Could not decode.");
uint dwMode;
- uint charsLength;
- uint bytesLength = count;
+ int charsLength;
+ int bytesLength = count;
ConvertINetString(&dwMode, codePage_, CP_UTF8, bytes.ptr + index, &bytesLength, null, &charsLength);
return charsLength;
}
@@ -651,8 +651,8 @@ private final class MLangEncoding : Encoding {
throw new ArgumentException("Could not encode.");
uint dwMode;
- uint charsLength = charCount;
- uint bytesLength = bytes.length - byteIndex;
+ int charsLength = charCount;
+ int bytesLength = to!int(bytes.length - byteIndex);
ConvertINetString(&dwMode, CP_UTF8, codePage_, cast(ubyte*)(chars.ptr + charIndex), &charsLength, bytes.ptr + byteIndex, &bytesLength);
return bytesLength;
}
@@ -662,8 +662,8 @@ private final class MLangEncoding : Encoding {
throw new ArgumentException("Could not decode.");
uint dwMode;
- uint bytesLength = byteCount;
- uint charsLength = chars.length - charIndex;
+ int bytesLength = byteCount;
+ int charsLength = to!int(chars.length - charIndex);
ConvertINetString(&dwMode, codePage_, CP_UTF8, bytes.ptr + byteIndex, &bytesLength, cast(ubyte*)chars.ptr + charIndex, &charsLength);
return charsLength;
}
diff --git a/source/juno/base/threading.d b/source/juno/base/threading.d
index f9de6c4..bec4461 100644
--- a/source/juno/base/threading.d
+++ b/source/juno/base/threading.d
@@ -13,6 +13,8 @@ import juno.base.core,
juno.base.native,
juno.base.time;
+import std.utf;
+
/**
* $(RED Deprecated.
* Please use core.thread.sleep instead.)
@@ -140,11 +142,11 @@ final class ManualResetEvent : EventWaitHandle {
final class Mutex : WaitHandle {
this(bool initiallyOwned = false, string name = null) {
- Handle hMutex = CreateMutex(null, (initiallyOwned ? 1 : 0), name.toUtf16z());
+ Handle hMutex = CreateMutex(null, (initiallyOwned ? 1 : 0), name.toUTF16z());
uint error = GetLastError();
if (error == ERROR_ACCESS_DENIED && (hMutex == Handle.init || hMutex == INVALID_HANDLE_VALUE))
- hMutex = OpenMutex(MUTEX_MODIFY_STATE | SYNCHRONIZE, 0, name.toUtf16z());
+ hMutex = OpenMutex(MUTEX_MODIFY_STATE | SYNCHRONIZE, 0, name.toUTF16z());
handle_ = hMutex;
}
@@ -158,7 +160,7 @@ final class Mutex : WaitHandle {
final class Semaphore : WaitHandle {
this(int initialCount, int maximumCount, string name = null) {
- handle_ = CreateSemaphore(null, initialCount, maximumCount, name.toUtf16z());
+ handle_ = CreateSemaphore(null, initialCount, maximumCount, name.toUTF16z());
}
int release(int releaseCount = 1) {
diff --git a/source/juno/com/core.d b/source/juno/com/core.d
index 3f87b95..e83a210 100644
--- a/source/juno/com/core.d
+++ b/source/juno/com/core.d
@@ -19,7 +19,7 @@ import juno.base.core,
import std.algorithm;
import std.array;
import std.utf : toUTF8, toUTF16z;
-import core.exception, core.memory;
+import core.atomic, core.exception, core.memory;
import core.stdc.wchar_ : wcslen;
import std.system;
@@ -3147,17 +3147,17 @@ template QueryInterfaceImpl(TList...) {
// Implements AddRef & Release for IUnknown subclasses.
template ReferenceCountImpl() {
- private int refCount_ = 1;
- private bool finalized_;
+ private shared int refCount_ = 1;
+ private shared bool finalized_;
extern(Windows):
uint AddRef() {
- return InterlockedIncrement(refCount_);
+ return atomicOp!"+="(refCount_, 1);
}
uint Release() {
- if (InterlockedDecrement(refCount_) == 0) {
+ if (atomicOp!"-="(refCount_, 1) == 0) {
if (!finalized_) {
finalized_ = true;
runFinalizer(this);
diff --git a/source/juno/io/core.d b/source/juno/io/core.d
index b020394..233c8db 100644
--- a/source/juno/io/core.d
+++ b/source/juno/io/core.d
@@ -125,7 +125,7 @@ abstract class Reader {
* count = The maximum number of character to _read.
* Returns: The number of characters that have been _read.
*/
- int read(char[] buffer, int index, int count) {
+ size_t read(char[] buffer, size_t index, size_t count) {
int n = 0;
do {
char ch = read();
@@ -143,7 +143,7 @@ abstract class Reader {
string readToEnd() {
string s;
char[] buffer = new char[4096];
- int len;
+ size_t len;
while ((len = read(buffer, 0, buffer.length)) != 0) {
s ~= buffer[0 .. len];
}
@@ -357,13 +357,13 @@ private class ConsoleStream : Stream {
protected override size_t readBlock(void* buffer, size_t size) {
uint bytesRead = 0;
- ReadFile(handle_, buffer, size, bytesRead, null);
+ ReadFile(handle_, buffer, to!uint(size), bytesRead, null);
return bytesRead;
}
protected override size_t writeBlock(in void* buffer, size_t size) {
uint bytesWritten = 0;
- WriteFile(handle_, buffer, size, bytesWritten, null);
+ WriteFile(handle_, buffer, to!uint(size), bytesWritten, null);
return bytesWritten;
}
diff --git a/source/juno/io/filesystem.d b/source/juno/io/filesystem.d
index e4bd0c5..49e9351 100644
--- a/source/juno/io/filesystem.d
+++ b/source/juno/io/filesystem.d
@@ -58,16 +58,16 @@ deprecated
void createDirectory(string path) {
string fullPath = getFullPath(path);
- int len = fullPath.length;
+ auto len = fullPath.length;
if (len >= 2 && std.path.isDirSeparator(fullPath[len - 1]))
len--;
string[] list;
bool pathExists;
- int rootLen = getRootLength(fullPath);
+ size_t rootLen = getRootLength(fullPath);
if (len > rootLen) {
- for (int i = len - 1; i >= rootLen; i--) {
+ for (auto i = len - 1; i >= rootLen; i--) {
string dir = fullPath[0 .. i + 1];
if (!directoryExists(dir))
@@ -1009,124 +1009,3 @@ interface Iterator(T) {
int opApply(int delegate(ref T) action);
}
-
-deprecated
-class FileSystemIterator : Iterator!(string) {
-
- private string path_;
- private string searchPattern_;
- private bool includeFiles_;
- private bool includeDirs_;
-
- this(string path, string searchPattern, bool includeFiles, bool includeDirs) {
- path_ = path;
- searchPattern_ = searchPattern;
- includeFiles_ = includeFiles;
- includeDirs_ = includeDirs;
- }
-
- int opApply(int delegate(ref string) action) {
-
- bool isDir(WIN32_FIND_DATA findData) {
- return ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
- }
-
- bool isFile(WIN32_FIND_DATA findData) {
- return ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0);
- }
-
- string getSearchResult(string path, WIN32_FIND_DATA findData) {
- return combine(path, toUtf8(findData.cFileName[0 .. wcslen(findData.cFileName.ptr)]));
- }
-
- int ret = 0;
-
- string fullPath = getFullPath(path_);
-
- string searchPattern = searchPattern_.stripRight();
- if (searchPattern == ".")
- searchPattern = "*";
- if (searchPattern.length == 0)
- return ret;
-
- string searchPath = combine(fullPath, searchPattern);
- if (std.path.isDirSeparator(searchPath[$ - 1])
- || searchPath[$ - 1] == ':')
- searchPath ~= '*';
-
- string userPath = path_;
- string tempPath = getDirectoryName(searchPattern);
- if (tempPath.length != 0)
- userPath = combine(userPath, tempPath);
-
- WIN32_FIND_DATA findData;
- uint lastError;
-
- Handle hFind = FindFirstFile(searchPath.toUTF16z(), findData);
- if (hFind != INVALID_HANDLE_VALUE) {
- scope(exit) FindClose(hFind);
-
- do {
- if (wcscmp(findData.cFileName.ptr, ".") == 0
- || wcscmp(findData.cFileName.ptr, "..") == 0)
- continue;
-
- string result = getSearchResult(userPath, findData);
-
- if ((includeDirs_ && isDir(findData))
- || (includeFiles_ && isFile(findData))) {
- if ((ret = action(result)) != 0)
- break;
- }
- } while (FindNextFile(hFind, findData));
-
- lastError = GetLastError();
- }
-
- if (lastError != ERROR_SUCCESS
- && lastError != ERROR_NO_MORE_FILES
- && lastError != ERROR_FILE_NOT_FOUND)
- ioError(lastError, userPath);
-
- return ret;
- }
-
-}
-
-/**
- * $(RED Deprecated.
- * Please use std.file.dirEntries instead.)
- *
- * Returns an iterable collection of directory names in the specified _path.
- */
-deprecated
-Iterator!(string) enumDirectories(string path, string searchPattern = "*") {
- return enumFileSystemNames(path, searchPattern, false, true);
-}
-
-/**
- * $(RED Deprecated.
- * Please use std.file.dirEntries instead.)
- *
- * Returns an iterable collection of file names in the specified _path.
- */
-deprecated
-Iterator!(string) enumFiles(string path, string searchPattern = "*") {
- return enumFileSystemNames(path, searchPattern, true, false);
-}
-
-/**
- * $(RED Deprecated.
- * Please use std.file.dirEntries instead.)
-
- * Returns an iterable collection of file-system entries in the specified _path.
- */
-deprecated
-Iterator!(string) enumFileSystemEntries(string path, string searchPattern = "*") {
- return enumFileSystemNames(path, searchPattern, true, true);
-}
-
-deprecated
-private Iterator!(string) enumFileSystemNames(string path, string searchPattern, bool includeFiles, bool includeDirs) {
- return new FileSystemIterator(path, searchPattern, includeFiles, includeDirs);
-}
diff --git a/source/juno/io/path.d b/source/juno/io/path.d
index d0da663..91189bf 100644
--- a/source/juno/io/path.d
+++ b/source/juno/io/path.d
@@ -49,8 +49,8 @@ string tempPath() {
}
deprecated
-package int getRootLength(string path) {
- int i, len = path.length;
+package size_t getRootLength(string path) {
+ size_t i, len = path.length;
if (len >= 1 && std.path.isDirSeparator(path[0])) {
i = 1;
if (len >= 2 && (std.path.isDirSeparator(path[1]))) {
@@ -112,8 +112,8 @@ string combine(string path1, string path2) {
deprecated
string getDirectoryName(string path) {
- int root = getRootLength(path);
- int i = path.length;
+ size_t root = getRootLength(path);
+ size_t i = path.length;
if (i > root) {
i = path.length;
if (i == root)
@@ -134,7 +134,7 @@ string getDirectoryName(string path) {
*/
deprecated
string getFileName(string path) {
- for (int i = path.length; --i >= 0;) {
+ for (size_t i = path.length; --i >= 0;) {
char ch = path[i];
if (std.path.isDirSeparator(ch) || ch == ':')
return path[i + 1 .. $];
@@ -150,7 +150,7 @@ string getFileName(string path) {
*/
deprecated
string getFullPath(string path) {
- auto p = path.toUtf16z();
+ auto p = path.toUTF16z();
auto buffer = new wchar[MaxPath + 1];
auto bufferLength = GetFullPathName(p, MaxPath + 1, buffer.ptr, null);
@@ -171,10 +171,10 @@ string getFullPath(string path) {
bufferLength = GetLongPathName(buffer.ptr, tempBuffer.ptr, MaxPath);
if (bufferLength > 0)
- return tempBuffer[0 .. bufferLength].toUtf8();
+ return to!string(tempBuffer[0 .. bufferLength]);
}
- return buffer[0 .. bufferLength].toUtf8();
+ return to!string(buffer[0 .. bufferLength]);
}
/// Specifies constants used to retrieve directory paths to system special folders.
diff --git a/source/juno/io/zip.d b/source/juno/io/zip.d
index bd557c7..739c5e2 100644
--- a/source/juno/io/zip.d
+++ b/source/juno/io/zip.d
@@ -6,6 +6,9 @@ import juno.base.core,
juno.locale.time,
std.stream,
etc.c.zlib;
+
+import std.conv;
+
//debug import std.stdio : writeln, writefln;
private enum : uint {
@@ -93,7 +96,7 @@ private void copyStream(Stream input, Stream output) {
input.position = 0;
while (true) {
- uint n = input.readBlock(buffer.ptr, buffer.length);
+ size_t n = input.readBlock(buffer.ptr, buffer.length);
if (n == 0)
return;
output.writeBlock(buffer.ptr, n);
@@ -146,13 +149,13 @@ private class InflateStream : CopyFilterStream {
override size_t readBlock(void* buffer, size_t size) {
if (zs_.avail_in == 0) {
- if ((zs_.avail_in = source().read(buffer_)) <= 0)
+ if ((zs_.avail_in = to!uint(source().read(buffer_))) <= 0)
return 0;
zs_.next_in = buffer_.ptr;
}
zs_.next_out = cast(ubyte*)buffer;
- zs_.avail_out = size;
+ zs_.avail_out = to!uint(size);
int result = inflate(&zs_, Z_NO_FLUSH);
if (result != Z_STREAM_END && result != Z_OK)
@@ -200,18 +203,18 @@ private class DeflateStream : CopyFilterStream {
}
override size_t writeBlock(in void* buffer, size_t size) {
- zs_.avail_in = size;
+ zs_.avail_in = to!uint(size);
zs_.next_in = cast(ubyte*)buffer;
do {
- zs_.avail_out = buffer_.length;
+ zs_.avail_out = to!uint(buffer_.length);
zs_.next_out = buffer_.ptr;
int result = deflate(&zs_, Z_NO_FLUSH);
if (result == Z_STREAM_ERROR)
throw new ZipException(result);
- uint n = buffer_.length - zs_.avail_out;
+ size_t n = buffer_.length - zs_.avail_out;
ubyte[] b = buffer_[0 .. n];
do {
size_t written = source().write(b);
@@ -235,7 +238,7 @@ private class DeflateStream : CopyFilterStream {
bool done;
do {
- zs_.avail_out = buffer_.length;
+ zs_.avail_out = to!uint(buffer_.length);
zs_.next_out = cast(ubyte*)buffer_.ptr;
int result = deflate(&zs_, Z_FINISH);
@@ -249,7 +252,7 @@ private class DeflateStream : CopyFilterStream {
throw new ZipException(result);
}
- uint n = buffer_.length - zs_.avail_out;
+ size_t n = buffer_.length - zs_.avail_out;
ubyte[] b = buffer_[0 .. n];
do {
size_t written = source().write(b);
@@ -280,7 +283,7 @@ private class CrcStream : CopyFilterStream {
override size_t readBlock(void* buffer, size_t size) {
size_t n = source().readBlock(buffer, size);
if (n != 0)
- value = etc.c.zlib.crc32(value, cast(ubyte*)buffer, n);
+ value = etc.c.zlib.crc32(value, cast(ubyte*)buffer, to!uint(n));
return n;
}
@@ -480,7 +483,7 @@ final class ZipReader {
input_.position = end;
size_t n = input_.read(buffer);
- for (int i = n - 22; i >= 0; i--) {
+ for (size_t i = n - 22; i >= 0; i--) {
if (i < end)
throw new ZipException("File contains corrupt data.");
diff --git a/source/juno/locale/core.d b/source/juno/locale/core.d
index 453b04e..600beb4 100644
--- a/source/juno/locale/core.d
+++ b/source/juno/locale/core.d
@@ -43,6 +43,7 @@ static ~this() {
regionNameToLcidMap = null;
}
+// TODO: deprecated
package wchar* toUTF16zNls(string s, int offset, int len, out int translated) {
translated = 0;
if (s.length == 0)
@@ -50,7 +51,7 @@ package wchar* toUTF16zNls(string s, int offset, int len, out int translated) {
// Function requires inclusion of null
auto nulled = s[offset..len] ~ "\0";
- len = nulled.length;
+ len = cast(int)nulled.length;
auto pChars = nulled.ptr;
int cch = MultiByteToWideChar(CP_UTF8, 0, pChars, len, null, 0);
@@ -80,6 +81,7 @@ unittest {
assert(arr1 == arr2);
}
+// TODO: deprecated
package string toUTF8Nls(in wchar* pChars, int cch, out int translated) {
translated = 0;
@@ -663,7 +665,7 @@ class Culture : IFormatProvider {
if (!isNeutral)
s ~= " (" ~ getLocaleInfo(cultureId_, LOCALE_SNATIVECTRYNAME) ~ ")";
else {
- int i = s.lastIndexOf("(");
+ auto i = s.lastIndexOf("(");
if (i != -1 && s.lastIndexOf(")") != -1)
s.length = i - 1;
}
@@ -691,7 +693,7 @@ class Culture : IFormatProvider {
if (!isNeutral)
s ~= " (" ~ getLocaleInfo(cultureId_, LOCALE_SENGCOUNTRY) ~ ")";
else {
- int i = s.lastIndexOf("(");
+ auto i = s.lastIndexOf("(");
if (i != -1 && s.lastIndexOf(")") != -1)
s.length = i - 1;
}
@@ -718,7 +720,7 @@ class Culture : IFormatProvider {
string s = getLocaleInfo(cultureId_, LOCALE_SLANGUAGE);
if (s != null && isNeutral && cultureId_ != LOCALE_INVARIANT) {
// Remove country from neutral cultures.
- int i = s.lastIndexOf("(");
+ auto i = s.lastIndexOf("(");
if (i != -1 && s.lastIndexOf(")") != -1)
s.length = i - 1;
}
@@ -2058,7 +2060,7 @@ class DateTimeFormat : IFormatProvider {
private static string getShortTime(uint culture) {
// There is no LOCALE_SSHORTTIME, so we simulate one based on the long time pattern.
string s = getLocaleInfo(culture, LOCALE_STIMEFORMAT);
- int i = s.lastIndexOf(getLocaleInfo(culture, LOCALE_STIME));
+ auto i = s.lastIndexOf(getLocaleInfo(culture, LOCALE_STIME));
if (i != -1)
s.length = i;
return s;
@@ -2107,8 +2109,8 @@ class DateTimeFormat : IFormatProvider {
}
foreach (ref s; formats) {
- int i = s.lastIndexOf(getLocaleInfo(culture, LOCALE_STIME));
- int j = -1;
+ auto i = s.lastIndexOf(getLocaleInfo(culture, LOCALE_STIME));
+ typeof(i) j = -1;
if (i != -1)
j = s.lastIndexOf(' ');
if (i != -1 && j != -1) {
@@ -2295,7 +2297,7 @@ class Collator {
/// ditto
int compare(string string1, int offset1, string string2, int offset2, CompareOptions options = CompareOptions.None) {
- return compare(string1, offset1, string1.length - offset1, string2, offset2, string2.length - offset2, options);
+ return compare(string1, offset1, to!int(string1.length - offset1), string2, offset2, to!int(string2.length - offset2), options);
}
/// ditto
@@ -2311,7 +2313,7 @@ class Collator {
//if ((options & CompareOptions.Ordinal) != 0 || (options & CompareOptions.OrdinalIgnoreCase) != 0)
// return compareStringOrdinal(string1, 0, string1.length, string2, 0, string2.length, (options & CompareOptions.OrdinalIgnoreCase) != 0);
- return compareString(sortingId_, string1, 0, string1.length, string2, 0, string2.length, getCompareFlags(options));
+ return compareString(sortingId_, string1, 0, to!int(string1.length), string2, 0, to!int(string2.length), getCompareFlags(options));
}
/**
@@ -2319,7 +2321,7 @@ class Collator {
int indexOf(string source, string value, int index, int count, CompareOptions options = CompareOptions.None) {
uint flags = getCompareFlags(options);
- int n = findString(sortingId_, flags | FIND_FROMSTART, source, index, count, value, value.length);
+ int n = findString(sortingId_, flags | FIND_FROMSTART, source, index, count, value, to!int(value.length));
if (n > -1)
return n + index;
if (n == -1)
@@ -2334,12 +2336,12 @@ class Collator {
/// ditto
int indexOf(string source, string value, int index, CompareOptions options = CompareOptions.None) {
- return indexOf(source, value, index, source.length - index, options);
+ return indexOf(source, value, index, to!int(source.length - index), options);
}
/// ditto
int indexOf(string source, string value, CompareOptions options = CompareOptions.None) {
- return indexOf(source, value, 0, source.length, options);
+ return indexOf(source, value, 0, to!int(source.length), options);
}
/**
@@ -2361,7 +2363,7 @@ class Collator {
uint flags = getCompareFlags(options);
- int n = findString(sortingId_, flags | FIND_FROMEND, source, (index - count) + 1, count, value, value.length);
+ int n = findString(sortingId_, flags | FIND_FROMEND, source, (index - count) + 1, count, value, to!int(value.length));
if (n > -1)
return n + (index - count) + 1;
if (n == -1)
@@ -2381,7 +2383,7 @@ class Collator {
/// ditto
int lastIndexOf(string source, string value, CompareOptions options = CompareOptions.None) {
- return lastIndexOf(source, value, source.length - 1, source.length, options);
+ return lastIndexOf(source, value, to!int(source.length - 1), to!int(source.length), options);
}
/**
@@ -2389,7 +2391,7 @@ class Collator {
bool isPrefix(string source, string prefix, CompareOptions options = CompareOptions.None) {
if (prefix.length == 0)
return true;
- return isPrefix(source, 0, source.length, prefix, getCompareFlags(options));
+ return isPrefix(source, 0, to!int(source.length), prefix, getCompareFlags(options));
}
/**
@@ -2397,7 +2399,7 @@ class Collator {
bool isSuffix(string source, string suffix, CompareOptions options = CompareOptions.None) {
if (suffix.length == 0)
return true;
- return isSuffix(source, source.length - 1, source.length, suffix, getCompareFlags(options));
+ return isSuffix(source, to!int(source.length - 1), to!int(source.length), suffix, getCompareFlags(options));
}
/**
@@ -2472,12 +2474,12 @@ class Collator {
private bool isPrefix(string source, int start, int length, string prefix, uint flags) {
// Call FindNLSString if the API is present on the system, otherwise call CompareString.
- int i = findString(sortingId_, 0, source, start, length, prefix, prefix.length);
+ int i = findString(sortingId_, 0, source, start, length, prefix, to!int(prefix.length));
if (i >= -1)
return (i != -1);
for (i = 1; i <= length; i++) {
- if (compareString(sortingId_, prefix, 0, prefix.length, source, start, i, flags) == 0)
+ if (compareString(sortingId_, prefix, 0, to!int(prefix.length), source, start, i, flags) == 0)
return true;
}
return false;
@@ -2485,12 +2487,12 @@ class Collator {
private bool isSuffix(string source, int end, int length, string suffix, uint flags) {
// Call FindNLSString if the API is present on the system, otherwise call CompareString.
- int i = findString(sortingId_, flags | FIND_ENDSWITH, source, 0, length, suffix, suffix.length);
+ int i = findString(sortingId_, flags | FIND_ENDSWITH, source, 0, length, suffix, to!int(suffix.length));
if (i >= -1)
return (i != -1);
for (i = 0; i < length; i++) {
- if (compareString(sortingId_, suffix, 0, suffix.length, source, end - i, i + 1, flags))
+ if (compareString(sortingId_, suffix, 0, to!int(suffix.length), source, end - i, i + 1, flags))
return true;
}
return false;
@@ -2504,9 +2506,9 @@ class Collator {
return ch;
}
- private static string changeCaseString(uint lcid, string string, bool upperCase) {
+ private static string changeCaseString(uint lcid, string str, bool upperCase) {
int cch, cb;
- wchar* pChars = toUTF16zNls(string, 0, string.length, cch);
+ wchar* pChars = toUTF16zNls(str, 0, to!int(str.length), cch);
LCMapString(lcid, (upperCase ? LCMAP_UPPERCASE : LCMAP_LOWERCASE) | LCMAP_LINGUISTIC_CASING, pChars, cch, pChars, cch);
return toUTF8Nls(pChars, cch, cb);
}
diff --git a/source/juno/locale/numeric.d b/source/juno/locale/numeric.d
index 44acbfa..3065c7a 100644
--- a/source/juno/locale/numeric.d
+++ b/source/juno/locale/numeric.d
@@ -41,7 +41,9 @@ package struct Number {
value /= 10;
}
- int end = n.scale = -(i - buffer.length);
+ // buffer is static length 20
+ static assert(buffer.length == 20);
+ auto end = n.scale = -(i - cast(int)buffer.length);
n.digits[0 .. end] = buffer[i .. i + end];
n.digits[end] = '\0';
@@ -101,8 +103,10 @@ package struct Number {
buffer[--i] = cast(char)(x % 10 + '0');
x /= 10;
}
- int end = -(i - buffer.length);
- n.scale = -(i - buffer.length) - d.scale;
+ // buffer is static length 30
+ static assert(buffer.length == 30);
+ auto end = -(i - cast(int)buffer.length);
+ n.scale = -(i - cast(int)buffer.length) - d.scale;
n.digits[0 .. end] = buffer[i .. i + end];
n.digits[end] = '\0';
@@ -244,8 +248,8 @@ package struct Number {
}
char* p = digits.ptr;
- int count = strlen(p);
- int left = count;
+ int count = to!int(strlen(p));
+ auto left = count;
while (*p == '0') {
left--;
@@ -258,11 +262,11 @@ package struct Number {
}
// Get digits, 9 at a time.
- int n = (left > 9) ? 9 : left;
+ byte n = cast(byte)((left > 9) ? 9 : left);
left -= n;
ulong bits = getDigits(p, n);
if (left > 0) {
- n = (left > 9) ? 9 : left;
+ n = cast(byte)((left > 9) ? 9 : left);
left -= n;
bits = mult64(cast(uint)bits, cast(uint)(pow10[n - 1] >>> (64 - pow10Exp[n - 1])));
bits += getDigits(p + 9, n);
@@ -1167,7 +1171,7 @@ private void formatFixed(ref Number number, ref string dst, int length, int[] gr
size = (count == 0) ? 0 : groupSizes[0];
// Insert separator at positions specified by groupSizes.
- int end = strlen(p);
+ int end = to!int(strlen(p));
int start = (pos < end) ? pos : end;
auto separator = array(retro(groupSeparator));
dchar[] temp;
diff --git a/source/juno/locale/text.d b/source/juno/locale/text.d
index 943dbcb..c3b789b 100644
--- a/source/juno/locale/text.d
+++ b/source/juno/locale/text.d
@@ -11,6 +11,7 @@ private import juno.base.native,
private import juno.locale.core : Culture, toUTF16zNls, toUTF8Nls;
private import std.c.string : memcmp, memicmp;
+import std.conv;
class Collator {
@@ -52,7 +53,7 @@ class Collator {
}
int compare(string string1, int offset1, string string2, int offset2, CompareOptions options = CompareOptions.None) {
- return compare(string1, offset1, string1.length - offset1, string2, offset2, string2.length - offset2, options);
+ return compare(string1, offset1, to!int(string1.length - offset1), string2, offset2, to!int(string2.length - offset2), options);
}
int compare(string string1, string string2, CompareOptions options = CompareOptions.None) {
@@ -67,13 +68,13 @@ class Collator {
//if ((options & CompareOptions.Ordinal) != 0 || (options & CompareOptions.OrdinalIgnoreCase) != 0)
// return compareStringOrdinal(string1, 0, string1.length, string2, 0, string2.length, (options & CompareOptions.OrdinalIgnoreCase) != 0);
- return compareString(sortingId_, string1, 0, string1.length, string2, 0, string2.length, getCompareFlags(options));
+ return compareString(sortingId_, string1, 0, to!int(string1.length), string2, 0, to!int(string2.length), getCompareFlags(options));
}
int indexOf(string source, string value, int index, int count, CompareOptions options = CompareOptions.None) {
uint flags = getCompareFlags(options);
- int n = findString(sortingId_, flags | FIND_FROMSTART, source, index, count, value, value.length);
+ int n = findString(sortingId_, flags | FIND_FROMSTART, source, index, count, value, to!int(value.length));
if (n > -1)
return n + index;
if (n == -1)
@@ -87,11 +88,11 @@ class Collator {
}
int indexOf(string source, string value, int index, CompareOptions options = CompareOptions.None) {
- return indexOf(source, value, index, source.length - index, options);
+ return indexOf(source, value, index, to!int(source.length - index), options);
}
int indexOf(string source, string value, CompareOptions options = CompareOptions.None) {
- return indexOf(source, value, 0, source.length, options);
+ return indexOf(source, value, 0, to!int(source.length), options);
}
int lastIndexOf(string source, string value, int index, int count, CompareOptions options = CompareOptions.None) {
@@ -111,7 +112,7 @@ class Collator {
uint flags = getCompareFlags(options);
- int n = findString(sortingId_, flags | FIND_FROMEND, source, (index - count) + 1, count, value, value.length);
+ int n = findString(sortingId_, flags | FIND_FROMEND, source, (index - count) + 1, count, value, to!int(value.length));
if (n > -1)
return n + (index - count) + 1;
if (n == -1)
@@ -129,19 +130,19 @@ class Collator {
}
int lastIndexOf(string source, string value, CompareOptions options = CompareOptions.None) {
- return lastIndexOf(source, value, source.length - 1, source.length, options);
+ return lastIndexOf(source, value, to!int(source.length - 1), to!int(source.length), options);
}
bool isPrefix(string source, string prefix, CompareOptions options = CompareOptions.None) {
if (prefix.length == 0)
return true;
- return isPrefix(source, 0, source.length, prefix, getCompareFlags(options));
+ return isPrefix(source, 0, to!int(source.length), prefix, getCompareFlags(options));
}
bool isSuffix(string source, string suffix, CompareOptions options = CompareOptions.None) {
if (suffix.length == 0)
return true;
- return isSuffix(source, source.length - 1, source.length, suffix, getCompareFlags(options));
+ return isSuffix(source, to!int(source.length - 1), to!int(source.length), suffix, getCompareFlags(options));
}
string toLower(string str) {
@@ -206,14 +207,14 @@ class Collator {
private bool isPrefix(string source, int start, int length, string prefix, uint flags) {
// Call FindNLSString if the API is present on the system, otherwise call CompareString.
- int i = findString(sortingId_, flags | FIND_STARTSWITH, source, start, length, prefix, prefix.length);
+ int i = findString(sortingId_, flags | FIND_STARTSWITH, source, start, length, prefix, to!int(prefix.length));
if (i == -1)
return false;
else if (i > -1)
return true;
for (i = 1; i <= length; i++) {
- if (compareString(sortingId_, prefix, 0, prefix.length, source, start, i, flags) == 0)
+ if (compareString(sortingId_, prefix, 0, to!int(prefix.length), source, start, i, flags) == 0)
return true;
}
return false;
@@ -221,22 +222,22 @@ class Collator {
private bool isSuffix(string source, int end, int length, string suffix, uint flags) {
// Call FindNLSString if the API is present on the system, otherwise call CompareString.
- int i = findString(sortingId_, flags | FIND_ENDSWITH, source, 0, length, suffix, suffix.length);
+ int i = findString(sortingId_, flags | FIND_ENDSWITH, source, 0, length, suffix, to!int(suffix.length));
if (i == -1)
return false;
else if (i > -1)
return true;
for (i = 0; i < length; i++) {
- if (compareString(sortingId_, suffix, 0, suffix.length, source, end - i, i + 1, flags))
+ if (compareString(sortingId_, suffix, 0, to!int(suffix.length), source, end - i, i + 1, flags))
return true;
}
return false;
}
- private static string changeCaseString(uint lcid, string string, bool upperCase) {
+ private static string changeCaseString(uint lcid, string str, bool upperCase) {
int cch, cb;
- wchar* pChars = toUTF16zNls(string, 0, string.length, cch);
+ wchar* pChars = toUTF16zNls(str, 0, to!int(str.length), cch);
LCMapString(lcid, (upperCase ? LCMAP_UPPERCASE : LCMAP_LOWERCASE) | LCMAP_LINGUISTIC_CASING, pChars, cch, pChars, cch);
return toUTF8Nls(pChars, cch, cb);
}
@@ -263,4 +264,4 @@ class Collator {
return result;
}
-}
\ No newline at end of file
+}
diff --git a/source/juno/locale/time.d b/source/juno/locale/time.d
index df14487..8768a2d 100644
--- a/source/juno/locale/time.d
+++ b/source/juno/locale/time.d
@@ -1,6 +1,8 @@
/**
* Copyright: (c) 2009 John Chapman
*
+ * TODO: deprecated should use std.datetime
+ *
* License: See $(LINK2 ..\..\licence.txt, licence.txt) for use and distribution terms.
*/
module juno.locale.time;
@@ -16,6 +18,8 @@ import std.algorithm : reverse;
debug import std.stdio : writefln;
+import std.conv;
+
// This module or classes contained within must not have any
// static ctors/dtors, otherwise there will be circular references
// with juno.locale.core.
@@ -443,7 +447,7 @@ package class CalendarData {
break;
}
- currentEra = eraNames.length;
+ currentEra = cast(int)eraNames.length;
}
private bool getCalendarData(string localeName, uint calendarId) {
@@ -2092,7 +2096,7 @@ private bool tryParseExact(string s, string pattern, DateTimeFormat dtf, ref Dat
bool doParse() {
- int parseDigits(string s, ref int pos, int max) {
+ int parseDigits(string s, ref size_t pos, int max) {
int result = s[pos++] - '0';
while (max > 1 && pos < s.length && s[pos] >= '0' && s[pos] <= '9') {
result = result * 10 + s[pos++] - '0';
@@ -2101,15 +2105,15 @@ private bool tryParseExact(string s, string pattern, DateTimeFormat dtf, ref Dat
return result;
}
- bool parseOne(string s, ref int pos, string value) {
+ bool parseOne(string s, ref size_t pos, string value) {
if (s[pos .. pos + value.length] != value)
return false;
pos += value.length;
return true;
}
- int parseMultiple(string s, ref int pos, string[] values ...) {
- int result = -1, max;
+ int parseMultiple(string s, ref size_t pos, string[] values ...) {
+ size_t result = -1, max;
foreach (i, value; values) {
if (value.length == 0 || s.length - pos < value.length)
continue;
@@ -2122,10 +2126,10 @@ private bool tryParseExact(string s, string pattern, DateTimeFormat dtf, ref Dat
}
}
pos += max;
- return result;
+ return to!int(result);
}
- TimeSpan parseTimeZoneOffset(string s, ref int pos) {
+ TimeSpan parseTimeZoneOffset(string s, ref size_t pos) {
bool sign;
if (pos < s.length) {
if (s[pos] == '-') {
@@ -2153,7 +2157,7 @@ private bool tryParseExact(string s, string pattern, DateTimeFormat dtf, ref Dat
result.hour = result.minute = result.second = 0;
result.fraction = 0.0;
- int pos, i, count;
+ size_t pos, i, count;
char c;
while (pos < pattern.length && i < s.length) {
diff --git a/source/juno/net/client.d b/source/juno/net/client.d
index a715c3d..adb533e 100644
--- a/source/juno/net/client.d
+++ b/source/juno/net/client.d
@@ -19,6 +19,7 @@ import juno.base.core,
static import std.c.stdlib;
import std.conv;
+import core.sys.windows.windows : DWORD_PTR;
debug import std.stdio : writeln, writefln;
@@ -197,7 +198,7 @@ enum : uint {
}
extern(Windows)
-alias void function(Handle hInternet, uint dwContext, uint dwInternetStatus, void* lpvStatusInformation, uint dwStatusInformationLength) INTERNET_STATUS_CALLBACK;
+alias void function(Handle hInternet, DWORD_PTR dwContext, uint dwInternetStatus, void* lpvStatusInformation, uint dwStatusInformationLength) INTERNET_STATUS_CALLBACK;
extern(Windows)
alias DllImport!("wininet.dll", "InternetSetStatusCallbackW",
@@ -227,17 +228,17 @@ enum : uint {
extern(Windows)
alias DllImport!("wininet.dll", "InternetConnectW",
- Handle function(Handle hInternet, in wchar* lpszServerName, ushort nServerPort, in wchar* lpszUserName, in wchar* lpszPassword, uint dwService, uint dwFlags, uint dwContext)) InternetConnect;
+ Handle function(Handle hInternet, in wchar* lpszServerName, ushort nServerPort, in wchar* lpszUserName, in wchar* lpszPassword, uint dwService, uint dwFlags, DWORD_PTR dwContext)) InternetConnect;
extern(Windows)
alias DllImport!("wininet.dll", "InternetOpenUrlW",
- Handle function(Handle hInternet, in wchar* lpszUrl, in wchar* lpszHeaders, uint dwHeadersLength, uint dwFlags, uint dwContext)) InternetOpenUrl;
+ Handle function(Handle hInternet, in wchar* lpszUrl, in wchar* lpszHeaders, uint dwHeadersLength, uint dwFlags, DWORD_PTR dwContext)) InternetOpenUrl;
const wchar* HTTP_VERSION = "HTTP/1.0";
extern(Windows)
alias DllImport!("wininet.dll", "HttpOpenRequestW",
- Handle function(Handle hConnect, in wchar* lpszVerb, in wchar* lpszObjectName, in wchar* lpszVersion, in wchar* lpszReferrer, in wchar** lplpszAcceptTypes, uint dwFlags, uint dwContext)) HttpOpenRequest;
+ Handle function(Handle hConnect, in wchar* lpszVerb, in wchar* lpszObjectName, in wchar* lpszVersion, in wchar* lpszReferrer, in wchar** lplpszAcceptTypes, uint dwFlags, DWORD_PTR dwContext)) HttpOpenRequest;
extern(Windows)
alias DllImport!("wininet.dll", "HttpSendRequestW",
@@ -263,11 +264,11 @@ enum : uint {
extern(Windows)
alias DllImport!("wininet.dll", "HttpSendRequestExW",
- int function(Handle hRequest, INTERNET_BUFFERSW* lpBuffersIn, INTERNET_BUFFERSW* lpBuffersOut, uint dwFlags, uint dwContext)) HttpSendRequestEx;
+ int function(Handle hRequest, INTERNET_BUFFERSW* lpBuffersIn, INTERNET_BUFFERSW* lpBuffersOut, uint dwFlags, DWORD_PTR dwContext)) HttpSendRequestEx;
extern(Windows)
alias DllImport!("wininet.dll", "HttpEndRequestW",
- int function(Handle hRequest, INTERNET_BUFFERSW* lpBuffersOut, uint dwFlags, uint dwContext)) HttpEndRequest;
+ int function(Handle hRequest, INTERNET_BUFFERSW* lpBuffersOut, uint dwFlags, DWORD_PTR dwContext)) HttpEndRequest;
enum : uint {
HTTP_QUERY_MIME_VERSION = 0,
@@ -416,15 +417,15 @@ enum : ushort {
extern(Windows)
alias DllImport!("wininet.dll", "FtpPutFileW",
- int function(Handle hConnect, in wchar* lpszLocalFile, in wchar* lpszNewRemoteFile, uint dwFlags, uint dwContext)) FtpPutFile;
+ int function(Handle hConnect, in wchar* lpszLocalFile, in wchar* lpszNewRemoteFile, uint dwFlags, DWORD_PTR dwContext)) FtpPutFile;
extern(Windows)
alias DllImport!("wininet.dll", "FtpOpenFileW",
- Handle function(Handle hConnect, in wchar* lpszFileName, uint dwAccess, uint dwFlags, uint dwContext)) FtpOpenFile;
+ Handle function(Handle hConnect, in wchar* lpszFileName, uint dwAccess, uint dwFlags, DWORD_PTR dwContext)) FtpOpenFile;
extern(Windows)
alias DllImport!("wininet.dll", "InternetQueryDataAvailable",
- int function(Handle hFile, uint* lpdwNumberOfBytesAvailable, uint dwFlags, uint dwContext)) InternetQueryDataAvailable;
+ int function(Handle hFile, uint* lpdwNumberOfBytesAvailable, uint dwFlags, DWORD_PTR dwContext)) InternetQueryDataAvailable;
extern(Windows)
alias DllImport!("wininet.dll", "InternetReadFile",
@@ -443,7 +444,7 @@ enum : uint {
extern(Windows)
alias DllImport!("wininet.dll", "InternetReadFileExW",
- int function(Handle hFile, INTERNET_BUFFERSW* lpBuffersOut, uint dwFlags, uint dwContext)) InternetReadFileEx;
+ int function(Handle hFile, INTERNET_BUFFERSW* lpBuffersOut, uint dwFlags, DWORD_PTR dwContext)) InternetReadFileEx;
/// void delegate(int percent, long bytesReceived, long bytesToReceive, ref bool abort)
alias void delegate(int percent, long bytesReceived, long bytesToReceive, out bool abort) DownloadProgressCallback;
@@ -797,7 +798,7 @@ private struct UploadBitsState {
private ubyte[] uploadBits(Uri address, string method, in ubyte[] data, UploadDataCompletedCallback uploadCompleted, UploadProgressCallback uploadProgress, bool async) {
extern(Windows)
- static void statusCallback(Handle handle, uint context, uint status, void* statusInformation, uint statusInformationLength) {
+ static void statusCallback(Handle handle, DWORD_PTR context, uint status, void* statusInformation, uint statusInformationLength) {
auto state = cast(UploadBitsState*)context;
switch (status) {
@@ -832,18 +833,18 @@ private ubyte[] uploadBits(Uri address, string method, in ubyte[] data, UploadDa
if (state.async) {
if (state.stage == 1) {
if (state.uri.scheme == Uri.uriSchemeFtp)
- FtpOpenFile(state.connection, state.uri.localPath().toUTF16z(), GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_RELOAD, cast(uint)state);
+ FtpOpenFile(state.connection, state.uri.localPath().toUTF16z(), GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_RELOAD, cast(DWORD_PTR)state);
else
- HttpOpenRequest(state.connection, state.method.toUTF16z(), state.uri.pathAndQuery().toUTF16z(), null, null, null, INTERNET_FLAG_RELOAD, cast(uint)state);
+ HttpOpenRequest(state.connection, state.method.toUTF16z(), state.uri.pathAndQuery().toUTF16z(), null, null, null, INTERNET_FLAG_RELOAD, cast(DWORD_PTR)state);
state.stage = 2;
}
else if (state.stage == 2) {
if (state.uri.scheme == Uri.uriSchemeFtp) {
uint bytesWritten;
- InternetWriteFile(state.file, state.buffer.ptr, state.buffer.length, &bytesWritten);
+ InternetWriteFile(state.file, state.buffer.ptr, to!uint(state.buffer.length), &bytesWritten);
}
else {
- HttpSendRequest(state.file, null, 0, state.buffer.ptr, state.buffer.length);
+ HttpSendRequest(state.file, null, 0, state.buffer.ptr, to!uint(state.buffer.length));
}
state.stage = 3;
}
@@ -915,7 +916,7 @@ private ubyte[] uploadBits(Uri address, string method, in ubyte[] data, UploadDa
password.toUTF16z(),
schemeIsFtp ? INTERNET_SERVICE_FTP : INTERNET_SERVICE_HTTP,
INTERNET_FLAG_PASSIVE | INTERNET_FLAG_DONT_CACHE,
- cast(uint)state);
+ cast(DWORD_PTR)state);
if (!async) scope(exit) InternetCloseHandle(connection);
if ((async && connection == Handle.init && GetLastError() != ERROR_IO_PENDING) || (!async && connection == Handle.init))
@@ -923,25 +924,25 @@ private ubyte[] uploadBits(Uri address, string method, in ubyte[] data, UploadDa
if (!async) {
if (schemeIsFtp) {
- Handle file = FtpOpenFile(connection, address.localPath().toUTF16z(), GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_RELOAD, cast(uint)state);
+ Handle file = FtpOpenFile(connection, address.localPath().toUTF16z(), GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_RELOAD, cast(DWORD_PTR)state);
scope(exit) InternetCloseHandle(file);
if (file == Handle.init)
throw new NetException;
uint bytesWritten;
- if (!InternetWriteFile(file, data.ptr, data.length, &bytesWritten)) {
+ if (!InternetWriteFile(file, data.ptr, to!uint(data.length), &bytesWritten)) {
//throw new NetException;
}
}
else {
- Handle request = HttpOpenRequest(connection, method.toUTF16z(), address.pathAndQuery().toUTF16z(), null, null, null, INTERNET_FLAG_RELOAD, cast(uint)state);
+ Handle request = HttpOpenRequest(connection, method.toUTF16z(), address.pathAndQuery().toUTF16z(), null, null, null, INTERNET_FLAG_RELOAD, cast(DWORD_PTR)state);
scope(exit) InternetCloseHandle(request);
if (request == Handle.init)
throw new NetException;
- if (!HttpSendRequest(request, null, 0, data.ptr, data.length)) {
+ if (!HttpSendRequest(request, null, 0, data.ptr, to!uint(data.length))) {
}
uint statusCode;
diff --git a/source/juno/net/core.d b/source/juno/net/core.d
index a3a8554..da3efe1 100644
--- a/source/juno/net/core.d
+++ b/source/juno/net/core.d
@@ -446,9 +446,9 @@ class Uri {
string path = getComponents(UriComponents.Path | UriComponents.KeepDelimiter);
if (path.length != 0) {
- int current;
+ size_t current;
while (current < path.length) {
- int next = path.indexOf('/', current);
+ auto next = path.indexOf('/', current);
if (next == -1)
next = path.length - 1;
@@ -462,7 +462,7 @@ class Uri {
}
private void parseUri(string s) {
- int i = s.indexOf(':');
+ auto i = s.indexOf(':');
if (i < 0)
return;
@@ -574,7 +574,7 @@ interface ICredentialsByHost {
private class CredentialKey {
Uri uriPrefix;
- int uriPrefixLength = -1;
+ size_t uriPrefixLength = -1;
string authType;
this(Uri uriPrefix, string authType) {
@@ -873,7 +873,7 @@ private @property bool isWin2k() {
private @property bool supportsIPv6() {
static Nullable!(bool) supportsIPv6_;
if (supportsIPv6_.isNull) {
- uint s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IP);
+ size_t s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IP);
if (GetLastError() != WSAEAFNOSUPPORT)
supportsIPv6_ = true;
else
@@ -1514,7 +1514,7 @@ class PingReply {
}
}
- private this(ICMPV6_ECHO_REPLY* reply, void* data, uint dataSize) {
+ private this(ICMPV6_ECHO_REPLY* reply, void* data, size_t dataSize) {
address_ = new IPAddress(reply.address.sin6_addr, reply.address.sin6_scope_id);
status_ = cast(IPStatus)reply.status;
if (status_ == IPStatus.Success) {
@@ -1613,6 +1613,8 @@ class Ping : IDisposable {
PingReply send(IPAddress address, uint timeout, ubyte[] buffer) {
if (address is null)
throw new ArgumentNullException("address");
+ if(buffer.length > ushort.max)
+ throw new ArgumentException("buffer");
ipv6_ = (address.addressFamily == AddressFamily.INET6);
@@ -1633,7 +1635,8 @@ class Ping : IDisposable {
memcpy(requestBuffer_, buffer.ptr, buffer.length);
scope(exit) LocalFree(requestBuffer_);
- uint replyBufferSize = ICMPV6_ECHO_REPLY.sizeof + buffer.length + 8;
+ uint replyBufferSize = ICMPV6_ECHO_REPLY.sizeof +
+ cast(ushort)buffer.length + 8;
if (replyBuffer_ == null)
replyBuffer_ = cast(void*)LocalAlloc(LMEM_FIXED, replyBufferSize);
diff --git a/source/juno/net/mail.d b/source/juno/net/mail.d
index 1fb872e..713a02f 100644
--- a/source/juno/net/mail.d
+++ b/source/juno/net/mail.d
@@ -334,7 +334,7 @@ class MailAddress {
private void parse(string address) {
string display;
- int i = address.indexOf('\"');
+ auto i = address.indexOf('\"');
if (i > 0)
throw new FormatException("The string is not in the form required for an e-mail address.");
@@ -427,7 +427,7 @@ class NameValueCollection {
nameAndValue_[name] = value;
}
- @property int count() {
+ @property size_t count() {
return nameAndValue_.keys.length;
}
diff --git a/source/juno/security/crypto.d b/source/juno/security/crypto.d
index e8d9b23..8869fc0 100644
--- a/source/juno/security/crypto.d
+++ b/source/juno/security/crypto.d
@@ -134,12 +134,12 @@ interface ICryptoTransform {
/**
* Transforms the specified input array and copies the resulting transform to the specified output array.
*/
- uint transformBlock(ubyte[] inputBuffer, uint inputOffset, uint inputCount, ubyte[] outputBuffer, uint outputOffset);
+ size_t transformBlock(ubyte[] inputBuffer, size_t inputOffset, uint inputCount, ubyte[] outputBuffer, size_t outputOffset);
/**
* Transforms the specified array.
*/
- ubyte[] transformFinalBlock(ubyte[] inputBuffer, uint inputOffset, uint inputCount);
+ ubyte[] transformFinalBlock(ubyte[] inputBuffer, size_t inputOffset, uint inputCount);
//ubyte[] transformFinalBlock(ubyte[] buffer);
/**
@@ -199,7 +199,7 @@ class CryptoStream : Stream {
private uint inputBufferIndex_;
private uint outputBlockSize_;
private ubyte[] outputBuffer_;
- private uint outputBufferIndex_;
+ private size_t outputBufferIndex_;
private bool finalBlockTransformed_;
@@ -274,8 +274,8 @@ class CryptoStream : Stream {
}
override size_t readBlock(void* buffer, size_t size) {
- uint readBytes = size;
- uint outputIndex = 0;
+ size_t readBytes = size;
+ size_t outputIndex = 0;
if (outputBufferIndex_ > 0) {
if (outputBufferIndex_ <= size) {
@@ -296,8 +296,8 @@ class CryptoStream : Stream {
if (finalBlockTransformed_)
return size - readBytes;
- uint outputBytes;
- uint numRead;
+ size_t outputBytes;
+ size_t numRead;
while (readBytes > 0) {
while (inputBufferIndex_ < inputBlockSize_) {
@@ -343,8 +343,8 @@ class CryptoStream : Stream {
}
override size_t writeBlock(in void* buffer, size_t size) {
- uint writeBytes = size;
- uint inputIndex = 0;
+ size_t writeBytes = size;
+ size_t inputIndex = 0;
if (inputBufferIndex_ > 0) {
if (size >= inputBlockSize_ - inputBufferIndex_) {
@@ -365,7 +365,7 @@ class CryptoStream : Stream {
outputBufferIndex_ = 0;
}
- uint outputBytes;
+ size_t outputBytes;
if (inputBufferIndex_ == inputBlockSize_) {
outputBytes = transform_.transformBlock(inputBuffer_, 0, inputBlockSize_, outputBuffer_, 0);
stream_.writeBlock(outputBuffer_.ptr, outputBytes);
@@ -374,8 +374,8 @@ class CryptoStream : Stream {
while (writeBytes > 0) {
if (writeBytes >= inputBlockSize_) {
- uint wholeBlocks = writeBytes / inputBlockSize_;
- uint wholeBlocksBytes = wholeBlocks * inputBlockSize_;
+ size_t wholeBlocks = writeBytes / inputBlockSize_;
+ uint wholeBlocksBytes = to!uint(wholeBlocks * inputBlockSize_);
ubyte[] tempBuffer = new ubyte[wholeBlocks * outputBlockSize_];
outputBytes = transform_.transformBlock(cast(ubyte[])buffer[0 .. size], inputIndex, wholeBlocksBytes, tempBuffer, 0);
@@ -425,7 +425,7 @@ abstract class HashAlgorithm : ICryptoTransform, IDisposable {
/**
* Computes the hash for the specified data.
*/
- final ubyte[] computeHash(ubyte[] buffer, uint offset, uint count) {
+ final ubyte[] computeHash(ubyte[] buffer, size_t offset, uint count) {
hashCore(buffer, offset, count);
hashValue = hashFinal();
@@ -436,17 +436,17 @@ abstract class HashAlgorithm : ICryptoTransform, IDisposable {
/// ditto
final ubyte[] computeHash(ubyte[] buffer) {
- return computeHash(buffer, 0, buffer.length);
+ return computeHash(buffer, 0, to!uint(buffer.length));
}
/// ditto
final ubyte[] computeHash(Stream input) {
ubyte[] buffer = new ubyte[4096];
- uint len;
+ size_t len;
do {
len = input.read(buffer);
if (len > 0)
- hashCore(buffer, 0, len);
+ hashCore(buffer, 0, to!uint(len));
} while (len > 0);
hashValue = hashFinal();
@@ -458,7 +458,7 @@ abstract class HashAlgorithm : ICryptoTransform, IDisposable {
/**
* Computes the hash value for the specified input array and copies the resulting hash value to the specified output array.
*/
- final uint transformBlock(ubyte[] inputBuffer, uint inputOffset, uint inputCount, ubyte[] outputBuffer, uint outputOffset) {
+ final size_t transformBlock(ubyte[] inputBuffer, size_t inputOffset, uint inputCount, ubyte[] outputBuffer, size_t outputOffset) {
hashCore(inputBuffer, inputOffset, inputCount);
if (outputBuffer != null && (inputBuffer != outputBuffer || inputOffset != outputOffset))
//memmove(outputBuffer.ptr + outputOffset, inputBuffer.ptr + inputOffset, inputCount);
@@ -469,7 +469,7 @@ abstract class HashAlgorithm : ICryptoTransform, IDisposable {
/**
* Computes the hash value for the specified input array.
*/
- final ubyte[] transformFinalBlock(ubyte[] inputBuffer, uint inputOffset, uint inputCount) {
+ final ubyte[] transformFinalBlock(ubyte[] inputBuffer, size_t inputOffset, uint inputCount) {
hashCore(inputBuffer, inputOffset, inputCount);
hashValue = hashFinal();
@@ -483,7 +483,7 @@ abstract class HashAlgorithm : ICryptoTransform, IDisposable {
abstract void initialize() {
}
- protected void hashCore(ubyte[] array, uint start, uint size);
+ protected void hashCore(ubyte[] array, size_t start, uint size);
protected ubyte[] hashFinal();
@@ -564,7 +564,7 @@ final class KeySizes {
abstract class SymmetricAlgorithm : IDisposable {
protected ubyte[] keyValue;
- protected uint keySizeValue;
+ protected size_t keySizeValue;
protected KeySizes[] legalKeySizesValue;
protected ubyte[] ivValue;
protected uint blockSizeValue;
@@ -616,14 +616,14 @@ abstract class SymmetricAlgorithm : IDisposable {
/**
* Determines whether the specified key size is valid for the algorithm.
*/
- final bool isValidKeySize(uint bitLength) {
+ final bool isValidKeySize(size_t bitLength) {
foreach (keySize; legalKeySizes) {
if (keySize.skip == 0) {
if (keySize.min == bitLength)
return true;
}
else {
- for (uint i = keySize.min; i <= keySize.max; i += keySize.skip) {
+ for (size_t i = keySize.min; i <= keySize.max; i += keySize.skip) {
if (i == bitLength)
return true;
}
@@ -649,7 +649,7 @@ abstract class SymmetricAlgorithm : IDisposable {
/**
* Gets or sets the size in bits of the secret key used by the symmetric algorithm.
*/
- @property void keySize(uint value) {
+ @property void keySize(size_t value) {
if (!isValidKeySize(value))
throw new CryptoException;
@@ -657,7 +657,7 @@ abstract class SymmetricAlgorithm : IDisposable {
keyValue = null;
}
/// ditto
- @property uint keySize() {
+ @property size_t keySize() {
return keySizeValue;
}
@@ -723,7 +723,7 @@ abstract class SymmetricAlgorithm : IDisposable {
abstract class AsymmetricAlgorithm : IDisposable {
protected KeySizes[] legalKeySizesValue;
- protected uint keySizeValue;
+ protected size_t keySizeValue;
protected this() {
}
@@ -731,7 +731,7 @@ abstract class AsymmetricAlgorithm : IDisposable {
/**
* Gets or sets the size in bits of the key used by the asymmetric algorithm.
*/
- void keySize(uint value) {
+ void keySize(size_t value) {
foreach (keySize; legalKeySizesValue) {
if (keySize.skip == 0) {
if (keySize.min == value) {
@@ -751,7 +751,7 @@ abstract class AsymmetricAlgorithm : IDisposable {
throw new CryptoException;
}
/// ditto
- uint keySize() {
+ size_t keySize() {
return keySizeValue;
}
@@ -835,7 +835,7 @@ private final class CAPIHashAlgorithm {
hash_ = newHash;
}
- void hashCore(ubyte[] array, uint start, uint size) {
+ void hashCore(ubyte[] array, size_t start, uint size) {
if (!CryptHashData(hash_, array.ptr + start, size, 0))
throw new CryptoException(GetLastError());
}
@@ -917,7 +917,7 @@ private final class BCryptHashAlgorithm {
hashObject_ = newHashObject;
}
- void hashCore(ubyte[] array, uint start, uint size) {
+ void hashCore(ubyte[] array, size_t start, uint size) {
int r = BCryptHashData(hash_, array.ptr + start, size, 0);
if (r != ERROR_SUCCESS)
throw new CryptoException(r);
@@ -931,7 +931,7 @@ private final class BCryptHashAlgorithm {
throw new CryptoException(r);
ubyte[] output = new ubyte[hashSize];
- r = BCryptFinishHash(hash_, output.ptr, output.length, 0);
+ r = BCryptFinishHash(hash_, output.ptr, to!uint(output.length), 0);
if (r != ERROR_SUCCESS)
throw new CryptoException(r);
return output;
@@ -996,7 +996,7 @@ final class Md5CryptoServiceProvider : Md5 {
hashAlgorithm_.initialize();
}
- protected override void hashCore(ubyte[] array, uint start, uint size) {
+ protected override void hashCore(ubyte[] array, size_t start, uint size) {
hashAlgorithm_.hashCore(array, start, size);
}
@@ -1032,7 +1032,7 @@ final class Md5Cng : Md5 {
hashAlgorithm_.initialize();
}
- protected override void hashCore(ubyte[] array, uint start, uint size) {
+ protected override void hashCore(ubyte[] array, size_t start, uint size) {
hashAlgorithm_.hashCore(array, start, size);
}
@@ -1083,7 +1083,7 @@ final class Sha1CryptoServiceProvider : Sha1 {
hashAlgorithm_.initialize();
}
- protected override void hashCore(ubyte[] array, uint start, uint size) {
+ protected override void hashCore(ubyte[] array, size_t start, uint size) {
hashAlgorithm_.hashCore(array, start, size);
}
@@ -1119,7 +1119,7 @@ final class Sha1Cng : Sha1 {
hashAlgorithm_.initialize();
}
- protected override void hashCore(ubyte[] array, uint start, uint size) {
+ protected override void hashCore(ubyte[] array, size_t start, uint size) {
hashAlgorithm_.hashCore(array, start, size);
}
@@ -1170,7 +1170,7 @@ final class Sha256CryptoServiceProvider : Sha256 {
hashAlgorithm_.initialize();
}
- protected override void hashCore(ubyte[] array, uint start, uint size) {
+ protected override void hashCore(ubyte[] array, size_t start, uint size) {
hashAlgorithm_.hashCore(array, start, size);
}
@@ -1206,7 +1206,7 @@ final class Sha256Cng : Sha256 {
hashAlgorithm_.initialize();
}
- protected override void hashCore(ubyte[] array, uint start, uint size) {
+ protected override void hashCore(ubyte[] array, size_t start, uint size) {
hashAlgorithm_.hashCore(array, start, size);
}
@@ -1257,7 +1257,7 @@ final class Sha384CryptoServiceProvider : Sha384 {
hashAlgorithm_.initialize();
}
- protected override void hashCore(ubyte[] array, uint start, uint size) {
+ protected override void hashCore(ubyte[] array, size_t start, uint size) {
hashAlgorithm_.hashCore(array, start, size);
}
@@ -1293,7 +1293,7 @@ final class Sha384Cng : Sha384 {
hashAlgorithm_.initialize();
}
- protected override void hashCore(ubyte[] array, uint start, uint size) {
+ protected override void hashCore(ubyte[] array, size_t start, uint size) {
hashAlgorithm_.hashCore(array, start, size);
}
@@ -1344,7 +1344,7 @@ final class Sha512CryptoServiceProvider : Sha512 {
hashAlgorithm_.initialize();
}
- protected override void hashCore(ubyte[] array, uint start, uint size) {
+ protected override void hashCore(ubyte[] array, size_t start, uint size) {
hashAlgorithm_.hashCore(array, start, size);
}
@@ -1380,7 +1380,7 @@ final class Sha512Cng : Sha512 {
hashAlgorithm_.initialize();
}
- protected override void hashCore(ubyte[] array, uint start, uint size) {
+ protected override void hashCore(ubyte[] array, size_t start, uint size) {
hashAlgorithm_.hashCore(array, start, size);
}
@@ -1483,7 +1483,8 @@ final class TripleDesCryptoServiceProvider : TripleDes {
override void generateIV() {
ubyte[] iv = new ubyte[8];
- if (!CryptGenRandom(provider_, iv.length, iv.ptr))
+ assert(iv.length < ubyte.max);
+ if (!CryptGenRandom(provider_, cast(ubyte)iv.length, iv.ptr))
throw new CryptoException(GetLastError());
ivValue = iv;
}
@@ -1501,12 +1502,12 @@ final class TripleDesCryptoServiceProvider : TripleDes {
return exportSymmetricKey(key_);
}
- override void keySize(uint value) {
+ override void keySize(size_t value) {
super.keySize = value;
if (key_ != Handle.init)
CryptDestroyKey(key_);
}
- override uint keySize() {
+ override size_t keySize() {
return super.keySize;
}
@@ -1683,7 +1684,7 @@ final class AesCryptoServiceProvider : Aes {
override void generateIV() {
ubyte[] iv = new ubyte[blockSizeValue / 8];
- if (!CryptGenRandom(provider_, iv.length, iv.ptr))
+ if (!CryptGenRandom(provider_, to!uint(iv.length), iv.ptr))
throw new CryptoException(GetLastError());
ivValue = iv;
}
@@ -1701,16 +1702,16 @@ final class AesCryptoServiceProvider : Aes {
return exportSymmetricKey(key_);
}
- override void keySize(uint value) {
+ override void keySize(size_t value) {
super.keySize = value;
if (key_ != Handle.init)
CryptDestroyKey(key_);
}
- override uint keySize() {
+ override size_t keySize() {
return super.keySize;
}
- private static uint algorithmId(uint keySize) {
+ private static uint algorithmId(size_t keySize) {
switch (keySize) {
case 128: return CALG_AES_128;
case 192: return CALG_AES_192;
@@ -1744,7 +1745,7 @@ private ubyte[] exportSymmetricKey(Handle key) {
}
private Handle importSymmetricKey(Handle provider, uint algorithm, ubyte[] key) {
- uint cbData = BLOBHEADER.sizeof + uint.sizeof + key.length;
+ uint cbData = to!uint(BLOBHEADER.sizeof + uint.sizeof + key.length);
auto pbData = cast(ubyte*)malloc(cbData);
auto pBlob = cast(BLOBHEADER*)pbData;
@@ -1753,7 +1754,7 @@ private Handle importSymmetricKey(Handle provider, uint algorithm, ubyte[] key)
pBlob.reserved = 0;
pBlob.aiKeyAlg = algorithm;
- *(cast(uint*)pbData + BLOBHEADER.sizeof) = key.length;
+ *(cast(uint*)pbData + BLOBHEADER.sizeof) = to!uint(key.length);
memmove(pbData + BLOBHEADER.sizeof + uint.sizeof, key.ptr, key.length);
Handle importedKey;
@@ -1881,7 +1882,7 @@ final class RsaCryptoServiceProvider : Rsa {
isPublic = false;
if (isPublic) {
- if (!CryptImportKey(provider_, keyBlob.ptr, keyBlob.length, exchangeKey, CRYPT_EXPORTABLE, key_))
+ if (!CryptImportKey(provider_, keyBlob.ptr, to!uint(keyBlob.length), exchangeKey, CRYPT_EXPORTABLE, key_))
throw new CryptoException(GetLastError());
}
else {
@@ -2013,15 +2014,15 @@ final class RsaCryptoServiceProvider : Rsa {
ubyte[] encrypt(ubyte[] rgb, bool useOAEP) {
ensureKeyPair();
- uint cb = rgb.length;
- if (!CryptEncrypt(key_, Handle.init, TRUE, useOAEP ? CRYPT_OAEP : 0, null, cb, rgb.length))
+ uint cb = to!uint(rgb.length);
+ if (!CryptEncrypt(key_, Handle.init, TRUE, useOAEP ? CRYPT_OAEP : 0, null, cb, to!uint(rgb.length)))
throw new CryptoException(GetLastError());
auto encryptedData = new ubyte[cb];
encryptedData[0 .. rgb.length] = rgb;
- cb = rgb.length;
- if (!CryptEncrypt(key_, Handle.init, TRUE, useOAEP ? CRYPT_OAEP : 0, encryptedData.ptr, cb, encryptedData.length))
+ cb = to!uint(rgb.length);
+ if (!CryptEncrypt(key_, Handle.init, TRUE, useOAEP ? CRYPT_OAEP : 0, encryptedData.ptr, cb, to!uint(encryptedData.length)))
throw new CryptoException(GetLastError());
return encryptedData;
@@ -2031,21 +2032,21 @@ final class RsaCryptoServiceProvider : Rsa {
ubyte[] decrypt(ubyte[] rgb, bool useOAEP) {
ensureKeyPair();
- uint cb = rgb.length;
+ uint cb = to!uint(rgb.length);
if (!CryptDecrypt(key_, Handle.init, TRUE, useOAEP ? CRYPT_OAEP : 0, null, cb))
throw new CryptoException(GetLastError());
auto decryptedData = new ubyte[cb];
decryptedData[0 .. rgb.length] = rgb;
- cb = rgb.length;
+ cb = to!uint(rgb.length);
if (!CryptDecrypt(key_, Handle.init, TRUE, useOAEP ? CRYPT_OAEP : 0, decryptedData.ptr, cb))
throw new CryptoException(GetLastError());
return decryptedData;
}
///
- ubyte[] signData(ubyte[] buffer, uint offset, uint count, string algorithm) {
+ ubyte[] signData(ubyte[] buffer, size_t offset, uint count, string algorithm) {
CRYPT_OID_INFO oidInfo;
if (auto pOidInfo = CryptFindOIDInfo(CRYPT_OID_INFO_NAME_KEY, algorithm.toUTF16z(), 0))
oidInfo = *pOidInfo;
@@ -2058,7 +2059,7 @@ final class RsaCryptoServiceProvider : Rsa {
/// ditto
ubyte[] signData(ubyte[] buffer, string algorithm) {
- return signData(buffer, 0, buffer.length, algorithm);
+ return signData(buffer, 0, to!uint(buffer.length), algorithm);
}
/// ditto
@@ -2098,11 +2099,11 @@ final class RsaCryptoServiceProvider : Rsa {
///
bool verifyData(ubyte[] data, string algorithm, ubyte[] signature) {
- return verifyData(data, 0, data.length, algorithm, signature);
+ return verifyData(data, 0, to!uint(data.length), algorithm, signature);
}
///
- bool verifyData(ubyte[] data, uint offset, uint count, string algorithm, ubyte[] signature) {
+ bool verifyData(ubyte[] data, size_t offset, uint count, string algorithm, ubyte[] signature) {
CRYPT_OID_INFO oidInfo;
if (auto pOidInfo = CryptFindOIDInfo(CRYPT_OID_INFO_NAME_KEY, algorithm.toUTF16z(), 0))
oidInfo = *pOidInfo;
@@ -2138,7 +2139,7 @@ final class RsaCryptoServiceProvider : Rsa {
throw new CryptoException(GetLastError());
scope(exit) CryptDestroyHash(tempHash);
- if (!CryptVerifySignature(tempHash, hash.ptr, hash.length, key_, null, 0)) {
+ if (!CryptVerifySignature(tempHash, hash.ptr, to!uint(hash.length), key_, null, 0)) {
uint lastError = GetLastError();
if (lastError != NTE_BAD_SIGNATURE)
throw new CryptoException(lastError);
@@ -2147,7 +2148,7 @@ final class RsaCryptoServiceProvider : Rsa {
return true;
}
- override uint keySize() {
+ override size_t keySize() {
ensureKeyPair();
uint cbKeySize = uint.sizeof;
@@ -2257,7 +2258,7 @@ final class DsaCryptoServiceProvider : Dsa {
isPublic = false;
if (isPublic) {
- if (!CryptImportKey(provider_, keyBlob.ptr, keyBlob.length, Handle.init, /*CRYPT_EXPORTABLE*/ 0, key_))
+ if (!CryptImportKey(provider_, keyBlob.ptr, to!uint(keyBlob.length), Handle.init, /*CRYPT_EXPORTABLE*/ 0, key_))
throw new CryptoException(GetLastError());
}
else {
@@ -2281,14 +2282,14 @@ final class DsaCryptoServiceProvider : Dsa {
}
///
- ubyte[] signData(ubyte[] buffer, uint offset, uint count) {
+ ubyte[] signData(ubyte[] buffer, size_t offset, uint count) {
ubyte[] hash = hashAlgorithm_.computeHash(buffer, offset, count);
return signHash(hash, null);
}
/// ditto
ubyte[] signData(ubyte[] buffer) {
- return signData(buffer, 0, buffer.length);
+ return signData(buffer, 0, to!uint(buffer.length));
}
/// ditto
@@ -2322,11 +2323,11 @@ final class DsaCryptoServiceProvider : Dsa {
///
bool verifyData(ubyte[] data, ubyte[] signature) {
- return verifyData(data, 0, data.length, signature);
+ return verifyData(data, 0, to!uint(data.length), signature);
}
/// ditto
- bool verifyData(ubyte[] data, uint offset, uint count, ubyte[] signature) {
+ bool verifyData(ubyte[] data, size_t offset, uint count, ubyte[] signature) {
ubyte[] hash = hashAlgorithm_.computeHash(data, offset, count);
return verifyHash(hash, null, signature);
}
@@ -2350,7 +2351,7 @@ final class DsaCryptoServiceProvider : Dsa {
throw new CryptoException(GetLastError());
scope(exit) CryptDestroyHash(tempHash);
- if (!CryptVerifySignature(tempHash, hash.ptr, hash.length, key_, null, 0)) {
+ if (!CryptVerifySignature(tempHash, hash.ptr, to!uint(hash.length), key_, null, 0)) {
uint lastError = GetLastError();
if (lastError != NTE_BAD_SIGNATURE)
throw new CryptoException(lastError);
@@ -2359,7 +2360,7 @@ final class DsaCryptoServiceProvider : Dsa {
return true;
}
- override uint keySize() {
+ override size_t keySize() {
ensureKeyPair();
uint cbKeySize = uint.sizeof;
@@ -2430,22 +2431,22 @@ private final class CAPITransform : ICryptoTransform {
}
}
- private uint encryptBlocks(ubyte[] buffer, uint offset, uint count) {
- uint length = count;
- if (!CryptEncrypt(key_, Handle.init, FALSE, 0, buffer.ptr + offset, length, buffer.length))
+ private uint encryptBlocks(ubyte[] buffer, size_t offset, uint count) {
+ auto length = count;
+ if (!CryptEncrypt(key_, Handle.init, FALSE, 0, buffer.ptr + offset, length, to!uint(buffer.length)))
throw new CryptoException(GetLastError());
//writefln("CryptEncrypt");
return length;
}
- private uint decryptBlocks(ubyte[] buffer, uint offset, uint count) {
- uint length = count;
+ private size_t decryptBlocks(ubyte[] buffer, size_t offset, uint count) {
+ auto length = count;
if (!CryptDecrypt(key_, Handle.init, FALSE, 0, buffer.ptr + offset, length))
throw new CryptoException(GetLastError());
return length;
}
- uint transformBlock(ubyte[] inputBuffer, uint inputOffset, uint inputCount, ubyte[] outputBuffer, uint outputOffset) {
+ size_t transformBlock(ubyte[] inputBuffer, size_t inputOffset, uint inputCount, ubyte[] outputBuffer, size_t outputOffset) {
//writefln("transformBlock");
if (encryptionMode_ == EncryptionMode.Encrypt) {
//memmove(outputBuffer.ptr + outputOffset, inputBuffer.ptr + inputOffset, inputCount);
@@ -2459,7 +2460,7 @@ private final class CAPITransform : ICryptoTransform {
depadBuffer_.length = inputBlockSize;
}
else {
- uint c = decryptBlocks(depadBuffer_, 0, depadBuffer_.length);
+ auto c = decryptBlocks(depadBuffer_, 0, to!uint(depadBuffer_.length));
//memmove(outputBuffer.ptr + outputOffset, depadBuffer_.ptr, c);
blockCopy(depadBuffer_, 0, outputBuffer, outputOffset, c);
depadBuffer_[] = 0;
@@ -2480,13 +2481,13 @@ private final class CAPITransform : ICryptoTransform {
}
}
- ubyte[] transformFinalBlock(ubyte[] inputBuffer, uint inputOffset, uint inputCount) {
+ ubyte[] transformFinalBlock(ubyte[] inputBuffer, size_t inputOffset, uint inputCount) {
- ubyte[] padBlock(ubyte[] block, uint offset, uint count) {
+ ubyte[] padBlock(ubyte[] block, size_t offset, size_t count) {
assert(block != null && count <= block.length - offset);
ubyte[] bytes;
- uint padding = inputBlockSize - (count % inputBlockSize);
+ auto padding = inputBlockSize - (count % inputBlockSize);
switch (paddingMode_) {
case PaddingMode.None:
bytes.length = count;
@@ -2514,7 +2515,7 @@ private final class CAPITransform : ICryptoTransform {
case PaddingMode.ISO10126:
bytes.length = count + padding;
- CryptGenRandom(provider_, bytes.length - 1, bytes.ptr);
+ CryptGenRandom(provider_, to!uint(bytes.length - 1), bytes.ptr);
bytes[0 .. count] = block[0 .. count];
bytes[$ - 1] = cast(ubyte)padding;
break;
@@ -2525,7 +2526,7 @@ private final class CAPITransform : ICryptoTransform {
return bytes;
}
- ubyte[] depadBlock(ubyte[] block, uint offset, uint count) {
+ ubyte[] depadBlock(ubyte[] block, size_t offset, size_t count) {
assert(block != null && count >= block.length - offset);
uint padding;
@@ -2539,7 +2540,7 @@ private final class CAPITransform : ICryptoTransform {
if (0 > padding || padding > inputBlockSize)
throw new CryptoException("Padding is invalid.");
- for (uint i = offset + count - padding; i < offset + count; i++) {
+ for (auto i = offset + count - padding; i < offset + count; i++) {
if (block[i] != cast(ubyte)padding)
throw new CryptoException("Padding is invalid");
}
@@ -2550,7 +2551,7 @@ private final class CAPITransform : ICryptoTransform {
if (0 > padding || padding > inputBlockSize)
throw new CryptoException("Padding is invalid.");
- for (uint i = offset + count - padding; i < offset + count - 1; i++) {
+ for (auto i = offset + count - padding; i < offset + count - 1; i++) {
if (block[i] != 0)
throw new CryptoException("Padding is invalid.");
}
@@ -2579,7 +2580,7 @@ private final class CAPITransform : ICryptoTransform {
memmove(bytes.ptr, inputBuffer.ptr + inputOffset, inputCount);*/
finalBytes = padBlock(inputBuffer, inputOffset, inputCount);
if (finalBytes.length > 0)
- encryptBlocks(finalBytes, 0, finalBytes.length);
+ encryptBlocks(finalBytes, 0, to!uint(finalBytes.length));
}
else {
ubyte[] temp;
@@ -2596,7 +2597,7 @@ private final class CAPITransform : ICryptoTransform {
blockCopy(inputBuffer, inputOffset, temp, depadBuffer_.length, inputCount);
}
if (temp.length > 0) {
- uint c = decryptBlocks(temp, 0, temp.length);
+ auto c = decryptBlocks(temp, 0, to!uint(temp.length));
finalBytes = depadBlock(temp, 0, c);
}
}
@@ -2604,7 +2605,7 @@ private final class CAPITransform : ICryptoTransform {
ubyte[] temp = new ubyte[outputBlockSize];
uint count = 0;
if (encryptionMode_ == EncryptionMode.Encrypt)
- CryptEncrypt(key_, Handle.init, TRUE, 0, temp.ptr, count, temp.length);
+ CryptEncrypt(key_, Handle.init, TRUE, 0, temp.ptr, count, to!uint(temp.length));
else
CryptDecrypt(key_, Handle.init, TRUE, 0, temp.ptr, count);
delete temp;
@@ -2621,7 +2622,7 @@ private final class CAPITransform : ICryptoTransform {
output = new ubyte[inputBlockSize];
memmove(output.ptr, buffer.ptr, buffer.length);
- uint count = output.length;
+ size_t count = output.length;
if (!CryptEncrypt(key_, Handle.init, FALSE, 0, output.ptr, count, output.length))
throw new CryptoException(GetLastError());
@@ -2631,7 +2632,7 @@ private final class CAPITransform : ICryptoTransform {
output = new ubyte[outputBlockSize];
memmove(output.ptr, buffer.ptr, buffer.length);
- uint count = output.length;
+ size_t count = output.length;
if (!CryptDecrypt(key_, Handle.init, FALSE, 0, output.ptr, count))
throw new CryptoException(GetLastError());
@@ -2639,7 +2640,7 @@ private final class CAPITransform : ICryptoTransform {
}
ubyte[] temp = new ubyte[outputBlockSize];
- uint count = 0;
+ size_t count = 0;
if (encryptionMode_ == EncryptionMode.Encrypt)
CryptEncrypt(key_, Handle.init, TRUE, 0, temp.ptr, count, temp.length);
else
@@ -2681,7 +2682,7 @@ final class RngCryptoServiceProvider : RandomNumberGenerator {
}
override void getBytes(ubyte[] data) {
- if (!CryptGenRandom(provider_, data.length, data.ptr))
+ if (!CryptGenRandom(provider_, to!uint(data.length), data.ptr))
throw new CryptoException(GetLastError());
}
@@ -2725,7 +2726,7 @@ final class RngCng : RandomNumberGenerator {
}
override void getBytes(ubyte[] data) {
- int r = BCryptGenRandom(algorithm_, data.ptr, data.length, 0);
+ int r = BCryptGenRandom(algorithm_, data.ptr, to!uint(data.length), 0);
if (r != ERROR_SUCCESS)
throw new CryptoException(r);
}
@@ -2759,9 +2760,9 @@ enum DataProtectionScope {
ubyte[] protectData(ubyte[] userData, ubyte[] optionalEntropy, DataProtectionScope protectionScope) {
DATA_BLOB dataBlob, entropyBlob, resultBlob;
- dataBlob = DATA_BLOB(userData.length, userData.ptr);
+ dataBlob = DATA_BLOB(to!uint(userData.length), userData.ptr);
if (optionalEntropy != null)
- entropyBlob = DATA_BLOB(optionalEntropy.length, optionalEntropy.ptr);
+ entropyBlob = DATA_BLOB(to!uint(optionalEntropy.length), optionalEntropy.ptr);
uint flags = CRYPTPROTECT_UI_FORBIDDEN;
if (protectionScope == DataProtectionScope.LocalMachine)
@@ -2784,9 +2785,9 @@ ubyte[] protectData(ubyte[] userData, ubyte[] optionalEntropy, DataProtectionSco
ubyte[] unprotectData(ubyte[] protectedData, ubyte[] optionalEntropy, DataProtectionScope protectionScope) {
DATA_BLOB dataBlob, entropyBlob, resultBlob;
- dataBlob = DATA_BLOB(protectedData.length, protectedData.ptr);
+ dataBlob = DATA_BLOB(to!uint(protectedData.length), protectedData.ptr);
if (optionalEntropy != null)
- entropyBlob = DATA_BLOB(optionalEntropy.length, optionalEntropy.ptr);
+ entropyBlob = DATA_BLOB(to!uint(optionalEntropy.length), optionalEntropy.ptr);
uint flags = CRYPTPROTECT_UI_FORBIDDEN;
if (protectionScope == DataProtectionScope.LocalMachine)
@@ -2837,7 +2838,7 @@ void protectMemory(ubyte[] userData, MemoryProtectionScope protectionScope) {
if (userData.length == 0 || (userData.length % 16) != 0)
throw new CryptoException("The length of the data must be a multiple of 16 bytes.");
- int status = RtlEncryptMemory(userData.ptr, userData.length, cast(uint)protectionScope);
+ int status = RtlEncryptMemory(userData.ptr, to!uint(userData.length), cast(uint)protectionScope);
if (status < 0)
throw new CryptoException(LsaNtStatusToWinError(status));
}
@@ -2849,7 +2850,7 @@ void unprotectMemory(ubyte[] encryptedData, MemoryProtectionScope protectionScop
if (encryptedData.length == 0 || (encryptedData.length % 16) != 0)
throw new CryptoException("The length of the data must be a multiple of 16 bytes.");
- int status = RtlDecryptMemory(encryptedData.ptr, encryptedData.length, cast(uint)protectionScope);
+ int status = RtlDecryptMemory(encryptedData.ptr, to!uint(encryptedData.length), cast(uint)protectionScope);
if (status < 0)
throw new CryptoException(LsaNtStatusToWinError(status));
}
diff --git a/source/juno/xml/dom.d b/source/juno/xml/dom.d
index e3d2608..3abad05 100644
--- a/source/juno/xml/dom.d
+++ b/source/juno/xml/dom.d
@@ -1100,7 +1100,7 @@ class XmlNode {
}
private static void splitName(string name, out string prefix, out string localName) {
- int i = name.indexOf(':');
+ auto i = name.indexOf(':');
if (i == -1 || i == 0 || name.length - 1 == i) {
prefix = "";
localName = name;