[haiku-commits] r40527 - in haiku/trunk/src: kits/locale tools/locale

  • From: zooey@xxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 16 Feb 2011 11:53:46 +0100 (CET)

Author: zooey
Date: 2011-02-16 11:53:46 +0100 (Wed, 16 Feb 2011)
New Revision: 40527
Changeset: http://dev.haiku-os.org/changeset/40527
Ticket: http://dev.haiku-os.org/ticket/7226

Removed:
   haiku/trunk/src/tools/locale/HashMapCatalog.cpp
Modified:
   haiku/trunk/src/kits/locale/HashMapCatalog.cpp
   haiku/trunk/src/tools/locale/Jamfile
Log:
Second (and last) part of fixing #7226:
* fix most obvious problems in parseQuotedChars()
* drop separate HashMapCatalog in tools-folder, which isn't much 
  different from the original one (we now just use that one instead)


Modified: haiku/trunk/src/kits/locale/HashMapCatalog.cpp
===================================================================
--- haiku/trunk/src/kits/locale/HashMapCatalog.cpp      2011-02-16 10:13:12 UTC 
(rev 40526)
+++ haiku/trunk/src/kits/locale/HashMapCatalog.cpp      2011-02-16 10:53:46 UTC 
(rev 40527)
@@ -11,6 +11,9 @@
 #include <stdlib.h>
 
 
+namespace BPrivate {
+
+
 /*
  * This is the standard implementation of a localization catalog, using a hash
  * map. This class is abstract, you need to inherit it and provide methodes for
@@ -86,7 +89,8 @@
 }
 
 
-uint32 CatKey::HashFun(const char* s, int startValue) {
+uint32
+CatKey::HashFun(const char* s, int startValue) {
        unsigned long h = startValue;
        for ( ; *s; ++s)
                h = 5 * h + *s;
@@ -97,7 +101,7 @@
        return size_t(h);
 }
 
-// (end CatKey)
+
 // BHashMapCatalog
 
 
@@ -143,15 +147,17 @@
 }
 
 
-void
+static status_t
 parseQuotedChars(BString& stringToParse)
 {
        char* in = stringToParse.LockBuffer(0);
+       if (in == NULL)
+               return B_ERROR;
        char* out = in;
        int newLength = 0;
        bool quoted = false;
 
-       while (*in != 0 || quoted) {
+       while (*in != 0) {
                if (quoted) {
                        if (*in == 'n')
                                *out = '\n';
@@ -160,17 +166,19 @@
                        else if (*in == '"')
                                *out = '"';
                        else if (*in == 'x') {
+                               if (in[1] == '\0' || in[2] == '\0')
+                                       break;
                                // Parse the 2-digit hex integer that follows
                                char tmp[3];
-                               tmp[0] = *(in+1);
-                               tmp[1] = *(in+2);
+                               tmp[0] = in[1];
+                               tmp[1] = in[2];
                                tmp[2] = '\0';
                                unsigned int hexchar = strtoul(tmp, NULL, 16);
                                *out = hexchar;
                                // skip the number
                                in += 2;
                        } else {
-                               // dump quote from unknown quoting-sequence:
+                               // drop quote from unknown quoting-sequence:
                                *out = *in ;
                        }
                        quoted = false;
@@ -187,7 +195,9 @@
                in++;
        }
        *out = '\0';
-       stringToParse.UnlockBuffer();
+       stringToParse.UnlockBuffer(newLength);
+
+       return B_OK;
 }
 
 
@@ -197,12 +207,14 @@
 {
        BString stringCopy(string);
        BString translatedCopy(translated);
-       parseQuotedChars(stringCopy);
-       parseQuotedChars(translatedCopy);
+       status_t result = parseQuotedChars(stringCopy);
+       if (result != B_OK)
+               return result;
+       if ((result = parseQuotedChars(translatedCopy)) != B_OK)
+               return result;
        CatKey key(stringCopy.String(), context, comment);
-       fCatMap.Put(key, translatedCopy.String());
+       return fCatMap.Put(key, translatedCopy.String());
                // overwrite existing element
-       return B_OK;
 }
 
 
@@ -210,11 +222,12 @@
 BHashMapCatalog::SetString(int32 id, const char *translated)
 {
        BString translatedCopy(translated);
-       parseQuotedChars(translatedCopy);
+       status_t result = parseQuotedChars(translatedCopy);
+       if (result != B_OK)
+               return result;
        CatKey key(id);
-       fCatMap.Put(key, translatedCopy.String());
+       return fCatMap.Put(key, translatedCopy.String());
                // overwrite existing element
-       return B_OK;
 }
 
 
@@ -222,10 +235,11 @@
 BHashMapCatalog::SetString(const CatKey& key, const char *translated)
 {
        BString translatedCopy(translated);
-       parseQuotedChars(translatedCopy);
-       fCatMap.Put(key, translatedCopy.String());
+       status_t result = parseQuotedChars(translatedCopy);
+       if (result != B_OK)
+               return result;
+       return fCatMap.Put(key, translatedCopy.String());
                // overwrite existing element
-       return B_OK;
 }
 
 
@@ -260,3 +274,6 @@
 {
        fFingerprint = ComputeFingerprint();
 }
+
+
+}      // namespace BPrivate

Modified: haiku/trunk/src/tools/locale/Jamfile
===================================================================
--- haiku/trunk/src/tools/locale/Jamfile        2011-02-16 10:13:12 UTC (rev 
40526)
+++ haiku/trunk/src/tools/locale/Jamfile        2011-02-16 10:53:46 UTC (rev 
40527)
@@ -4,6 +4,7 @@
 UsePrivateHeaders locale ;
 UsePrivateHeaders shared ;
 
+SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits locale ] ;
 SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits tracker ] ;
 
 local localetools =


Other related posts:

  • » [haiku-commits] r40527 - in haiku/trunk/src: kits/locale tools/locale - zooey