Apply locale-independent logic
authorHyunbin Lee <hyunbin.lee@samsung.com>
Mon, 29 Apr 2013 02:42:49 +0000 (11:42 +0900)
committerGerrit Code Review <gerrit2@kim11>
Mon, 29 Apr 2013 02:42:49 +0000 (11:42 +0900)
inc/FIoRegistry.h
src/io/FIoRegistry.cpp
src/io/FIo_RegistryImpl.cpp
src/io/inc/FIo_RegistryImpl.h

index 6dba5f3..7387c6c 100644 (file)
@@ -467,6 +467,8 @@ public:
        *                                                                               synchronization.
        * @exception    E_SECTION_NOT_FOUND             The specified @c sectionName is not found within the registry.
        * @exception    E_KEY_ALREADY_EXIST             The specified @c entryName already exists in this section.
+       * @remarks              This method converts the specified double type @c value to string value using "%lg" format specifier. @n
+       *                               Also, it does not depend on system locale.
        */
        result AddValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, double value);
 
@@ -488,6 +490,8 @@ public:
        *                                                                               synchronization.
        * @exception    E_SECTION_NOT_FOUND             The specified @c sectionName is not found within the registry.
        * @exception    E_KEY_ALREADY_EXIST             The specified @c entryName already exists in this section.
+       * @remarks              This method converts the specified float type @c value to string value using "%g" format specifier. @n
+       *                               Also, it does not depend on system locale.
        */
        result AddValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, float value);
 
@@ -600,6 +604,7 @@ public:
        * @exception    E_KEY_NOT_FOUND                 The specified @c entryName is not found within the registry.
        * @exception    E_PARSING_FAILED                The method has failed to parse the encoded entry value string, or the value is retrieved by using an incorrect data type.
        * @exception    E_DATA_NOT_FOUND                The name-value pair has no value assigned (if the value is retrieved using the REGTYPE_STRING type, an empty string is returned even if no value is assigned).
+       * @remarks              This method does not depend on system locale.
        */
        result GetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, double& retVal) const;
 
@@ -623,6 +628,7 @@ public:
        * @exception    E_KEY_NOT_FOUND                 The specified @c entryName is not found within the registry.
        * @exception    E_PARSING_FAILED                The method has failed to parse the encoded entry value string, or the value is retrieved by using an incorrect data type.
        * @exception    E_DATA_NOT_FOUND                The name-value pair has no value assigned (if the value is retrieved using the REGTYPE_STRING type, an empty string is returned even if no value is assigned).
+       * @remarks              This method does not depend on system locale.
        */
        result GetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, float& retVal) const;
 
@@ -748,6 +754,8 @@ public:
        * @remarks              This method will not add a name-value pair as an entry of a specific section
        *               if no entry with the specified name exists.
        *                               In such a case, it returns E_KEY_NOT_FOUND. Use AddValue() to insert a new entry.
+       * @remarks              This method converts the specified double type @c newValue to string value using "%lg" format specifier. @n
+       *                               Also, it does not depend on system locale.
        * @see                  AddValue()
        */
        result SetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, double newValue);
@@ -773,6 +781,8 @@ public:
        * @remarks              This method will not add a name-value pair as an entry of a specific section
        *               if no entry with the specified name exists.
        *                               In such a case, it returns E_KEY_NOT_FOUND. Use AddValue() to insert a new entry.
+       * @remarks              This method converts the specified float type @c newValue to string value using "%g" format specifier. @n
+       *                               Also, it does not depend on system locale.
        * @see                  AddValue()
        */
        result SetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, float newValue);
index ab817fd..9aaf1fc 100644 (file)
@@ -187,69 +187,69 @@ Registry::GetAllEntryNamesN(const String& sectionName) const
 }
 
 result
-Registry::AddValue(const String& sectionName, const String& entryName, int value)
+Registry::AddValue(const String& sectionName, const String& entryName, int entryValue)
 {
        SysAssertf(__pRegistryImpl != null, "Not yet constructed. Construct() should be called before use.\n");
        SysTryReturnResult(NID_IO, sectionName.GetLength() > 0, E_INVALID_ARG, "sectionName.GetLength() <= 0");
        SysTryReturnResult(NID_IO, entryName.GetLength() > 0, E_INVALID_ARG, "entryName.GetLength() <= 0");
 
-       return __pRegistryImpl->AddValue(sectionName, entryName, Integer::ToString(value));
+       return __pRegistryImpl->AddValue(sectionName, entryName, Integer::ToString(entryValue));
 }
 
 result
