79 lines
1.9 KiB
C++
79 lines
1.9 KiB
C++
#pragma once
|
|
#ifndef _NB_CORE_TYPES
|
|
#define _NB_CORE_TYPES
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
#include "TypeTraits.hpp"
|
|
|
|
namespace nb {
|
|
|
|
#ifdef _NB_TARGET_WINDOWS
|
|
const std::string NEWLINE = "\n";
|
|
const std::wstring WNEWLINE = L"\n";
|
|
#endif // _NB_TARGET_WINDOWS
|
|
#ifdef _NB_TARGET_LINUX
|
|
const std::string NEWLINE = "\n";
|
|
const std::wstring WNEWLINE = L"\n";
|
|
#endif // _NB_TARGET_LINUX
|
|
|
|
const std::string TABOVER = " ";
|
|
|
|
// std::wstring str_to_wstr(std::string in);
|
|
|
|
// std::string wstr_to_str(std::wstring in);
|
|
|
|
template <typename Stream, typename... Args>
|
|
void stream(const Stream& s, Args&&... args);
|
|
|
|
template <typename Stream, typename... Args>
|
|
void stream(const Stream& s, Args&&... args) {
|
|
(s << ... << args);
|
|
}
|
|
|
|
template<typename... Args>
|
|
void term(Args&&... args) { stream(std::cout, args..., nb::NEWLINE); }
|
|
|
|
template<typename... Args>
|
|
void wterm(Args&&... args) { stream(std::wcout, args..., nb::WNEWLINE); }
|
|
|
|
template <typename T = char>
|
|
std::basic_string<T> find_and_replace(
|
|
ExplicitType_t<std::basic_string<T>> original,
|
|
ExplicitType_t<std::basic_string_view<T>> find,
|
|
ExplicitType_t<std::basic_string_view<T>> replace
|
|
) {
|
|
using StringType = std::basic_string<T>;
|
|
|
|
StringType ret(original);
|
|
|
|
std::size_t find_len = find.length();
|
|
std::size_t replace_len = replace.length();
|
|
std::size_t currpos = 0;
|
|
while(true) {
|
|
currpos = ret.find(find, currpos);
|
|
if (currpos == StringType::npos) {
|
|
break;
|
|
}
|
|
ret = ret.erase(currpos, find_len);
|
|
ret = ret.insert(currpos, replace);
|
|
currpos += replace_len;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
std::string indent_strblock(
|
|
std::string block,
|
|
std::string prepend,
|
|
std::string topIndent
|
|
);
|
|
|
|
std::string indent_strblock(
|
|
std::string block,
|
|
std::string prepend
|
|
);
|
|
|
|
} // namespace nb
|
|
#endif // _NB_CORE_TYPES
|