Closed Bug 337730 Opened 19 years ago Closed 19 years ago

Add additional utilities to nsStringAPI

Categories

(Core :: XPCOM, defect)

PowerPC
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9alpha1

People

(Reporter: benjamin, Assigned: benjamin)

References

Details

Attachments

(1 file, 1 obsolete file)

Porting additional string utilies to the frozen string API, as needed by camino and gnomevfs.
Blocks: 337731
Attachment #221824 - Flags: review?(darin)
Comment on attachment 221824 [details] [diff] [review] Additional string utilities and tests, rev. 1 >Index: xpcom/glue/nsStringAPI.cpp >+void >+nsAString::Trim(const char *aSet, PRBool aLeading, PRBool aTrailing) >+PRBool >+nsAString::LowerCaseEqualsLiteral(const char *aASCIIString) const >+{ >+ PRUint32 otherlen = strlen(aASCIIString); Might be nice to avoid paying the cost of this strlen. Just walk the two buffers looking for a terminator or begin==end. >+static PRBool NS_strnmatch(const PRUnichar *aStr, const char* aSubstring, >+static PRBool NS_strnimatch(const PRUnichar *aStr, const char* aSubstring, Hrm... maybe these shouldn't use the NS_ prefix as that is generally used for public facing APIs. >+ // Set the new length. >+ NS_StringGetMutableData(aString, end - start, &start); >+} Maybe this should just call SetLength. >+PRInt32 >+CaseInsensitiveCompare(const char *a, const char *b, >+ PRUint32 len) >+{ >+ for (const char *aend = a + len; a < aend; ++a, ++b) { >+ char la = NS_ToLower(*a); >+ char lb = NS_ToLower(*b); >+ >+ if (la == lb) >+ continue; >+ >+ return la < lb ? -1 : 1; >+ } >+ >+ return 0; >+} It seems like it would be beneficial if there was a way to get direct access to kUpper2Lower (and kLower2Upper) to avoid the function call overhead of NS_ToLower (and NS_ToUpper). r=darin
Attachment #221824 - Flags: review?(darin) → review+
Hopefully interdiff will make the change obvious here.
Attachment #221824 - Attachment is obsolete: true
Comment on attachment 222675 [details] [diff] [review] Additional string utilities and tests, rev. 1.1 >? xpcom/tests/external/Makefile.in Forgot to cvs add? >Index: xpcom/ds/nsCRT.h ... > static PRUint32 strlen(const PRUnichar* s) { >+ if (!s) { >+ NS_ERROR("Passing null to nsCRT::strlen"); >+ return 0; >+ } > return NS_strlen(s); > } Add a TODO comment about removing this code eventually? r=darin
Attachment #222675 - Flags: review+
Fixed on trunk. Whittling away at the libxul-frozen-only dependency list continues!
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Blocks: 743581
No longer blocks: 150073
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: