Thread overview
Error: `std.uni.isUpper` conflicts with `std.ascii.isUpper`
Jul 14, 2020
Marcone
Jul 14, 2020
Ben Jones
Jul 14, 2020
oddp
Jul 14, 2020
oddp
Jul 15, 2020
WebFreak001
Jul 15, 2020
aberba
Jul 15, 2020
WebFreak001
July 14, 2020
import std: isUpper, writeln;

void main(){
	writeln(isUpper('A'));
}

Why I get this error? How can I use isUpper()?
July 14, 2020
On Tuesday, 14 July 2020 at 20:37:53 UTC, Marcone wrote:
> import std: isUpper, writeln;
>
> void main(){
> 	writeln(isUpper('A'));
> }
>
> Why I get this error? How can I use isUpper()?

import std.uni: isUpper; // or import std.ascii : isUpper
import std.stdio : writeln;

import std pulls in all the modules in phobos and uni and ascii both contain functions named isUpper.  There's probably many ways to fix the error, but I usually import the modules I want explicitly.
July 14, 2020
On 2020-07-14 22:37, Marcone via Digitalmars-d-learn wrote:
> import std: isUpper, writeln;
> 
> void main(){
>      writeln(isUpper('A'));
> }
> 
> Why I get this error? How can I use isUpper()?

Two more options:

either fully qualify the name:

import std;
void main(){
    writeln(std.uni.isUpper('A'));
}

or import locally:

import std;
void main(){
    import std.uni;
    writeln(isUpper('A'));
}
July 14, 2020
On 2020-07-14 22:37, Marcone via Digitalmars-d-learn wrote:
> import std: isUpper, writeln;
> 
> void main(){
>      writeln(isUpper('A'));
> }
> 
> Why I get this error? How can I use isUpper()?

Two more options:

either fully qualify the name:

import std;
void main(){
    writeln(std.uni.isUpper('A'));
}

or import locally:

import std;
void main(){
    import std.uni;
    writeln(isUpper('A'));
}
July 15, 2020
On Tuesday, 14 July 2020 at 20:37:53 UTC, Marcone wrote:
> import std: isUpper, writeln;
>
> void main(){
> 	writeln(isUpper('A'));
> }
>
> Why I get this error? How can I use isUpper()?

Additionally to the other answers telling you how to fix it, it's important to know why it happens in the first place:

std.ascii defines an isUpper method which only works on ASCII characters (byte value < 128), which means it's a really simple and very fast check, basically the same as `c >= 'A' && c <= 'Z'` but usually more readable. The other functions in std.ascii work the same and are all just very convenient methods for these simple checks. You should only really use this for file formats and internal strings, never for anything the user could input (preferably not even for validation of English applications)

std.uni defines an isUpper method as defined in the unicode 6.2 spec (the whole std.uni module is for these standardized unicode classifications and transformations, but NOT for UTF encoding/decoding, that's what std.utf is for), which means it works for a lot more languages than just the basic English alphabet in ASCII, at the cost of being slower.

If you have a normal import like `import std;` you can specify "more specified" imports using `import std.uni : isUpper;` or `import std.ascii : isUpper;` which will not clash with your first import, as long as you don't try to import both in the same scope. Basically:


import std;
import std.uni : isUpper;

bool someUserInputTest(string x) { return x[0].isUpper; }


Note that none of D's std.uni functions support using any locale, so if you want to do anything more than the default language neutral unicode locale you will have to use some library or using the OS APIs. Note also that D is missing some unicode properties like some check for characters which aren't lowercase or UPPERCASE but Titlecase (like Dz [U+01F2 LATIN CAPITAL LETTER D WITH SMALL LETTER Z]) which you could however use OS APIs for.
July 15, 2020
On Wednesday, 15 July 2020 at 07:01:34 UTC, WebFreak001 wrote:
> On Tuesday, 14 July 2020 at 20:37:53 UTC, Marcone wrote:
>> [...]
>
> Additionally to the other answers telling you how to fix it, it's important to know why it happens in the first place:
>
> [...]

Without reading this very explanation, how would one know whilst reading docs?
July 15, 2020
On Wednesday, 15 July 2020 at 11:25:34 UTC, aberba wrote:
> On Wednesday, 15 July 2020 at 07:01:34 UTC, WebFreak001 wrote:
>> On Tuesday, 14 July 2020 at 20:37:53 UTC, Marcone wrote:
>>> [...]
>>
>> Additionally to the other answers telling you how to fix it, it's important to know why it happens in the first place:
>>
>> [...]
>
> Without reading this very explanation, how would one know whilst reading docs?

in that explanation I broadly covered:

https://dlang.org/spec/module.html#name_lookup
https://dlang.org/spec/module.html#selective_imports
https://dlang.org/phobos/std_ascii.html
https://dlang.org/phobos/std_ascii.html#isUpper
https://dlang.org/phobos/std_uni.html
https://dlang.org/phobos/std_uni.html#isUpper
https://dlang.org/phobos/std_uni.html#Character