numericValue for (unicode) characters

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Jan 9 15:21:13 PST 2013


On Mon, Jan 07, 2013 at 07:51:19PM +0100, monarch_dodra wrote:
> On Saturday, 5 January 2013 at 00:47:14 UTC, H. S. Teoh wrote:
> >[...]
> >I, for one, would love to know why isNumeric != hasNumericValue.
[...]
> I guess it's just bad wording from the standard.
> 
> The standard defined 3 groups that make up Number:
> [Nd] 	Number, Decimal Digit
> [Nl] 	Number, Letter
> [No] 	Number, Other
> 
> However, there are a couple of characters that *are* numbers, but
> aren't in those goups.
> 
> The "Good" news is that the standard, *does* define number_types to
> classify the kind of number a char is:
> * Null: Not a number
> * Digit: Obvious
> * Decimal: Any decimal number that is NOT a digit
> * Numeric: Everything else.
> 
> So they used "Numeric" as wild, and "Number" as their general
> category.
> 
> This leaves us with ambiguity when choosing our word:
> Technically '5' does not clasify as "numeric", although you could
> consider it "has a numeric value".
> 
> I hope that makes sense.

Hmph. I guess we need to differentiate between the unicode category
called "numeric", and the property of having a numerical value. So we'd
need both isNumeric and hasNumericValue. Ugh. It's ugly but if that's
what the standard is, then that's what it is.

Anyway, I'd love to see std.uni cover all unicode categories.

Offhanded note: should we unify the various isX() functions into:

	bool inCategory(string category)(dchar ch)

where category is the Unicode designation, say "Nl", "Nd", etc.? That
way, it's more future-proof in case the Unicode guys add more
categories. Also makes it easier to remember which function to call;
else you'd always have to remember "N" -> isNumeric, "L" -> isAlpha,
etc..

The current names of course can be left as aliases.


T

-- 
The fact that anyone still uses AOL shows that even the presence of
options doesn't stop some people from picking the pessimal one. - Mike
Ellis


More information about the Digitalmars-d mailing list