First way to publish
This commit is contained in:
parent
0be7fe9bff
commit
647b8f3072
17 changed files with 240 additions and 21 deletions
|
@ -1,6 +1,7 @@
|
|||
set(SOURCES
|
||||
logger.cpp
|
||||
loggable.cpp
|
||||
utils.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
|
@ -8,6 +9,7 @@ set(HEADERS
|
|||
loggable.h
|
||||
definitions.h
|
||||
result.h
|
||||
utils.h
|
||||
)
|
||||
|
||||
target_sources(${EXEC_NAME} PRIVATE ${SOURCES})
|
32
shared/utils.cpp
Normal file
32
shared/utils.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include "utils.h"
|
||||
|
||||
std::string Shared::getISOTimestamp() {
|
||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> time = std::chrono::floor<std::chrono::seconds>(now);
|
||||
|
||||
return std::format("{:%FT%TZ}", time);
|
||||
}
|
||||
|
||||
std::string Shared::getUUID() {
|
||||
uuid_t uuid;
|
||||
uuid_generate_random(uuid);
|
||||
char uuid_str[37];
|
||||
uuid_unparse_lower(uuid, uuid_str);
|
||||
|
||||
return std::string(uuid_str);
|
||||
}
|
||||
|
||||
Shared::Strings Shared::split(const std::string& string, const std::string& delimiter) {
|
||||
Strings result;
|
||||
|
||||
std::size_t last = 0;
|
||||
std::size_t next = string.find(delimiter, last);
|
||||
while (next != std::string::npos) {
|
||||
result.emplace_back(string.substr(last, next - last));
|
||||
last = next + 1;
|
||||
next = string.find(delimiter, last);
|
||||
}
|
||||
result.emplace_back(string.substr(last));
|
||||
|
||||
return result;
|
||||
}
|
18
shared/utils.h
Normal file
18
shared/utils.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
// SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include "definitions.h"
|
||||
|
||||
namespace Shared {
|
||||
std::string getISOTimestamp();
|
||||
std::string getUUID();
|
||||
Shared::Strings split(const std::string& string, const std::string& delimiter = " ");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue