Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 90 additions & 87 deletions source/juno/base/collections.d

Large diffs are not rendered by default.

232 changes: 75 additions & 157 deletions source/juno/base/string.d

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions source/juno/base/text.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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);
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions source/juno/base/threading.d
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions source/juno/com/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions source/juno/io/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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];
}
Expand Down Expand Up @@ -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;
}

Expand Down
127 changes: 3 additions & 124 deletions source/juno/io/filesystem.d
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}
16 changes: 8 additions & 8 deletions source/juno/io/path.d
Original file line number Diff line number Diff line change
Expand Up @@ -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]))) {
Expand Down Expand Up @@ -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)
Expand All @@ -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 .. $];
Expand All @@ -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);
Expand All @@ -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.
Expand Down
Loading