Should you be able to initialize a float with a char?
kdevel
kdevel at vogtner.de
Thu May 19 22:14:31 UTC 2022
On Thursday, 19 May 2022 at 20:48:47 UTC, Ali Çehreli wrote:
[...]
> > "However, the assumption that setting bit 5 of the
> representation will
> > convert uppercase letters to lowercase is not valid for
> EBCDIC." [1]
> >
> > [1] Does C and C++ guarantee the ASCII of [a-f] and [A-F]
> characters?
> > https://ogeek.cn/qa/?qa=669486/
>
> In D, char is UTF-8 and ASCII is a subset of UTF-8.
The latter part, that ASCII is a subset of UTF-8, is 1†. I
disagree with the wording of the former part, that in D a char
"is" UTF-8.
> Walter's code above is valid without making any ASCII
> assumption.
Walter made the 0 claim "It does not assume it, it tests for if
it would be valid [ascii and not unicode]" [2] ‡
Okay. Let's do UTF-8:
```
import std.stdio;
import std.string;
import std.utf;
char char_tolower_bright (char c)
{
if ('A' <= c && c <= 'Z')
c = c | 0x20;
return c;
}
string tolower_bright (string s)
{
string t;
foreach (c; s.byCodeUnit)
t ~= c.char_tolower_bright;
return t;
}
void process_strings (string s)
{
writefln!"input : %s" (s);
auto t = s.tolower_bright;
writefln!"bright : %s" (t);
auto u = s.toLower;
writefln!"toLower (std.utf): %s" (u);
}
void main ()
{
process_strings ("A Ä");
process_strings ("A Ä");
}
```
Free of charge I compiled and ran this for you:
$ dmd lcb
$ ./lcb
input : A Ä
bright : a Ä
toLower (std.utf): a ä
input : A Ä
bright : a ä
toLower (std.utf): a ä
See the problem?
† Hint for interpretation: booleans "are" integers.
[2] http://forum.dlang.org/post/t662ll$tnm$1@digitalmars.com
‡ There is probably no consensus about what "it" means.
More information about the Digitalmars-d
mailing list