2024-04-25 21:14:13 +00:00
|
|
|
#ifndef TRANSCRIPTION_UTILS_H
|
|
|
|
#define TRANSCRIPTION_UTILS_H
|
|
|
|
|
|
|
|
#include <string>
|
2024-04-26 19:34:18 +00:00
|
|
|
#include <vector>
|
2024-05-10 21:37:09 +00:00
|
|
|
#include <chrono>
|
2024-06-26 19:35:43 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cctype>
|
2024-04-25 21:14:13 +00:00
|
|
|
|
2024-06-05 22:02:36 +00:00
|
|
|
// Fix UTF8 string for Windows
|
2024-04-25 21:14:13 +00:00
|
|
|
std::string fix_utf8(const std::string &str);
|
2024-06-05 22:02:36 +00:00
|
|
|
|
|
|
|
// Remove leading and trailing non-alphabetic characters
|
2024-04-25 21:14:13 +00:00
|
|
|
std::string remove_leading_trailing_nonalpha(const std::string &str);
|
|
|
|
|
2024-06-05 22:02:36 +00:00
|
|
|
// Split a string by a delimiter
|
|
|
|
std::vector<std::string> split(const std::string &string, char delimiter);
|
2024-05-10 21:37:09 +00:00
|
|
|
|
2024-06-05 22:02:36 +00:00
|
|
|
// Get the current timestamp in milliseconds since epoch
|
2024-05-10 21:37:09 +00:00
|
|
|
inline uint64_t now_ms()
|
|
|
|
{
|
|
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
std::chrono::system_clock::now().time_since_epoch())
|
|
|
|
.count();
|
|
|
|
}
|
|
|
|
|
2024-07-19 18:02:24 +00:00
|
|
|
// Get the current timestamp in nano seconds since epoch
|
|
|
|
inline uint64_t now_ns()
|
|
|
|
{
|
|
|
|
return std::chrono::duration_cast<std::chrono::nanoseconds>(
|
|
|
|
std::chrono::system_clock::now().time_since_epoch())
|
|
|
|
.count();
|
|
|
|
}
|
|
|
|
|
2024-06-05 22:02:36 +00:00
|
|
|
// Split a string into words based on spaces
|
|
|
|
std::vector<std::string> split_words(const std::string &str_copy);
|
|
|
|
|
2024-06-26 19:35:43 +00:00
|
|
|
// trim (strip) string from leading and trailing whitespaces
|
|
|
|
template<typename StringLike> StringLike trim(const StringLike &str)
|
|
|
|
{
|
|
|
|
StringLike str_copy = str;
|
|
|
|
str_copy.erase(str_copy.begin(),
|
|
|
|
std::find_if(str_copy.begin(), str_copy.end(),
|
|
|
|
[](unsigned char ch) { return !std::isspace(ch); }));
|
|
|
|
str_copy.erase(std::find_if(str_copy.rbegin(), str_copy.rend(),
|
|
|
|
[](unsigned char ch) { return !std::isspace(ch); })
|
|
|
|
.base(),
|
|
|
|
str_copy.end());
|
|
|
|
return str_copy;
|
|
|
|
}
|
|
|
|
|
2024-04-25 21:14:13 +00:00
|
|
|
#endif // TRANSCRIPTION_UTILS_H
|