init
This commit is contained in:
39
src/util.h
Normal file
39
src/util.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "json.h"
|
||||
|
||||
namespace telegram_tui {
|
||||
|
||||
struct StoredConfig {
|
||||
std::string api_id;
|
||||
std::string api_hash;
|
||||
bool auto_reload_chat_history = false;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::string get_env(const char* name);
|
||||
[[nodiscard]] std::string trim_copy(std::string value);
|
||||
[[nodiscard]] std::string single_line(std::string text);
|
||||
[[nodiscard]] bool is_decimal_number(const std::string& value);
|
||||
[[nodiscard]] std::filesystem::path data_root();
|
||||
[[nodiscard]] StoredConfig load_app_config();
|
||||
bool save_app_config(const StoredConfig& config);
|
||||
[[nodiscard]] std::string safe_string(const json& object, const char* key);
|
||||
[[nodiscard]] std::int64_t safe_i64(const json& object, const char* key);
|
||||
[[nodiscard]] std::int32_t safe_i32(const json& object, const char* key);
|
||||
[[nodiscard]] std::string format_time(std::int32_t unix_time);
|
||||
[[nodiscard]] std::string format_date(std::int32_t unix_time);
|
||||
[[nodiscard]] std::string format_datetime(std::int32_t unix_time);
|
||||
[[nodiscard]] std::string format_file_size(std::int64_t size_bytes);
|
||||
[[nodiscard]] std::vector<std::string> wrap_text(const std::string& text, int width);
|
||||
[[nodiscard]] std::size_t utf8_byte_index_from_utf16_offset(const std::string& text, std::size_t utf16_offset);
|
||||
[[nodiscard]] std::size_t utf8_prev_index(const std::string& text, std::size_t byte_index);
|
||||
[[nodiscard]] std::size_t utf8_next_index(const std::string& text, std::size_t byte_index);
|
||||
[[nodiscard]] int utf8_display_width(const std::string& text, std::size_t byte_limit = std::string::npos);
|
||||
void pop_utf8_back(std::string& text);
|
||||
|
||||
} // namespace telegram_tui
|
||||
Reference in New Issue
Block a user