Convert C-string version of nsCCommaSeparatedTokenizer into generic version, too.
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 03 May 2010 19:11:19 -0700
changeset 1555 919d2f65c65b14eeb88b0d0de07840414c8da814
parent 1554 7a792acb48c78defe41fb9f47813a3cd30344b7a
child 1556 07e0021effbc68a28557e1c1b65808bc5a3f5b4e
push id1253
push userdholbert@mozilla.com
push dateTue, 04 May 2010 02:11:24 +0000
Convert C-string version of nsCCommaSeparatedTokenizer into generic version, too.
series
tokenizer_extendCstringVersion
--- a/series
+++ b/series
@@ -1,12 +1,13 @@
 smil_infallibleMisc #+WIP
 tokenizer_renameFile
 tokenizer_allowOtherChars
 tokenizer_allowSeparatorToBeOptional
 tokenizer_fixOldUses
 tokenizer_useInSVGAndSMIL
+tokenizer_extendCstringVersion
 smil_541297ChangeAbortToWarning
 smil_541297Fix
 smil_debuggingCode #+debug
 smil_misc #+nits
 smil_cacheTextZoom #+notsure
 smil_alwaysRecomposeDebugging #+debug
new file mode 100644
--- /dev/null
+++ b/tokenizer_extendCstringVersion
@@ -0,0 +1,182 @@
+From: Daniel Holbert <dholbert@cs.stanford.edu>
+Bug 562310 Part 6: Convert C-string version (nsCCommaSeparatedTokenizer) into generic nsCCharSeparatedTokenizer class, too. r=NOT_REVIEWED_YET
+
+diff --git a/content/base/src/nsCrossSiteListenerProxy.cpp b/content/base/src/nsCrossSiteListenerProxy.cpp
+--- a/content/base/src/nsCrossSiteListenerProxy.cpp
++++ b/content/base/src/nsCrossSiteListenerProxy.cpp
+@@ -286,17 +286,17 @@ nsCrossSiteListenerProxy::CheckRequestAp
+   if (mIsPreflight) {
+     nsCAutoString headerVal;
+     // The "Access-Control-Allow-Methods" header contains a comma separated
+     // list of method names.
+     http->GetResponseHeader(NS_LITERAL_CSTRING("Access-Control-Allow-Methods"),
+                             headerVal);
+     PRBool foundMethod = mPreflightMethod.EqualsLiteral("GET") ||
+       mPreflightMethod.EqualsLiteral("POST");
+-    nsCCommaSeparatedTokenizer methodTokens(headerVal);
++    nsCCharSeparatedTokenizer methodTokens(headerVal, ',');
+     while(methodTokens.hasMoreTokens()) {
+       const nsDependentCSubstring& method = methodTokens.nextToken();
+       if (method.IsEmpty()) {
+         continue;
+       }
+       if (!IsValidHTTPToken(method)) {
+         return NS_ERROR_DOM_BAD_URI;
+       }
+@@ -305,17 +305,17 @@ nsCrossSiteListenerProxy::CheckRequestAp
+     NS_ENSURE_TRUE(foundMethod, NS_ERROR_DOM_BAD_URI);
+ 
+     // The "Access-Control-Allow-Headers" header contains a comma separated
+     // list of header names.
+     headerVal.Truncate();
+     http->GetResponseHeader(NS_LITERAL_CSTRING("Access-Control-Allow-Headers"),
+                             headerVal);
+     nsTArray<nsCString> headers;
+-    nsCCommaSeparatedTokenizer headerTokens(headerVal);
++    nsCCharSeparatedTokenizer headerTokens(headerVal, ',');
+     while(headerTokens.hasMoreTokens()) {
+       const nsDependentCSubstring& header = headerTokens.nextToken();
+       if (header.IsEmpty()) {
+         continue;
+       }
+       if (!IsValidHTTPToken(header)) {
+         return NS_ERROR_DOM_BAD_URI;
+       }
+diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp
+--- a/content/base/src/nsXMLHttpRequest.cpp
++++ b/content/base/src/nsXMLHttpRequest.cpp
+@@ -377,17 +377,17 @@ nsACProxyListener::AddResultToCache(nsIR
+     return;
+   }
+ 
+   // The "Access-Control-Allow-Methods" header contains a comma separated
+   // list of method names.
+   http->GetResponseHeader(NS_LITERAL_CSTRING("Access-Control-Allow-Methods"),
+                           headerVal);
+ 
+-  nsCCommaSeparatedTokenizer methods(headerVal);
++  nsCCharSeparatedTokenizer methods(headerVal, ',');
+   while(methods.hasMoreTokens()) {
+     const nsDependentCSubstring& method = methods.nextToken();
+     if (method.IsEmpty()) {
+       continue;
+     }
+     PRUint32 i;
+     for (i = 0; i < entry->mMethods.Length(); ++i) {
+       if (entry->mMethods[i].token.Equals(method)) {
+@@ -407,17 +407,17 @@ nsACProxyListener::AddResultToCache(nsIR
+     }
+   }
+ 
+   // The "Access-Control-Allow-Headers" header contains a comma separated
+   // list of method names.
+   http->GetResponseHeader(NS_LITERAL_CSTRING("Access-Control-Allow-Headers"),
+                           headerVal);
+ 
+-  nsCCommaSeparatedTokenizer headers(headerVal);
++  nsCCharSeparatedTokenizer headers(headerVal, ',');
+   while(headers.hasMoreTokens()) {
+     const nsDependentCSubstring& header = headers.nextToken();
+     if (header.IsEmpty()) {
+       continue;
+     }
+     PRUint32 i;
+     for (i = 0; i < entry->mHeaders.Length(); ++i) {
+       if (entry->mHeaders[i].token.Equals(header)) {
+diff --git a/security/manager/ssl/src/nsNSSIOLayer.cpp b/security/manager/ssl/src/nsNSSIOLayer.cpp
+--- a/security/manager/ssl/src/nsNSSIOLayer.cpp
++++ b/security/manager/ssl/src/nsNSSIOLayer.cpp
+@@ -2258,17 +2258,17 @@ void nsSSLIOLayerHelpers::setRenegoUnres
+   }
+ 
+   mRenegoUnrestrictedSites = new nsCStringHashSet();
+   if (!mRenegoUnrestrictedSites)
+     return;
+   
+   mRenegoUnrestrictedSites->Init(1);
+   
+-  nsCCommaSeparatedTokenizer toker(str);
++  nsCCharSeparatedTokenizer toker(str, ',');
+ 
+   while (toker.hasMoreTokens()) {
+     const nsCSubstring &host = toker.nextToken();
+     if (!host.IsEmpty()) {
+       mRenegoUnrestrictedSites->Put(host);
+     }
+   }
+ }
+diff --git a/xpcom/ds/nsCharSeparatedTokenizer.h b/xpcom/ds/nsCharSeparatedTokenizer.h
+--- a/xpcom/ds/nsCharSeparatedTokenizer.h
++++ b/xpcom/ds/nsCharSeparatedTokenizer.h
+@@ -160,17 +160,19 @@ private:
+                (aChar == ' ' || aChar == '\n' ||
+                 aChar == '\r'|| aChar == '\t');
+     }
+ };
+ 
+ class nsCCommaSeparatedTokenizer
+ {
+ public:
+-    nsCCommaSeparatedTokenizer(const nsCSubstring& aSource)
++    nsCCommaSeparatedTokenizer(const nsCSubstring& aSource,
++                               char aSeparatorChar)
++        : mSeparatorChar(aSeparatorChar)
+     {
+         aSource.BeginReading(mIter);
+         aSource.EndReading(mEnd);
+ 
+         while (mIter != mEnd && isWhitespace(*mIter)) {
+             ++mIter;
+         }
+     }
+@@ -185,43 +187,45 @@ public:
+ 
+     /**
+      * Returns the next token.
+      */
+     const nsDependentCSubstring nextToken()
+     {
+         nsCSubstring::const_char_iterator end = mIter, begin = mIter;
+ 
+-        // Search until we hit comma or end
+-        while (mIter != mEnd && *mIter != ',') {
+-          while (mIter != mEnd && !isWhitespace(*mIter) && *mIter != ',') {
++        // Search until we hit separator or end.
++        while (mIter != mEnd && *mIter != mSeparatorChar) {
++          while (mIter != mEnd &&
++                 !isWhitespace(*mIter) && *mIter != mSeparatorChar) {
+               ++mIter;
+           }
+           end = mIter;
+ 
+           while (mIter != mEnd && isWhitespace(*mIter)) {
+               ++mIter;
+           }
+         }
+         
+-        // Skip comma
++        // Skip separator (and any whitespace after it).
+         if (mIter != mEnd) {
+-            NS_ASSERTION(*mIter == ',', "Ended loop too soon");
++            NS_ASSERTION(*mIter == mSeparatorChar, "Ended loop too soon");
+             ++mIter;
+ 
+             while (mIter != mEnd && isWhitespace(*mIter)) {
+                 ++mIter;
+             }
+         }
+         
+         return Substring(begin, end);
+     }
+ 
+ private:
+     nsCSubstring::const_char_iterator mIter, mEnd;
++    PRUnichar mSeparatorChar;
+ 
+     PRBool isWhitespace(unsigned char aChar)
+     {
+         return aChar <= ' ' &&
+                (aChar == ' ' || aChar == '\n' ||
+                 aChar == '\r'|| aChar == '\t');
+     }
+ };