[ACR][20/08/2013][Add]Enhance Double::ToString() andFloat::ToString() to set a specif...
authordarpan.ka <darpan.ka@samsung.com>
Fri, 23 Aug 2013 10:36:31 +0000 (19:36 +0900)
committerdarpan.ka <darpan.ka@samsung.com>
Wed, 11 Sep 2013 02:16:01 +0000 (11:16 +0900)
Change-Id: I1ac975c762b2f9dd1d1566b7e1f6763acb431f95
Signed-off-by: darpan.ka <darpan.ka@samsung.com>
src/base/FBaseDouble.cpp
src/base/FBaseFloat.cpp
src/base/FBase_LocalizedNumParser.cpp
src/base/inc/FBase_LocalizedNumParser.h

index 55c1bf2..2f7554b 100644 (file)
@@ -211,8 +211,7 @@ Double::ToString(void) const
 String
 Double::ToString(int precision) const
 {
-//Dummy implementation to resolve build break
-       return String(L"");
+       return Double::ToString(value, precision);
 }
 
 String
@@ -224,8 +223,7 @@ Double::ToString(double value)
 String
 Double::ToString(double value, int precision)
 {
-//Dummy implementation to resolve build break
-       return String(L"");
+       return _LocalizedNumParser::ToString(value, "", precision);
 }
 
 
index 7f24ae7..6ed2b0f 100644 (file)
@@ -205,8 +205,7 @@ Float::ToString(void) const
 String
 Float::ToString(int precision) const
 {
-//Dummy implementation to resolve build break
-       return String(L"");
+       return Float::ToString(value, precision);
 }
 
 String
@@ -218,8 +217,7 @@ Float::ToString(float value)
 String
 Float::ToString(float value, int precision)
 {
-//Dummy implementation to resolve build break
-       return String(L"");
+       return _LocalizedNumParser::ToString(value, "", precision);
 }
 
 
index 7d5b68d..3a66c0e 100644 (file)
 #include <FBaseSysLog.h>
 #include "FBase_LocalizedNumParser.h"
 
