Add string utils to common library
authorWonYoung Choi <wy80.choi@samsung.com>
Mon, 20 Apr 2015 14:22:23 +0000 (23:22 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Mon, 20 Apr 2015 14:22:23 +0000 (23:22 +0900)
Change-Id: I0920db5aebf42255f6ed5ba96cf2a64b5604e9d9

packaging/wrt.spec
src/common/CMakeLists.txt
src/common/string_utils.cc [new file with mode: 0644]
src/common/string_utils.h [new file with mode: 0644]
src/runtime/CMakeLists.txt

index a709ff7..0639cb7 100755 (executable)
@@ -24,6 +24,7 @@ BuildRequires: pkgconfig(efl-assist)
 BuildRequires: pkgconfig(deviced)
 BuildRequires: pkgconfig(capi-system-runtime-info)
 BuildRequires: pkgconfig(cert-svc)
+BuildRequires: pkgconfig(uuid)
 BuildRequires: boost-devel
 %if %{with x}
 BuildRequires: pkgconfig(ecore-x)
index f7b7886..633db26 100644 (file)
@@ -2,17 +2,25 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+PKG_CHECK_MODULES(TARGET_COMMON_STATIC_DEPS
+  uuid
+  dlog
+  REQUIRED
+)
+
 SET(TARGET_COMMON_STATIC_INCS
   ${BASE_SRCDIR}
+  ${TARGET_COMMON_STATIC_DEPS_INCLUDE_DIRS}
 )
 
 SET(TARGET_COMMON_STATIC_SRCS
   ${BASE_SRCDIR}/common/file_utils.cc
   ${BASE_SRCDIR}/common/message_types.cc
+  ${BASE_SRCDIR}/common/string_utils.cc
   ${BASE_SRCDIR}/common/command_line.cc
 )
 
 INCLUDE_DIRECTORIES(${TARGET_COMMON_STATIC_INCS})
 ADD_LIBRARY(${TARGET_COMMON_STATIC} STATIC
   ${TARGET_COMMON_STATIC_SRCS}
-)
\ No newline at end of file
+)
diff --git a/src/common/string_utils.cc b/src/common/string_utils.cc
new file mode 100644 (file)
index 0000000..25218ff
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "common/string_utils.h"
+
+#include <uuid/uuid.h>
+#include <string>
+#include <algorithm>
+
+namespace wrt {
+namespace utils {
+
+std::string GenerateUUID() {
+  char tmp[37];
+  uuid_t uuid;
+  uuid_generate(uuid);
+  uuid_unparse(uuid, tmp);
+  return std::string(tmp);
+}
+
+bool StartsWith(const std::string& str, const std::string& sub) {
+  if (sub.size() > str.size()) return false;
+  return std::equal(sub.begin(), sub.end(), str.begin());
+}
+
+bool EndsWith(const std::string& str, const std::string& sub) {
+  if (sub.size() > str.size()) return false;
+  return std::equal(sub.rbegin(), sub.rend(), str.rbegin());
+}
+
+}  // namespace utils
+}  // namespace wrt
diff --git a/src/common/string_utils.h b/src/common/string_utils.h
new file mode 100644 (file)
index 0000000..4b42caf
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WRT_COMMON_STRING_UTILS_H_
+#define WRT_COMMON_STRING_UTILS_H_
+
+#include <string>
+
+namespace wrt {
+namespace utils {
+
+std::string GenerateUUID();
+bool StartsWith(const std::string& str, const std::string& sub);
+bool EndsWith(const std::string& str, const std::string& sub);
+
+}  // namespace utils
+}  // namespace wrt
+
+#endif  // WRT_COMMON_STRING_UTILS_H_
index 43beb9e..e8f75ba 100755 (executable)
@@ -11,6 +11,7 @@ IF(WAYLAND_SUPPORT)
 ENDIF(WAYLAND_SUPPORT)
 
 PKG_CHECK_MODULES(TARGET_RUNTIME_DEPS
+  uuid
   appsvc
   bundle
   dlog