Merge pull request #8944 from WalterBright/unqualCast2

utf.d replace use of Unqual with cast()
This commit is contained in:
Walter Bright 2024-03-09 16:52:18 -08:00 committed by GitHub
commit 6fa90fe18e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -328,7 +328,7 @@ Returns:
bool isValidCodepoint(Char)(Char c) bool isValidCodepoint(Char)(Char c)
if (isSomeChar!Char) if (isSomeChar!Char)
{ {
alias UChar = Unqual!Char; alias UChar = typeof(cast() c);
static if (is(UChar == char)) static if (is(UChar == char))
{ {
return c <= 0x7F; return c <= 0x7F;
@ -1418,8 +1418,8 @@ do
} }
else else
{ {
alias Char = Unqual!(ElementType!S); alias Char = typeof(cast() ElementType!S.init);
Char[4] codeUnits; Char[4] codeUnits = void;
S tmp = str.save; S tmp = str.save;
for (size_t i = numCodeUnits; i > 0; ) for (size_t i = numCodeUnits; i > 0; )
{ {
@ -2821,7 +2821,7 @@ if (isSomeChar!C)
size_t codeLength(C, InputRange)(InputRange input) size_t codeLength(C, InputRange)(InputRange input)
if (isSomeFiniteCharInputRange!InputRange) if (isSomeFiniteCharInputRange!InputRange)
{ {
alias EncType = Unqual!(ElementEncodingType!InputRange); alias EncType = typeof(cast() ElementEncodingType!InputRange.init);
static if (isSomeString!InputRange && is(EncType == C) && is(typeof(input.length))) static if (isSomeString!InputRange && is(EncType == C) && is(typeof(input.length)))
return input.length; return input.length;
else else
@ -3089,7 +3089,8 @@ private T toUTFImpl(T, S)(scope S s)
static if (is(S == C[], C) || hasLength!S) static if (is(S == C[], C) || hasLength!S)
app.reserve(s.length); app.reserve(s.length);
foreach (c; s.byUTF!(Unqual!(ElementEncodingType!T))) ElementEncodingType!T e = void;
foreach (c; s.byUTF!(typeof(cast() ElementEncodingType!T.init)))
app.put(c); app.put(c);
return app.data; return app.data;
@ -3168,10 +3169,10 @@ if (is(immutable typeof(*P.init) == typeof(str[0])))
return trustedPtr(); return trustedPtr();
} }
alias C = Unqual!(ElementEncodingType!S); alias C = typeof(cast() ElementEncodingType!S.init);
//If the P is mutable, then we have to make a copy. //If the P is mutable, then we have to make a copy.
static if (is(Unqual!(typeof(*P.init)) == typeof(*P.init))) static if (is(typeof(cast() *P.init) == typeof(*P.init)))
{ {
return toUTFzImpl!(P, const(C)[])(cast(const(C)[])str); return toUTFzImpl!(P, const(C)[])(cast(const(C)[])str);
} }
@ -3204,12 +3205,14 @@ if (is(typeof(str[0]) C) && is(immutable typeof(*P.init) == immutable C) && !is(
//C[] or const(C)[] -> C*, const(C)*, or immutable(C)* //C[] or const(C)[] -> C*, const(C)*, or immutable(C)*
{ {
alias InChar = typeof(str[0]); alias InChar = typeof(str[0]);
alias UInChar = typeof(cast() str[0]); // unqualified version of InChar
alias OutChar = typeof(*P.init); alias OutChar = typeof(*P.init);
alias UOutChar = typeof(cast() *P.init); // unqualified version
//const(C)[] -> const(C)* or //const(C)[] -> const(C)* or
//C[] -> C* or const(C)* //C[] -> C* or const(C)*
static if (( is(const(Unqual!InChar) == InChar) && is(const(Unqual!OutChar) == OutChar)) || static if (( is(const(UInChar) == InChar) && is( const(UOutChar) == OutChar)) ||
(!is(const(Unqual!InChar) == InChar) && !is(immutable(Unqual!OutChar) == OutChar))) (!is(const(UInChar) == InChar) && !is(immutable(UOutChar) == OutChar)))
{ {
if (!__ctfe) if (!__ctfe)
{ {
@ -3228,7 +3231,7 @@ if (is(typeof(str[0]) C) && is(immutable typeof(*P.init) == immutable C) && !is(
else else
{ {
import std.array : uninitializedArray; import std.array : uninitializedArray;
auto copy = uninitializedArray!(Unqual!OutChar[])(str.length + 1); auto copy = uninitializedArray!(UOutChar[])(str.length + 1);
copy[0 .. $ - 1] = str[]; copy[0 .. $ - 1] = str[];
copy[$ - 1] = '\0'; copy[$ - 1] = '\0';