diff --git a/source/numem/collections/vector.d b/source/numem/collections/vector.d index ff9fa9d..414c737 100644 --- a/source/numem/collections/vector.d +++ b/source/numem/collections/vector.d @@ -572,7 +572,7 @@ public: D slices are short lived and may end up pointing to invalid memory if their string is modified. */ @trusted - T[] opSlice(size_t dim = 0)(size_t start, size_t end) { + inout(T)[] opSlice(size_t dim = 0)(size_t start, size_t end) inout { return memory[start..end]; } diff --git a/source/numem/core/env.d b/source/numem/core/env.d index 543e1d3..c12fbc5 100644 --- a/source/numem/core/env.d +++ b/source/numem/core/env.d @@ -15,6 +15,7 @@ import numem.core.memory; version(Windows) import core.sys.windows.winbase : GetEnvironmentVariableW, SetEnvironmentVariableW; else import core.sys.posix.stdlib : setenv, getenv; +import core.sys.windows.raserror; @nogc: @@ -26,7 +27,7 @@ struct Environment { private: static nstring get(const(char)* key) { version(Windows) { - auto utf16k = key.toUTF16; + auto utf16k = key.fromStringz.toUTF16; // Try getting the size of the env var. // if this fails, the env var is probably empty. @@ -37,7 +38,7 @@ private: // Windows includes the null terminator, but n*string does too // so to not have 2 null terminators, subtract 1. nwstring envstr = nwstring(bufSize-1); - bufSize = GetEnvironmentVariableW(utf16k.ptr, envstr.ptr, envstr.length+1); + bufSize = GetEnvironmentVariableW(utf16k.ptr, cast(wchar*)envstr.ptr, cast(uint)(envstr.length+1)); nogc_delete(utf16k); return envstr.toUTF8; @@ -48,9 +49,9 @@ private: static bool set(const(char)* key, nstring value) { version(Windows) { - auto utf16k = key.toUTF16(); + auto utf16k = key.fromStringz.toUTF16(); auto utf16v = value.toUTF16(); - return SetEnvironmentVariableW(utf16k.ptr, utf16v.ptr); + return cast(bool)SetEnvironmentVariableW(utf16k.ptr, utf16v.ptr); } else { return setenv(key, value.ptr, 1) == 0; } diff --git a/source/numem/string.d b/source/numem/string.d index 7bd09fe..4faf5ed 100644 --- a/source/numem/string.d +++ b/source/numem/string.d @@ -416,19 +416,16 @@ public: } /** - Tests equality between nstrings + Tests equality between strings */ @trusted - bool opEquals(R)(R other) if(is(R == basic_string!T)) { - return this.length == other.length && this[0..$] == other[0..$]; - } - - /** - Tests equality between nstrings - */ - @trusted - bool opEquals(R)(R other) if(is(R == immutable(T)[])) { - return this.size == other.length && this[0..$-1] == other[0..$]; + bool opEquals(R)(ref auto inout R other) inout if (isSomeString!R) { + static if (isSomeCString!R) + size_t len = cstrlen(other); + else + size_t len = other.length; + + return this.length == len && this.vec_[0..len] == other[0..len]; } /** diff --git a/source/numem/text/unicode/package.d b/source/numem/text/unicode/package.d index 8e95096..f85e762 100644 --- a/source/numem/text/unicode/package.d +++ b/source/numem/text/unicode/package.d @@ -110,8 +110,8 @@ T encode(T)(ref auto UnicodeSequence seq, bool addBOM = false) if (isSomeNString This will always create a copy. */ -ref auto toUTF8(FromT)(ref auto T from) if (isSomeSafeString!T) { - static if (StringCharSize!T == 1) +ref auto toUTF8(FromT)(ref auto FromT from) if (isSomeSafeString!FromT) { + static if (StringCharSize!FromT == 1) return nstring(from); else return encode!nstring(decode(from, true), false); @@ -122,8 +122,8 @@ ref auto toUTF8(FromT)(ref auto T from) if (isSomeSafeString!T) { This will always create a copy. */ -ref auto toUTF16(FromT)(ref auto T from, bool addBOM = false) if (isSomeSafeString!T) { - static if (StringCharSize!T == 2) +ref auto toUTF16(FromT)(ref auto FromT from, bool addBOM = false) if (isSomeSafeString!FromT) { + static if (StringCharSize!FromT == 2) return nwstring(from); else return encode!nwstring(decode(from, true), addBOM); @@ -134,8 +134,8 @@ ref auto toUTF16(FromT)(ref auto T from, bool addBOM = false) if (isSomeSafeStri This will always create a copy. */ -ref auto toUTF32(FromT)(ref auto T from, bool addBOM = false) if (isSomeSafeString!T) { - static if (StringCharSize!T == 2) +ref auto toUTF32(FromT)(ref auto FromT from, bool addBOM = false) if (isSomeSafeString!FromT) { + static if (StringCharSize!FromT == 2) return ndstring(from); else return encode!ndstring(decode(from, true), addBOM); diff --git a/source/numem/text/unicode/utf8.d b/source/numem/text/unicode/utf8.d index cd55e8d..295b17a 100644 --- a/source/numem/text/unicode/utf8.d +++ b/source/numem/text/unicode/utf8.d @@ -290,9 +290,10 @@ UnicodeSequence decode(inout(char)[] str) { // Validate length, add FFFD if invalid. size_t clen = str[i].getLength(); - if (clen >= i+str.length || clen == 0) { + if (i+clen > str.length || clen == 0) { code ~= unicodeReplacementCharacter; i++; + continue; } txt[0..clen] = str[i..i+clen];