summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Dolzhenko <d.dolzhenko@samsung.com>2017-06-14 14:46:55 +0300
committerDenis Dolzhenko <d.dolzhenko@samsung.com>2017-06-14 14:46:55 +0300
commit02b0fab5d555e654bac1b483309a048e2204ead4 (patch)
treeaf3e4d22c577d7535022031b10a82779a1caca08
parent2638bdb7b3aa1249dff711edaa793ce11334c3bc (diff)
downloadidle-clock-digital-02b0fab5d555e654bac1b483309a048e2204ead4.tar.gz
idle-clock-digital-02b0fab5d555e654bac1b483309a048e2204ead4.tar.bz2
idle-clock-digital-02b0fab5d555e654bac1b483309a048e2204ead4.zip
TizenRefApp-8686 Implement I18nString class
Change-Id: I60300c355964c66ec457c085faf0770d11039bf4 Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
-rw-r--r--src/Common/inc/I18nString.h57
-rw-r--r--src/Common/src/I18nString.cpp137
2 files changed, 194 insertions, 0 deletions
diff --git a/src/Common/inc/I18nString.h b/src/Common/inc/I18nString.h
new file mode 100644
index 0000000..89f61b9
--- /dev/null
+++ b/src/Common/inc/I18nString.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef I18nString_h_
+#define I18nString_h_
+
+#include <string>
+#include <utils_i18n.h>
+
+namespace IdleClock {
+
+ class I18nString :
+ private std::basic_string<i18n_uchar> {
+
+ public:
+ I18nString();
+ I18nString(const I18nString &that);
+ I18nString(I18nString &&that);
+ I18nString(size_t count);
+ I18nString(const char *str);
+ I18nString(const i18n_uchar *uStr);
+ I18nString(const std::string &str);
+
+ I18nString &operator=(const I18nString &that);
+ i18n_uchar *getUStr() const;
+ operator i18n_uchar *() const;
+ int getLen() const;
+ std::string toStr() const;
+ size_t getCapacity() const;
+ void clear();
+ bool isEmpty() const;
+
+ private:
+ using Impl = std::basic_string<i18n_uchar>;
+
+ private:
+ void copyStr(const I18nString &that);
+ void copyStr(const i18n_uchar *uStr);
+ void copyStr(const std::string &str);
+ void copyStr(const char *str);
+ };
+}
+
+#endif /* I18nString_h_ */
diff --git a/src/Common/src/I18nString.cpp b/src/Common/src/I18nString.cpp
new file mode 100644
index 0000000..8ce901e
--- /dev/null
+++ b/src/Common/src/I18nString.cpp
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "I18nString.h"
+#include <string.h>
+
+using namespace IdleClock;
+
+I18nString::I18nString()
+{
+}
+
+I18nString::I18nString(const I18nString &that)
+{
+ copyStr(that);
+}
+
+I18nString::I18nString(I18nString &&that)
+ : Impl(std::move(that))
+{
+}
+
+I18nString::I18nString(size_t count)
+ : Impl(count, 0)
+{
+}
+
+I18nString::I18nString(const char *str)
+{
+ copyStr(str);
+}
+
+I18nString::I18nString(const i18n_uchar *uStr)
+{
+ copyStr(uStr);
+}
+
+I18nString::I18nString(const std::string &str)
+ : I18nString(str.c_str())
+{
+}
+
+i18n_uchar *I18nString::getUStr() const
+{
+ return (i18n_uchar*)&front();
+}
+
+I18nString::operator i18n_uchar *() const
+{
+ return getUStr();
+}
+
+I18nString &I18nString::operator=(const I18nString &that)
+{
+ copyStr(that);
+ return *this;
+}
+
+int I18nString::getLen() const
+{
+ return data() ? i18n_ustring_get_length(data()) : 0;
+}
+
+std::string I18nString::toStr() const
+{
+ std::string res;
+ int len = length() * sizeof(i18n_uchar);
+ if (len >= 0) {
+ res.resize(len);
+ i18n_ustring_copy_au(&res.front(), data());
+ }
+ return res;
+}
+
+size_t I18nString::getCapacity() const
+{
+ return capacity();
+}
+
+void I18nString::clear()
+{
+ std::basic_string<i18n_uchar>::clear();
+}
+
+bool I18nString::isEmpty() const
+{
+ return Impl::empty();
+}
+
+void I18nString::copyStr(const I18nString &that)
+{
+ copyStr(that.getUStr());
+}
+
+void I18nString::copyStr(const i18n_uchar *uStr)
+{
+ clear();
+ if (uStr) {
+ int len = uStr ? i18n_ustring_get_length(uStr) : 0;
+ resize(len);
+ i18n_ustring_mem_copy(getUStr(), uStr, len);
+ }
+}
+
+void I18nString::copyStr(const std::string &str)
+{
+ clear();
+ if (!str.empty()) {
+ size_t len = str.length();
+ resize(len);
+ i18n_ustring_copy_ua_n(getUStr(), str.c_str(), len);
+ }
+}
+
+void I18nString::copyStr(const char *str)
+{
+ clear();
+ if (str) {
+ size_t len = strlen(str);
+ resize(len);
+ i18n_ustring_copy_ua_n(getUStr(), str, len);
+ }
+}
+