www.digitalmars.com         C & C++   DMDScript  

D - the switch statement with reference to strings and case sensitivity

reply scott tara.mvdomain (Scott Robinson) writes:
The inclusion of strings (ex: "switch (s) { case "hello": case "HELLO": }")
I believe is a great addition.

However, that said, you haven't specified if the string matching is case
sensitive. Reason suggests it is, and this doesn't make the new switch
statement ability as useful as it could be.

I wonder if there could be a possible inclusion of of something like switch
(s) with (y), in that y is/can be strcmp or stricmp?

The dealings of return values, loops, and sensitivity to the case contents
are all issues which can be worked out simply - but specific implementatoin
I leave to the actual designers.

Scott.

-- 
jabber:quad jabber.org         - Universal ID (www.jabber.org)
http://dsn.itgo.com/           - Personal webpage
robhome.dyndns.org             - Home firewall

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GAT dpu s: a--- C++ UL+++ P++ L+++ E- W++ N+ o+ K w
O M V- PS+ PE Y+ PGP+++ t++ 5 X R tv b++++ DI++++ D++
G+ e+ h! r- y
------END GEEK CODE BLOCK------
Aug 17 2001
next sibling parent reply Russ Lewis <russ deming-os.org> writes:
Scott Robinson wrote:

 The inclusion of strings (ex: "switch (s) { case "hello": case "HELLO": }")
 I believe is a great addition.

 However, that said, you haven't specified if the string matching is case
 sensitive. Reason suggests it is, and this doesn't make the new switch
 statement ability as useful as it could be.

 I wonder if there could be a possible inclusion of of something like switch
 (s) with (y), in that y is/can be strcmp or stricmp?

Or, perhaps, regular expressions could be used. :)
Aug 17 2001
parent reply scott tara.mvdomain (Scott Robinson) writes:
Yikes! Are regular expressions, by default, in the language?

Regular expressions certainly seem to defeat the idea of a readable
language. ;-) Plus they're a bit heavy weight for a couple case insensitive
string comparisons.

Scott.

In article <3B7D3B11.47C93DE deming-os.org>, Russ Lewis wrote:
Scott Robinson wrote:

 The inclusion of strings (ex: "switch (s) { case "hello": case "HELLO": }")
 I believe is a great addition.

 However, that said, you haven't specified if the string matching is case
 sensitive. Reason suggests it is, and this doesn't make the new switch
 statement ability as useful as it could be.

 I wonder if there could be a possible inclusion of of something like switch
 (s) with (y), in that y is/can be strcmp or stricmp?

Or, perhaps, regular expressions could be used. :)

-- jabber:quad jabber.org - Universal ID (www.jabber.org) http://dsn.itgo.com/ - Personal webpage robhome.dyndns.org - Home firewall -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GAT dpu s: a--- C++ UL+++ P++ L+++ E- W++ N+ o+ K w O M V- PS+ PE Y+ PGP+++ t++ 5 X R tv b++++ DI++++ D++ G+ e+ h! r- y ------END GEEK CODE BLOCK------
Aug 17 2001
parent reply Russ Lewis <russ deming-os.org> writes:
Scott Robinson wrote:

 Yikes! Are regular expressions, by default, in the language?

 Regular expressions certainly seem to defeat the idea of a readable
 language. ;-) Plus they're a bit heavy weight for a couple case insensitive
 string comparisons.

Yeah, they're pretty heavyweight for simple compares, but they allow unbelievable flexibility. Perhaps something analogous to grep, where you can do "simple" compares with a trivial syntax, and regular expressions if necessary.
Aug 17 2001
parent "Dave Nebinger" <dnebinger riteaid.com> writes:
Guys, what's wrong with "switch (lower(s)){case 'hello':..."?

"Russ Lewis" <russ deming-os.org> wrote in message
news:3B7D4064.66FF69BC deming-os.org...
 Scott Robinson wrote:

 Yikes! Are regular expressions, by default, in the language?

 Regular expressions certainly seem to defeat the idea of a readable
 language. ;-) Plus they're a bit heavy weight for a couple case


 string comparisons.

Yeah, they're pretty heavyweight for simple compares, but they allow

 flexibility.  Perhaps something analogous to grep, where you can do

 compares with a trivial syntax, and regular expressions if necessary.

Aug 17 2001
prev sibling next sibling parent Christophe de Dinechin <descubes earthlink.net> writes:
Scott Robinson wrote:

 The inclusion of strings (ex: "switch (s) { case "hello": case "HELLO": }")
 I believe is a great addition.

I am a bit puzzled by how this would be implemented. Case 1: strings are simiilar in internal structure to C strings (a pointer to bytes, possibly with a length). Then, are two strings with the same content but different values equal in a switch? Note that you can't easily guarantee that the pointers for identical strings will always be equal, at least in the case of shared libraries... Case 2: strings are more complex things (like a string token, an ID in a string table, an atom, call it what you want). In that case, identity is easier to define, BUT you pay a price on every string creation. Christophe PS: Maybe this is somehwere in the spec, but I did not see it.
Aug 18 2001
prev sibling parent "Walter" <walter digitalmars.com> writes:
Yes, it's case sensitive. -Walter

Scott Robinson wrote in message ...
The inclusion of strings (ex: "switch (s) { case "hello": case "HELLO": }")
I believe is a great addition.

However, that said, you haven't specified if the string matching is case
sensitive. Reason suggests it is, and this doesn't make the new switch
statement ability as useful as it could be.

I wonder if there could be a possible inclusion of of something like switch
(s) with (y), in that y is/can be strcmp or stricmp?

The dealings of return values, loops, and sensitivity to the case contents
are all issues which can be worked out simply - but specific implementatoin
I leave to the actual designers.

Scott.

--
jabber:quad jabber.org         - Universal ID (www.jabber.org)
http://dsn.itgo.com/           - Personal webpage
robhome.dyndns.org             - Home firewall

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GAT dpu s: a--- C++ UL+++ P++ L+++ E- W++ N+ o+ K w
O M V- PS+ PE Y+ PGP+++ t++ 5 X R tv b++++ DI++++ D++
G+ e+ h! r- y
------END GEEK CODE BLOCK------

Aug 18 2001