#include "utils.h"
#include <cinttypes>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <curl/curl.h>
#include <cwchar>
#include <fcntl.h>
#include <iconv.h>
#include <langinfo.h>
#include <libxml/uri.h>
#include <mutex>
#include <pwd.h>
#include <sstream>
#include <stfl.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <unistd.h>
#if HAVE_GCRYPT
#include <gnutls/gnutls.h>
#if GNUTLS_VERSION_NUMBER < 0x020b00
#include <errno.h>
#include <gcrypt.h>
#include <pthread.h>
GCRY_THREAD_OPTION_PTHREAD_IMPL;
#endif
#endif
#if HAVE_OPENSSL
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#include <openssl/crypto.h>
#endif
#endif
#include "config.h"
#include "curldatareceiver.h"
#include "curlhandle.h"
#include "links.h"
#include "libnewsboat-ffi/src/utils.rs.h"
#include "logger.h"
#include "strprintf.h"
using HTTPMethod = newsboat::utils::HTTPMethod;
namespace newsboat {
std::string utils::strip_comments(const std::string& line)
{
return std::string(utils::bridged::strip_comments(line));
}
std::vector<std::string> utils::tokenize_quoted(const std::string& str,
std::string delimiters)
{
const auto tokens = utils::bridged::tokenize_quoted(str, delimiters);
std::vector<std::string> result;
for (const auto& token : tokens) {
result.push_back(std::string(token));
}
return result;
}
nonstd::optional<std::string> utils::extract_token_quoted(std::string& str,
std::string delimiters)
{
rust::String remaining = str;
rust::String token;
if (utils::bridged::extract_token_quoted(remaining, delimiters, token)) {
str = std::string(remaining);
return std::string(token);
}
str = std::string(remaining);
return {};
}
std::vector<std::string> utils::tokenize(const std::string& str,
std::string delimiters)
{
/*
* This function tokenizes a string by the delimiters. Plain and simple.
*/
std::vector<std::string> tokens;
std::string::size_type last_pos = str.find_first_not_of(delimiters, 0);
std::string::size_type pos = str.find_first_of(delimiters, last_pos);
while (std::string::npos != pos || std::string::npos != last_pos) {
tokens.push_back(str.substr(last_pos, pos - last_pos));
last_pos = str.find_first_not_of(delimiters, pos);
pos = str.find_first_of(delimiters, last_pos);
}
return tokens;
}
std::vector<std::string> utils::tokenize_spaced(const std::string& str,
std::string delimiters)
{
std::vector<std::string> tokens;
std::string::size_type last_pos = str.find_first_not_of(delimiters, 0);
std::string::size_type pos = str.find_first_of(delimiters, last_pos);
if (last_pos != 0) {
tokens.push_back(str.substr(0, last_pos));
}
while (std::string::npos != pos || std::string::npos != last_pos) {
tokens.push_back(str.substr(last_pos, pos - last_pos));
last_pos = str.find_first_not_of(delimiters, pos);
if (last_pos > pos) {
tokens.push_back(str.substr(pos, last_pos - pos));
}
pos = str.find_first_of(delimiters, last_pos);
}
return tokens;
}
std::string utils::consolidate_whitespace(const std::string& str)
{
return std::string(utils::bridged::consolidate_whitespace(str));
}
std::vector<std::string> utils::tokenize_nl(const std::string& str,
std::string delimiters)
{
std::vector<std::string> tokens;
std::string::size_type last_pos = str.find_first_not_of(delimiters, 0);
std::string::size_type pos = str.find_first_of(delimiters, last_pos);
unsigned int i;
LOG(Level::DEBUG,
"utils::tokenize_nl: last_pos = %" PRIu64,
static_cast<uint64_t>(last_pos));
if (last_pos != std::string::npos) {
for (