* string-ci* oddity
@ 2008-12-19 14:55 Bill Schottstaedt
2009-01-02 2:36 ` Thien-Thi Nguyen
0 siblings, 1 reply; 3+ messages in thread
From: Bill Schottstaedt @ 2008-12-19 14:55 UTC (permalink / raw)
To: bug-guile
Why do both Guile and Gauche give this result in string-ci<?
(and the other string-ci functions similarly):
guile> (char-ci<? #\a #\_)
#t
guile> (string-ci<? "a" "_")
#f
gosh> (char-ci<? #\a #\_)
#t
gosh> (string-ci<? "a" "_")
#f
The odd chars are ASCII 91 to 96:
guile> (string-ci<? "a" "[")
#f
guile> (char-ci<? #\a #\[)
#t
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: string-ci* oddity
2008-12-19 14:55 string-ci* oddity Bill Schottstaedt
@ 2009-01-02 2:36 ` Thien-Thi Nguyen
2009-02-02 0:00 ` Thien-Thi Nguyen
0 siblings, 1 reply; 3+ messages in thread
From: Thien-Thi Nguyen @ 2009-01-02 2:36 UTC (permalink / raw)
To: bug-guile
() "Bill Schottstaedt" <bil@ccrma.Stanford.EDU>
() Fri, 19 Dec 2008 06:55:21 -0800
Why do both Guile and Gauche give this result in string-ci<?
(and the other string-ci functions similarly):
The odd chars are ASCII 91 to 96:
ASCII 91-96 lie between the two ranges A-Z and a-z.
One procedure smashes case up and the other down.
Smashing happens unconditionally.
(define (my-char-ci<? p q)
(< (down p)) (down q))
Another more complicated (but arguably more correct) approach
would be to determine if one/both of the args are not smashable,
and entirely avoid smashing in that case. Something like:
(define (smashable? c)
(or (<= #\a c #\z) (<= #\A c #\Z)))
(define (my-char-ci<? p q)
(if (and (smashable? p) (smashable? q))
(< (down p) (down q))
(< p q)))
Pseudoscheme (numeric operators don't actually take chars),
but you get the idea.
thi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: string-ci* oddity
2009-01-02 2:36 ` Thien-Thi Nguyen
@ 2009-02-02 0:00 ` Thien-Thi Nguyen
0 siblings, 0 replies; 3+ messages in thread
From: Thien-Thi Nguyen @ 2009-02-02 0:00 UTC (permalink / raw)
To: bug-guile
FYI, below is the code that all ci comparison
funcs will be using in the next Guile 1.4.x release.
This means, for example:
(char-ci<? #\a #\_) => #f.
thi
___________________________________________________________________
// libguile/chars.c
#define ISLOWER(c) (islower (c) ? (1 + c - 'a') : 0)
#define ISUPPER(c) (isupper (c) ? (1 + c - 'A') : 0)
static int
ccmp_ci (int x, int y)
{
int lx, ux = 0, ly, uy = 0, rv;
rv = ((! ((lx = ISLOWER (x)) || (ux = ISUPPER (x))))
||
(! ((ly = ISLOWER (y)) || (uy = ISUPPER (y)))))
/* One or both do not satisfy `isalpha'; subtract directly. */
? (x - y)
/* Both satisfy `isalpha'; subtract in one domain or another. */
: (lx
? (lx - (ly
? ly
: uy))
: (ux - (uy
? uy
: ly)));
return !rv
? 0
: (GOOD (rv)
? 1
: -1);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-02-02 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-19 14:55 string-ci* oddity Bill Schottstaedt
2009-01-02 2:36 ` Thien-Thi Nguyen
2009-02-02 0:00 ` Thien-Thi Nguyen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).