From a9617824d29ad8e3d26df7739e764e79844b9697 Mon Sep 17 00:00:00 2001 From: WonYoung Choi Date: Mon, 20 Apr 2015 23:22:23 +0900 Subject: [PATCH] Add string utils to common library Change-Id: I0920db5aebf42255f6ed5ba96cf2a64b5604e9d9 --- packaging/wrt.spec | 1 + src/common/CMakeLists.txt | 10 +++++++++- src/common/string_utils.cc | 33 +++++++++++++++++++++++++++++++++ src/common/string_utils.h | 20 ++++++++++++++++++++ src/runtime/CMakeLists.txt | 1 + 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/common/string_utils.cc create mode 100644 src/common/string_utils.h diff --git a/packaging/wrt.spec b/packaging/wrt.spec index a709ff7..0639cb7 100755 --- a/packaging/wrt.spec +++ b/packaging/wrt.spec @@ -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) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index f7b7886..633db26 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -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 index 0000000..25218ff --- /dev/null +++ b/src/common/string_utils.cc @@ -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 +#include +#include + +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 index 0000000..4b42caf --- /dev/null +++ b/src/common/string_utils.h @@ -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 + +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_ diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt index 43beb9e..e8f75ba 100755 --- a/src/runtime/CMakeLists.txt +++ b/src/runtime/CMakeLists.txt @@ -11,6 +11,7 @@ IF(WAYLAND_SUPPORT) ENDIF(WAYLAND_SUPPORT) PKG_CHECK_MODULES(TARGET_RUNTIME_DEPS + uuid appsvc bundle dlog -- 2.7.4