-Registry::AddValue(const String& sectionName, const String& entryName, double value)
+Registry::AddValue(const String& sectionName, const String& entryName, double entryValue)
 {
        SysAssertf(__pRegistryImpl != null, "Not yet constructed. Construct() should be called before use.\n");
        SysTryReturnResult(NID_IO, sectionName.GetLength() > 0, E_INVALID_ARG, "sectionName.GetLength() <= 0");
        SysTryReturnResult(NID_IO, entryName.GetLength() > 0, E_INVALID_ARG, "entryName.GetLength() <= 0");
 
-       return __pRegistryImpl->AddValue(sectionName, entryName, Double::ToString(value));
+       return __pRegistryImpl->AddValue(sectionName, entryName, entryValue);
 }
 
 result
-Registry::AddValue(const String& sectionName, const String& entryName, float value)
+Registry::AddValue(const String& sectionName, const String& entryName, float entryValue)
 {
        SysAssertf(__pRegistryImpl != null, "Not yet constructed. Construct() should be called before use.\n");
        SysTryReturnResult(NID_IO, sectionName.GetLength() > 0, E_INVALID_ARG, "sectionName.GetLength() <= 0");
        SysTryReturnResult(NID_IO, entryName.GetLength() > 0, E_INVALID_ARG, "entryName.GetLength() <= 0");
 
-       return __pRegistryImpl->AddValue(sectionName, entryName, Float::ToString(value));
+       return __pRegistryImpl->AddValue(sectionName, entryName, entryValue);
 }
 
 result
-Registry::AddValue(const String& sectionName, const String& entryName, const String& value)
+Registry::AddValue(const String& sectionName, const String& entryName, const String& entryValue)
 {
        SysAssertf(__pRegistryImpl != null, "Not yet constructed. Construct() should be called before use.\n");
        SysTryReturnResult(NID_IO, sectionName.GetLength() > 0, E_INVALID_ARG, "sectionName.GetLength() <= 0");
        SysTryReturnResult(NID_IO, entryName.GetLength() > 0, E_INVALID_ARG, "entryName.GetLength() <= 0");
 
-       return __pRegistryImpl->AddValue(sectionName, entryName, value);
+       return __pRegistryImpl->AddValue(sectionName, entryName, entryValue);
 }
 
 result
-Registry::AddValue(const String& sectionName, const String& entryName, const UuId& value)
+Registry::AddValue(const String& sectionName, const String& entryName, const UuId& entryValue)
 {
        SysAssertf(__pRegistryImpl != null, "Not yet constructed. Construct() should be called before use.\n");
        SysTryReturnResult(NID_IO, sectionName.GetLength() > 0, E_INVALID_ARG, "sectionName.GetLength() <= 0");
        SysTryReturnResult(NID_IO, entryName.GetLength() > 0, E_INVALID_ARG, "entryName.GetLength() <= 0");
 
-       return __pRegistryImpl->AddValue(sectionName, entryName, value.ToString());
+       return __pRegistryImpl->AddValue(sectionName, entryName, entryValue.ToString());
 }
 
 result
-Registry::AddValue(const String& sectionName, const String& entryName, const ByteBuffer& value)
+Registry::AddValue(const String& sectionName, const String& entryName, const ByteBuffer& entryValue)
 {
        SysAssertf(__pRegistryImpl != null, "Not yet constructed. Construct() should be called before use.\n");
        SysTryReturnResult(NID_IO, sectionName.GetLength() > 0, E_INVALID_ARG, "sectionName.GetLength() <= 0");
        SysTryReturnResult(NID_IO, entryName.GetLength() > 0, E_INVALID_ARG, "entryName.GetLength() <= 0");
 
-       int size = value.GetLimit();
+       int size = entryValue.GetLimit();
        SysTryReturnResult(NID_IO, size > 0, E_INVALID_ARG, "invalid buffer length");
 
        String strValEncoded;
        String strVal;
        result r = E_SUCCESS;
-       byte* pValue = const_cast< byte* >(value.GetPointer());
+       byte* pValue = const_cast< byte* >(entryValue.GetPointer());
        SysAssert(pValue);
 
        for (int i = 0; i < size; i++)
@@ -301,20 +301,7 @@ Registry::GetValue(const String& sectionName, const String& entryName, double& r
        SysTryReturnResult(NID_IO, sectionName.GetLength() > 0, E_INVALID_ARG, "sectionName.GetLength() <= 0");
        SysTryReturnResult(NID_IO, entryName.GetLength() > 0, E_INVALID_ARG, "entryName.GetLength() <= 0");
 
-       result r = E_SUCCESS;
-       String valStr;
-
-       r = __pRegistryImpl->GetValue(sectionName, entryName, valStr);
-       if (!IsFailed(r))
-       {
-               r = Double::Parse(valStr, retVal);
-               if (IsFailed(r))
-               {
-                       r = E_PARSING_FAILED;
-               }
-       }
-
-       return r;
+       return __pRegistryImpl->GetValue(sectionName, entryName, retVal);
 }
 
 result
@@ -324,20 +311,7 @@ Registry::GetValue(const String& sectionName, const String& entryName, float& re
        SysTryReturnResult(NID_IO, sectionName.GetLength() > 0, E_INVALID_ARG, "sectionName.GetLength() <= 0");
        SysTryReturnResult(NID_IO, entryName.GetLength() > 0, E_INVALID_ARG, "entryName.GetLength() <= 0");
 
-       result r = E_SUCCESS;
-       String valStr;
-
-       r = __pRegistryImpl->GetValue(sectionName, entryName, valStr);
-       if (!IsFailed(r))
-       {
-               r = Float::Parse(valStr, retVal);
-               if (IsFailed(r))
-               {
-                       r = E_PARSING_FAILED;
-               }
-       }
-
-       return r;
+       return __pRegistryImpl->GetValue(sectionName, entryName, retVal);
 }
 
 result
@@ -446,7 +420,7 @@ Registry::SetValue(const String& sectionName, const String& entryName, double ne
        SysTryReturnResult(NID_IO, sectionName.GetLength() > 0, E_INVALID_ARG, "sectionName.GetLength() <= 0");
        SysTryReturnResult(NID_IO, entryName.GetLength() > 0, E_INVALID_ARG, "entryName.GetLength() <= 0");
 
-       return __pRegistryImpl->SetValue(sectionName, entryName, Double::ToString(newValue));
+       return __pRegistryImpl->SetValue(sectionName, entryName, newValue);
 }
 
 result
@@ -456,7 +430,7 @@ Registry::SetValue(const String& sectionName, const String& entryName, float new
        SysTryReturnResult(NID_IO, sectionName.GetLength() > 0, E_INVALID_ARG, "sectionName.GetLength() <= 0");
        SysTryReturnResult(NID_IO, entryName.GetLength() > 0, E_INVALID_ARG, "entryName.GetLength() <= 0");
 
-       return __pRegistryImpl->SetValue(sectionName, entryName, Float::ToString(newValue));
+       return __pRegistryImpl->SetValue(sectionName, entryName, newValue);
 }
 
 result
index 50c9590..47e4881 100644 (file)
@@ -23,6 +23,9 @@
 #include <unistd.h>
 #include <new>
 #include <unique_ptr.h>
+#include <locale.h>
+#include <string.h>
+#include <errno.h>
 
 #include <FBaseInteger.h>
 #include <FBaseDouble.h>
@@ -56,12 +59,17 @@ static const int _MAX_REG_OPENMODE_LENGTH = 2;
 
 _RegistryImpl::_RegistryImpl(void)
        : __pRegistryCore(null)
+       , __loc((locale_t)0)
 {
 }
 
 _RegistryImpl::~_RegistryImpl(void)
 {
        delete __pRegistryCore;
+       if (__loc != (locale_t)0)
+       {
+               freelocale(__loc);
+       }
 }
 
 bool
@@ -133,6 +141,13 @@ _RegistryImpl::Construct(const String& regPath, const char* pOpenMode, const Byt
                __pRegistryCore = pSecureRegistry.release();
        }
 
+       __loc = newlocale(LC_ALL_MASK, "C", (locale_t)0);
+       if (__loc == (locale_t)0)
+       {
+               SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to create locale object. errno: %d (%s)",
+                               errno, strerror(errno));
+       }
+
        return r;
 }
 
@@ -194,24 +209,96 @@ _RegistryImpl::GetAllEntryNamesN(const String& sectionName) const
 }
 
 result
-_RegistryImpl::GetValue(const String& sectionName, const String& entryName, String& valStr)
+_RegistryImpl::GetValue(const String& sectionName, const String& entryName, float& entryValue)
+{
+       String value;
+       uselocale(__loc);
+       result r = GetValue(sectionName, entryName, value);
+       if (!IsFailed(r))
+       {
+               r = Float::Parse(value, entryValue);
+               if (IsFailed(r))
+               {
+                       r = E_PARSING_FAILED;
+               }
+       }
+       uselocale(LC_GLOBAL_LOCALE);
+       return r;
+}
+
+result
+_RegistryImpl::GetValue(const String& sectionName, const String& entryName, double& entryValue)
+{
+       String value;
+       uselocale(__loc);
+       result r = GetValue(sectionName, entryName, value);
+       if (!IsFailed(r))
+       {
+               r = Double::Parse(value, entryValue);
+               if (IsFailed(r))
+               {
+                       r = E_PARSING_FAILED;
+               }
+       }
+       uselocale(LC_GLOBAL_LOCALE);
+       return r;
+}
+
+result
+_RegistryImpl::GetValue(const String& sectionName, const String& entryName, String& entryValue)
 {
        SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
-       return __pRegistryCore->GetValue(sectionName, entryName, valStr);
+       return __pRegistryCore->GetValue(sectionName, entryName, entryValue);
 }
 
 result
-_RegistryImpl::AddValue(const String& sectionName, const String& entryName, const String& valStr)
+_RegistryImpl::AddValue(const String& sectionName, const String& entryName, float entryValue)
+{
+       uselocale(__loc);
+       result r = AddValue(sectionName, entryName, Float::ToString(entryValue));
+       uselocale(LC_GLOBAL_LOCALE);
+       return r;
+}
+
+result
+_RegistryImpl::AddValue(const String& sectionName, const String& entryName, double entryValue)
+{
+       uselocale(__loc);
+       result r = AddValue(sectionName, entryName, Double::ToString(entryValue));
+       uselocale(LC_GLOBAL_LOCALE);
+       return r;
+}
+
+result
+_RegistryImpl::AddValue(const String& sectionName, const String& entryName, const String& entryValue)
 {
        SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
-       return __pRegistryCore->AddValue(sectionName, entryName, valStr);
+       return __pRegistryCore->AddValue(sectionName, entryName, entryValue);
 }
 
 result
-_RegistryImpl::SetValue(const String& sectionName, const String& entryName, const String& valStr)
+_RegistryImpl::SetValue(const String& sectionName, const String& entryName, float entryValue)
+{
+       uselocale(__loc);
+       result r = SetValue(sectionName, entryName, Float::ToString(entryValue));
+       uselocale(LC_GLOBAL_LOCALE);
+       return r;
+}
+
+result
+_RegistryImpl::SetValue(const String& sectionName, const String& entryName, double entryValue)
+{
+       uselocale(__loc);
+       result r = SetValue(sectionName, entryName, Double::ToString(entryValue));
+       uselocale(LC_GLOBAL_LOCALE);
+       return r;
+}
+
+result
+_RegistryImpl::SetValue(const String& sectionName, const String& entryName, const String& entryValue)
 {
        SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
-       return __pRegistryCore->SetValue(sectionName, entryName, valStr);
+       return __pRegistryCore->SetValue(sectionName, entryName, entryValue);
 }
 
 result
@@ -295,7 +382,16 @@ void
 _RegistryImpl::GetEntryValue(int sectionIndex, int entryIndex, _RegValueType type, void* pValue, int* pSize)
 {
        SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
-       __pRegistryCore->GetEntryValue(sectionIndex, entryIndex, type, pValue, pSize);
+       if (type == REG_VALUE_TYPE_REAL)
+       {
+               uselocale(__loc);
+               __pRegistryCore->GetEntryValue(sectionIndex, entryIndex, type, pValue, pSize);
+               uselocale(LC_GLOBAL_LOCALE);
+       }
+       else
+       {
+               __pRegistryCore->GetEntryValue(sectionIndex, entryIndex, type, pValue, pSize);
+       }
 }
 
 String
index 98db3fc..762ea41 100644 (file)
@@ -28,6 +28,7 @@
 #include <FOspConfig.h>
 #include <FBaseObject.h>
 #include <FIoFileLock.h>
+#include <locale.h>
 
 namespace Tizen {namespace Base
 {
@@ -106,11 +107,23 @@ public:
 
        result GetEntryList(const Tizen::Base::String& sectionName, Tizen::Base::Collection::HashMap& retMap);
 
-       result GetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, Tizen::Base::String& valStr);
+       result GetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, float& entryValue);
 
-       result AddValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, const Tizen::Base::String& valStr);
+       result GetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, double& entryValue);
 
-       result SetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, const Tizen::Base::String& valStr);
+       result GetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, Tizen::Base::String& entryValue);
+
+       result AddValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, float entryValue);
+
+       result AddValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, double entryValue);
+
+       result AddValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, const Tizen::Base::String& entryValue);
+
+       result SetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, float entryValue);
+
+       result SetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, double entryValue);
+
+       result SetValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName, const Tizen::Base::String& entryValue);
 
        result RemoveValue(const Tizen::Base::String& sectionName, const Tizen::Base::String& entryName);
 
@@ -155,10 +168,12 @@ private:
 
        static bool ConvertRegistryOpenMode(long legacyMode, char* pOpenMode);
 
-    static result CheckOpenMode(const Tizen::Base::String& openMode);
+       static result CheckOpenMode(const Tizen::Base::String& openMode);
 
        _RegistryCore* __pRegistryCore;
 
+       locale_t __loc;
+
 }; // _RegistryImpl
 
 }} // Tizen::Io