Closed Bug 101852 Opened 23 years ago Closed 23 years ago

implement nsCRT::IsAsciiString

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla0.9.6

People

(Reporter: darin.moz, Assigned: ftang)

Details

Attachments

(1 file)

the patch for bug 42898 introduced an IsAsciiString helper function that really
should be a part of nsCRT.
This is how it looks like:

PRBool
IsAsciiString(const char *s)
{
    for (const char *c = s; *c; c++) {
        if (!nsCRT::IsAscii(*c)) return PR_FALSE;
    }
    return PR_TRUE;
}
hmm...

it looks like there already is a:
 PRBool nsCRT::IsAscii(PRUnichar *aString)

However, it does not look like it performs the tests as the patch here.  cc-ing
frank for clarity.  
what is needed is:

   nsCRT::IsAscii(const char *aString)

to accompany the Unicode version that is already there.
sorry for not being more clear.  I do not think that:
PRBool nsCRT::IsAscii(PRUnichar *aString)
is implemented correctly.

Assign to frank.  

Frank can you verify that IsAscii(PRUnichar *aString) is implmented correctly
and add nsCRT::IsAscii(const char *aString).

Assignee: dougt → ftang
PRBool nsCRT::IsAscii(PRUnichar *aString)

should have const before the PRUnichar, right?

/be
It looks like both nsCRT::IsAscii in source/xpcom/ds/nsCRT.cpp were implemented 
correctly:


672 
673 /**
674  *  Determine if given char in valid alpha range
675  *  
676  *  @update  ftang 04.27.2000
677  *  @param   aChar is character to be tested
678  *  @return  TRUE if in ASCII range
679  */
680 PRBool nsCRT::IsAscii(PRUnichar aChar) {
681   return (0x0080 > aChar);
682 }
683 /**
684  *  Determine if given char in valid alpha range
685  *  
686  *  @update  ftang 04.27.2000
687  *  @param   aString is null terminated to be tested
688  *  @return  TRUE if all characters aare in ASCII range
689  */
690 PRBool nsCRT::IsAscii(PRUnichar *aString) {
691   while(*aString) {
692      if( 0x0080 <= *aString)
693         return PR_FALSE;
694      aString++;
695   }
696   return PR_TRUE;
697 }

>------- Additional Comments From Brendan Eich 2001-10-01 15:24 -------
>PRBool nsCRT::IsAscii(PRUnichar *aString)
>should have const before the PRUnichar, right?
>/be

yes
notice that PRUnichar is unsigned data type so (0x0080 < *aString) work if 
*aString is 0xfffe . However, char is signed data type so (0x80 < *aString) 
won't work for the char* version, we need to use (0x80 & *aString) to check it 
is pure 7-bits data or not. 

>sorry for not being more clear.  I do not think that:
>PRBool nsCRT::IsAscii(PRUnichar *aString)
>is implemented correctly.
Why you said so, which part is not correct ? 
ASCII in unicode is defined from U+0000 to U+007F

darin, can you r= my patch ?
Status: NEW → ASSIGNED
Comment on attachment 51696 [details]
here is the patch for IsAscii(const char* aString) and adding the const part.

sr=darin
Attachment #51696 - Flags: superreview+
Comment on attachment 51696 [details]
here is the patch for IsAscii(const char* aString) and adding the const part.

r=alecf
Attachment #51696 - Flags: review+
Comment on attachment 51696 [details]
here is the patch for IsAscii(const char* aString) and adding the const part.

ftang, just wanted to point out that casting like so:

    0x80 <= (unsigned char)*aString

is an alternative to testing 0x80 & *aString.  Either is likely to be as fast, I think (possibly the & test is faster).

/be
wait for m0.9.6 open to check in 
Target Milestone: --- → mozilla0.9.6
fix and check in 
fixed and check in 
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
So we can now remove nsDNSService::IsAsciiString and
nsHttpHandler::IsAsciiString right?
william: looks like it -- how about a trivial patch for iDNS code, in a new bug?

/be 
Trivial patch in bug 103991.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: