[haiku-commits] r35503 - in haiku/trunk: headers/os/locale src/kits/locale src/tests/kits/locale

  • From: pulkomandy@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 17 Feb 2010 01:02:51 +0100 (CET)

Author: pulkomandy
Date: 2010-02-17 01:02:50 +0100 (Wed, 17 Feb 2010)
New Revision: 35503
Changeset: http://dev.haiku-os.org/changeset/35503/haiku

Added:
   haiku/trunk/headers/os/locale/TimeFormat.h
   haiku/trunk/src/kits/locale/TimeFormat.cpp
   haiku/trunk/src/tests/kits/locale/formatTest.cpp
Modified:
   haiku/trunk/headers/os/locale/Format.h
   haiku/trunk/headers/os/locale/NumberFormat.h
   haiku/trunk/src/kits/locale/FloatFormat.cpp
   haiku/trunk/src/kits/locale/Format.cpp
   haiku/trunk/src/kits/locale/IntegerFormat.cpp
   haiku/trunk/src/kits/locale/Jamfile
   haiku/trunk/src/kits/locale/LocaleRoster.cpp
   haiku/trunk/src/kits/locale/NumberFormat.cpp
   haiku/trunk/src/tests/kits/locale/Jamfile
Log:
-Added new TimeFormat API for formatting and localizing a time (uptime, copy 
duration, ...)
-Added a very simple test that shows the API is corrupting memory and ends up 
crashing
-Fixed build of other locale tests


Modified: haiku/trunk/headers/os/locale/Format.h
===================================================================
--- haiku/trunk/headers/os/locale/Format.h      2010-02-16 22:19:37 UTC (rev 
35502)
+++ haiku/trunk/headers/os/locale/Format.h      2010-02-17 00:02:50 UTC (rev 
35503)
@@ -39,7 +39,7 @@
 
                BFormat &operator=(const BFormat &other);
 
-               BFormat(BFormatImpl *impl);
+               BFormat();
 
        protected:
                BFormatImpl     *fImpl;

Modified: haiku/trunk/headers/os/locale/NumberFormat.h
===================================================================
--- haiku/trunk/headers/os/locale/NumberFormat.h        2010-02-16 22:19:37 UTC 
(rev 35502)
+++ haiku/trunk/headers/os/locale/NumberFormat.h        2010-02-17 00:02:50 UTC 
(rev 35503)
@@ -13,7 +13,7 @@
 
                BNumberFormat &operator=(const BNumberFormat &other);
 
-               BNumberFormat(BNumberFormatImpl *impl);
+               BNumberFormat();
 
        private:
                inline BNumberFormatImpl *NumberFormatImpl() const;

Added: haiku/trunk/headers/os/locale/TimeFormat.h
===================================================================
--- haiku/trunk/headers/os/locale/TimeFormat.h                          (rev 0)
+++ haiku/trunk/headers/os/locale/TimeFormat.h  2010-02-17 00:02:50 UTC (rev 
35503)
@@ -0,0 +1,25 @@
+/* 
+ * Copyright 2010, Haiku, Inc.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef _B_TIME_FORMAT_H_
+#define _B_TIME_FORMAT_H_
+
+
+#include <NumberFormat.h>
+#include <SupportDefs.h>
+
+
+class BString;
+
+
+class BTimeFormat : public BNumberFormat {
+       public:
+               status_t Format(int64 number, BString *buffer) const;
+
+               // TODO : version for char* buffer, size_t bufferSize
+               // TODO : parsing ?     
+};
+
+
+#endif

Modified: haiku/trunk/src/kits/locale/FloatFormat.cpp
===================================================================
--- haiku/trunk/src/kits/locale/FloatFormat.cpp 2010-02-16 22:19:37 UTC (rev 
35502)
+++ haiku/trunk/src/kits/locale/FloatFormat.cpp 2010-02-17 00:02:50 UTC (rev 
35503)
@@ -45,7 +45,7 @@
 
 // constructor
 BFloatFormat::BFloatFormat(BFloatFormatImpl *impl)
-       : BNumberFormat(impl),
+       : BNumberFormat(),
          BFloatFormatParameters(impl ? impl->DefaultFloatFormatParameters()
                                                                    : NULL)
 {

Modified: haiku/trunk/src/kits/locale/Format.cpp
===================================================================
--- haiku/trunk/src/kits/locale/Format.cpp      2010-02-16 22:19:37 UTC (rev 
35502)
+++ haiku/trunk/src/kits/locale/Format.cpp      2010-02-17 00:02:50 UTC (rev 
35503)
@@ -21,8 +21,7 @@
 }
 
 // constructor
-BFormat::BFormat(BFormatImpl *impl)
-       : fImpl(impl)
+BFormat::BFormat()
 {
 }
 

Modified: haiku/trunk/src/kits/locale/IntegerFormat.cpp
===================================================================
--- haiku/trunk/src/kits/locale/IntegerFormat.cpp       2010-02-16 22:19:37 UTC 
(rev 35502)
+++ haiku/trunk/src/kits/locale/IntegerFormat.cpp       2010-02-17 00:02:50 UTC 
(rev 35503)
@@ -45,7 +45,7 @@
 
 // constructor
 BIntegerFormat::BIntegerFormat(BIntegerFormatImpl *impl)
-       : BNumberFormat(impl),
+       : BNumberFormat(),
          BIntegerFormatParameters(impl ? impl->DefaultIntegerFormatParameters()
                                                                    : NULL)
 {

Modified: haiku/trunk/src/kits/locale/Jamfile
===================================================================
--- haiku/trunk/src/kits/locale/Jamfile 2010-02-16 22:19:37 UTC (rev 35502)
+++ haiku/trunk/src/kits/locale/Jamfile 2010-02-17 00:02:50 UTC (rev 35503)
@@ -31,6 +31,7 @@
          NumberFormatImpl.cpp
          NumberFormatParameters.cpp
          PropertyFile.cpp
+         TimeFormat.cpp
          UnicodeChar.cpp
        : be $(TARGET_LIBSTDC++) libicu-common.so libicu-i18n.so
        ;

Modified: haiku/trunk/src/kits/locale/LocaleRoster.cpp
===================================================================
--- haiku/trunk/src/kits/locale/LocaleRoster.cpp        2010-02-16 22:19:37 UTC 
(rev 35502)
+++ haiku/trunk/src/kits/locale/LocaleRoster.cpp        2010-02-17 00:02:50 UTC 
(rev 35503)
@@ -602,18 +602,15 @@
                        catalog = info->fInstantiateFunc(signature, lang, 
fingerprint);
                        if (catalog) {
                                info->fLoadedCatalogs.AddItem(catalog);
-#if 0
-                               // Chain-loading of catalogs has been disabled, 
as with the
-                               // current way of handling languages (there are 
no general
-                               // languages like 'English', but only 
specialized ones, like
-                               // 'English-american') it does not make sense...
-                               //
                                // Chain-load catalogs for languages that 
depend on
                                // other languages.
                                // The current implementation uses the filename 
in order to
                                // detect dependencies (parenthood) between 
languages (it
                                // traverses from "english-british-oxford" to 
"english-british"
                                // to "english"):
+                               // TODO :use ICU facilities instead, so we can 
handle more
+                               // complex things such as fr_FR@euro, or 
whatever, encodings
+                               // and so on.
                                int32 pos;
                                BString langName(lang);
                                BCatalogAddOn *currCatalog=catalog, 
*nextCatalog;
@@ -628,7 +625,6 @@
                                                currCatalog = nextCatalog;
                                        }
                                }
-#endif
                                return catalog;
                        }
                }

Modified: haiku/trunk/src/kits/locale/NumberFormat.cpp
===================================================================
--- haiku/trunk/src/kits/locale/NumberFormat.cpp        2010-02-16 22:19:37 UTC 
(rev 35502)
+++ haiku/trunk/src/kits/locale/NumberFormat.cpp        2010-02-17 00:02:50 UTC 
(rev 35503)
@@ -21,8 +21,8 @@
 }
 
 // constructor
-BNumberFormat::BNumberFormat(BNumberFormatImpl *impl)
-       : BFormat(impl)
+BNumberFormat::BNumberFormat()
+       : BFormat()
 {
 }
 

Added: haiku/trunk/src/kits/locale/TimeFormat.cpp
===================================================================
--- haiku/trunk/src/kits/locale/TimeFormat.cpp                          (rev 0)
+++ haiku/trunk/src/kits/locale/TimeFormat.cpp  2010-02-17 00:02:50 UTC (rev 
35503)
@@ -0,0 +1,37 @@
+/* 
+ * Copyright 2010, Adrien Destugues, pulkomandy@xxxxxxxxx
+ * Distributed under the terms of the MIT License.
+ */
+
+#include <TimeFormat.h>
+
+#include <unicode/format.h>
+#include <unicode/tmutfmt.h>
+#include <unicode/utypes.h>
+#include <ICUWrapper.h>
+
+status_t BTimeFormat::Format(int64 number, BString* buffer) const
+{
+       // create time unit amount instance - a combination of Number and time 
unit
+       UErrorCode status = U_ZERO_ERROR;
+       TimeUnitAmount* source = new TimeUnitAmount(number/1000000, 
TimeUnit::UTIMEUNIT_SECOND, status);
+       // create time unit format instance
+       TimeUnitFormat* format = new TimeUnitFormat(status);
+       // format a time unit amount
+       UnicodeString formatted;
+       Formattable formattable(source);
+       if (!U_SUCCESS(status)) {
+               delete source;
+               delete format;
+               return B_ERROR;
+       }
+
+       formatted = ((icu_4_2::Format*)format)->format(formattable, formatted, 
status);
+
+       BStringByteSink bbs(buffer);
+       formatted.toUTF8(bbs);
+
+       delete source;
+       delete format;
+       return B_OK;
+}

Modified: haiku/trunk/src/tests/kits/locale/Jamfile
===================================================================
--- haiku/trunk/src/tests/kits/locale/Jamfile   2010-02-16 22:19:37 UTC (rev 
35502)
+++ haiku/trunk/src/tests/kits/locale/Jamfile   2010-02-17 00:02:50 UTC (rev 
35503)
@@ -23,7 +23,7 @@
        # LocaleTest <sources> ;
        local sources = $(1) ;
        local name = $(sources[1]:B) ;
-       Application $(name) : $(sources) : be liblocale.so $(TARGET_LIBSUPC++) ;
+       Application $(name) : $(sources) : be liblocale.so $(TARGET_LIBSTDC++) 
$(TARGET_LIBSUPC++) ;
 }
 
 LocaleTest catalogSpeed.cpp ;
@@ -32,6 +32,7 @@
 LocaleTest collatorTest.cpp ;
 LocaleTest genericNumberFormatTest.cpp ;
 LocaleTest localeTest.cpp ;
+LocaleTest formatTest.cpp ;
 
 Application ICUTest : 
        ICUTest.cpp :

Added: haiku/trunk/src/tests/kits/locale/formatTest.cpp
===================================================================
--- haiku/trunk/src/tests/kits/locale/formatTest.cpp                            
(rev 0)
+++ haiku/trunk/src/tests/kits/locale/formatTest.cpp    2010-02-17 00:02:50 UTC 
(rev 35503)
@@ -0,0 +1,15 @@
+#include <iostream>
+
+#include <time.h>
+
+#include <String.h>
+#include <TimeFormat.h>
+
+int main() {
+       BTimeFormat timeFormatter;
+       BString str;
+
+       timeFormatter.Format(123456, &str);
+
+       std::cout << str.String();
+}


Other related posts: