1 // Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "common/string_utils.h"
18 std::string GenerateUUID() {
22 uuid_unparse(uuid, tmp);
23 return std::string(tmp);
26 bool StartsWith(const std::string& str, const std::string& sub) {
27 if (sub.size() > str.size()) return false;
28 return std::equal(sub.begin(), sub.end(), str.begin());
31 bool EndsWith(const std::string& str, const std::string& sub) {
32 if (sub.size() > str.size()) return false;
33 return std::equal(sub.rbegin(), sub.rend(), str.rbegin());
36 std::string ReplaceAll(const std::string& replace,
37 const std::string& from, const std::string& to) {
38 std::string str = replace;
39 size_t pos = str.find(from);
40 while (pos != std::string::npos) {
41 str.replace(pos, from.length(), to);
42 pos = str.find(from, pos+to.length());
47 std::string GetCurrentMilliSeconds() {
48 std::ostringstream ss;
50 clock_gettime(CLOCK_REALTIME, &spec);
51 ss << spec.tv_sec << "." <<
52 std::setw(3) << std::setfill('0') << (round(spec.tv_nsec / 1.0e6));