Closed
Bug 101852
Opened 23 years ago
Closed 23 years ago
implement nsCRT::IsAsciiString
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
mozilla0.9.6
People
(Reporter: darin.moz, Assigned: ftang)
Details
Attachments
(1 file)
2.06 KB,
text/plain
|
alecf
:
review+
darin.moz
:
superreview+
|
Details |
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;
}
Comment 2•23 years ago
|
||
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.
Reporter | ||
Comment 3•23 years ago
|
||
what is needed is:
nsCRT::IsAscii(const char *aString)
to accompany the Unicode version that is already there.
Comment 4•23 years ago
|
||
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
Comment 5•23 years ago
|
||
PRBool nsCRT::IsAscii(PRUnichar *aString)
should have const before the PRUnichar, right?
/be
Assignee | ||
Comment 6•23 years ago
|
||
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
Assignee | ||
Comment 7•23 years ago
|
||
Assignee | ||
Comment 8•23 years ago
|
||
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.
Assignee | ||
Comment 9•23 years ago
|
||
>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
Reporter | ||
Comment 10•23 years ago
|
||
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 11•23 years ago
|
||
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 12•23 years ago
|
||
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
Assignee | ||
Comment 13•23 years ago
|
||
wait for m0.9.6 open to check in
Target Milestone: --- → mozilla0.9.6
Assignee | ||
Comment 14•23 years ago
|
||
fix and check in
Assignee | ||
Comment 15•23 years ago
|
||
fixed and check in
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Comment 16•23 years ago
|
||
So we can now remove nsDNSService::IsAsciiString and
nsHttpHandler::IsAsciiString right?
Comment 17•23 years ago
|
||
william: looks like it -- how about a trivial patch for iDNS code, in a new bug?
/be
Comment 18•23 years ago
|
||
Trivial patch in bug 103991.
You need to log in
before you can comment on or make changes to this bug.
Description
•