Bug 500631 part 1 - Make the default isindex prompt use a localized string in the HTML5 parser. r=bnewman.
authorHenri Sivonen <hsivonen@iki.fi>
Wed, 17 Mar 2010 10:26:17 +0200
changeset 40916 4aa2109bb5c6bd6157a477859f516aa0bdf6296a
parent 40915 e648fd6a9dee8d7891f46fa79d4af64d75ead677
child 40917 7db9990e38719d5f5f8ade0dae9aabb8e3022e6b
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnewman
bugs500631
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 500631 part 1 - Make the default isindex prompt use a localized string in the HTML5 parser. r=bnewman.
parser/html/nsHtml5Portability.cpp
--- a/parser/html/nsHtml5Portability.cpp
+++ b/parser/html/nsHtml5Portability.cpp
@@ -35,16 +35,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "prtypes.h"
 #include "nsIAtom.h"
 #include "nsString.h"
 #include "jArray.h"
 #include "nsHtml5Portability.h"
+#include "nsContentUtils.h"
 
 nsIAtom*
 nsHtml5Portability::newLocalNameFromBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length, nsHtml5AtomTable* interner)
 {
   NS_ASSERTION(!offset, "The offset should always be zero here.");
   NS_ASSERTION(interner, "Didn't get an atom service.");
   return interner->GetAtom(nsDependentSubstring(buf, buf + length));
 }
@@ -177,22 +178,33 @@ nsHtml5Portability::literalEqualsString(
     return PR_FALSE;
   }
   return string->EqualsASCII(literal);
 }
 
 jArray<PRUnichar,PRInt32>
 nsHtml5Portability::isIndexPrompt()
 {
-  // XXX making this localizable is bug 500631
-  const char* literal = "This is a searchable index. Insert your search keywords here: ";
-  jArray<PRUnichar,PRInt32> arr = jArray<PRUnichar,PRInt32>(62);
-  for (PRInt32 i = 0; i < 62; ++i) {
-    arr[i] = literal[i];
+  nsXPIDLString prompt;
+  nsresult rv =
+      nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
+                                         "IsIndexPrompt", prompt);
+  PRUint32 len = prompt.Length();
+  if (NS_FAILED(rv) || !len) {
+    // jArray doesn't support dynamically-allocated zero-length arrays
+    // and this method has no way to signal an error. Let's return
+    // the REPLACEMENT CHARACTER to avoid crashing on null pointer.
+    jArray<PRUnichar,PRInt32> arr = jArray<PRUnichar,PRInt32>(1);
+    arr[0] = 0xFFFD;
+    return arr;
   }
+  jArray<PRUnichar,PRInt32> arr = jArray<PRUnichar,PRInt32>(len);
+  PRUnichar* arrAsPtr = arr;
+  const PRUnichar* strAsPtr = prompt.BeginReading();
+  memcpy(arrAsPtr, strAsPtr, len * sizeof(PRUnichar));
   return arr;
 }
 
 void
 nsHtml5Portability::initializeStatics()
 {
 }