+#define CHECK_NAN_OR_INF_AND_RETURN(value)     \
+       if (std::isnan(value))                  \
+       {                                       \
+               return String(L"NaN");          \
+       }                                       \
+       if (std::isinf(value))                  \
+       {                                       \
+               return String(L"Infinity");     \
+       }
+
 namespace Tizen { namespace Base
 {
 
@@ -105,20 +115,11 @@ String
 _LocalizedNumParser::ToString(double value, const char* pLocale)
 {
        ClearLastResult();
-
-       if (std::isnan(value))
-       {
-               return String(L"NaN");
-       }
-
-       if (std::isinf(value))
-       {
-               return String(L"Infinity");
-       }
+       CHECK_NAN_OR_INF_AND_RETURN(value);
 
        _CLocaleWrapper clocale;
        result r = clocale.Construct(pLocale);
-       SysTryReturn(NID_BASE, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+       SysTryReturn(NID_BASE, r == E_SUCCESS, String(L""), r, "[%s] Propagating.", GetErrorMessage(r));
 
        wchar_t sValue[DBL_MAX_LENGTH + 1] = {0, };
        swprintf(sValue, sizeof(sValue) / sizeof(sValue[0]), L"%#lg", value);
@@ -127,23 +128,30 @@ _LocalizedNumParser::ToString(double value, const char* pLocale)
 }
 
 String
-_LocalizedNumParser::ToString(float value, const char* pLocale)
+_LocalizedNumParser::ToString(double value, const char* pLocale, int precision)
 {
        ClearLastResult();
+       CHECK_NAN_OR_INF_AND_RETURN(value);
 
-       if (std::isnan(value))
-       {
-               return String(L"NaN");
-       }
+       _CLocaleWrapper clocale;
+       result r = clocale.Construct(pLocale);
+       SysTryReturn(NID_BASE, r == E_SUCCESS, String(L""), r, "[%s] Propagating.", GetErrorMessage(r));
 
-       if (std::isinf(value))
-       {
-               return String(L"Infinity");
-       }
+       wchar_t sValue[DBL_MAX_LENGTH + 1] = {0, };
+       swprintf(sValue, sizeof(sValue) / sizeof(sValue[0]), L"%.*f", precision, value);
+
+       return String(sValue);
+}
+
+String
+_LocalizedNumParser::ToString(float value, const char* pLocale)
+{
+       ClearLastResult();
+       CHECK_NAN_OR_INF_AND_RETURN(value);
 
        _CLocaleWrapper clocale;
        result r = clocale.Construct(pLocale);
-       SysTryReturn(NID_BASE, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+       SysTryReturn(NID_BASE, r == E_SUCCESS, String(L""), r, "[%s] Propagating.", GetErrorMessage(r));
 
        wchar_t sValue[FLOAT_LENGTH_MAX + 1] = {0, };
        swprintf(sValue, sizeof(sValue) / sizeof(sValue[0]), L"%g", value);
@@ -151,4 +159,19 @@ _LocalizedNumParser::ToString(float value, const char* pLocale)
        return String(sValue);
 }
 
+String
+_LocalizedNumParser::ToString(float value, const char* pLocale, int precision)
+{
+       ClearLastResult();
+       CHECK_NAN_OR_INF_AND_RETURN(value);
+
+       _CLocaleWrapper clocale;
+       result r = clocale.Construct(pLocale);
+       SysTryReturn(NID_BASE, r == E_SUCCESS, String(L""), r, "[%s] Propagating.", GetErrorMessage(r));
+
+       wchar_t sValue[DBL_MAX_LENGTH + 1] = {0, };
+       swprintf(sValue, sizeof(sValue) / sizeof(sValue[0]), L"%.*f", precision, value);
+
+       return String(sValue);
+}
 }}  // Tizen::Base
index 9139bde..399010f 100644 (file)
@@ -95,13 +95,37 @@ public:
         * @remarks
         *                              - If the input value is Not-a-Number(NaN), the result is the string "NaN".
         *                              Furthermore, infinity produces the result "Infinity". @n
-        *                              6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
+        *                              6 digits are given for the precision of this method. Use Double::ToString(int precision) to set the specific precision.
         *                              - The behavior of this method is dependent on the specified locale setting.
         *                              - The specific error code can be accessed using the GetLastResult() method.
         */
        static String ToString(double value, const char* pLocale);
 
        /**
+        * Locale specifiable version of Double::ToString(int precision). @n
+        * This method is affected by the specified @c pLocale.
+        *
+        * @since 3.0
+        *
+        * @return                      A string containing a Unicode representation of the specified @c double value
+        * @param[in]   value           A @c double value to convert
+        * @param[in]   pLocale         A specific locale identifier. @n
+        *                                      The @c pLocale can have below values.
+        *                                      - "" : the system default locale
+        *                                      - "C" or "POSIX" : the POSIX locale
+        *                                      - "language[_territory][.codeset]" : an implementation-provided locale, e.g. "en_US.utf8", "fr_FR.utf8", etc.
+        * @param[in]   precision       Number of digits after a decimal separator
+        * @exception   E_SUCCESS       The method is successful.
+        * @exception   E_INVALID_ARG   The specified locale identifier is invalid.
+        * @remarks
+        *                              - If the input value is Not-a-Number(NaN), the result is the string "NaN".
+        *                              Furthermore, infinity produces the result "Infinity". @n
+        *                              - The behavior of this method is dependent on the specified locale setting.
+        *                              - The specific error code can be accessed using the GetLastResult() method.
+        */
+       static String ToString(double value, const char* pLocale, int precision);
+
+       /**
         * Locale specifiable version of Float::ToString(). @n
         * This method is affected by the specified @c pLocale.
         *
@@ -119,12 +143,36 @@ public:
         * @remarks
         *                              - If the input value is Not-a-Number(NaN), the result is the string "NaN".
         *                              Furthermore, infinity produces the result "Infinity". @n
-        *                              6 digits are given for the precision of this method. Use String::Format() to set the specific precision.
+        *                              6 digits are given for the precision of this method. Use Float::ToString(int precision) to set the specific precision.
         *                              - The behavior of this method is dependent on the specified locale setting.
         *                              - The specific error code can be accessed using the GetLastResult() method.
         */
        static String ToString(float value, const char* pLocale);
 
+       /**
+        * Locale specifiable version of Float::ToString(int precision). @n
+        * This method is affected by the specified @c pLocale.
+        *
+        * @since 3.0
+        *
+        * @return                      A string containing a Unicode representation of the specified @c float value
+        * @param[in]   value           A @c float value to convert
+        * @param[in]   pLocale         A specific locale identifier. @n
+        *                                      The @c pLocale can have below values.
+        *                                      - "" : the system default locale
+        *                                      - "C" or "POSIX" : the POSIX locale
+        *                                      - "language[_territory][.codeset]" : an implementation-provided locale, e.g. "en_US.utf8", "fr_FR.utf8", etc.
+        * @param[in]   precision       Number of digits after a decimal separator
+        * @exception   E_SUCCESS       The method is successful.
+        * @exception   E_INVALID_ARG   The specified locale identifier is invalid.
+        * @remarks
+        *                              - If the input value is Not-a-Number(NaN), the result is the string "NaN".
+        *                              Furthermore, infinity produces the result "Infinity". @n
+        *                              - The behavior of this method is dependent on the specified locale setting.
+        *                              - The specific error code can be accessed using the GetLastResult() method.
+        */
+       static String ToString(float value, const char* pLocale, int precision);
+
 private:
        //
        // This default constructor is intentionally declared as private because this class is not constructible.
@@ -163,4 +211,4 @@ private:
        static const int DBL_MAX_LENGTH = 17 + 308 + 3; // significant decimal digits + exponent + extra characters
 };
 }}  // Tizen::Base
-#endif  // _FBASE_INTERNAL_LOCALIZED_NUM_PARSER_H_
\ No newline at end of file
+#endif  // _FBASE_INTERNAL_LOCALIZED_NUM_PARSER_H_