mirror of
https://github.com/ModOrganizer2/libbsarch.git
synced 2026-07-27 14:06:31 -07:00
Reorganized directories
Readded .editorconfig C wrapper can be built again Delphi library can be built again Initial cleanup of cmake files
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/* Copyright (C) 2019 G'k
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
#include "convertible_ostream.hpp"
|
||||
|
||||
namespace libbsarch {
|
||||
convertible_ostream &convertible_ostream::operator<<(const std::string &rh)
|
||||
{
|
||||
std::cout << rh;
|
||||
return *this;
|
||||
}
|
||||
convertible_ostream &convertible_ostream::operator<<(const char *rh)
|
||||
{
|
||||
std::cout << rh;
|
||||
return *this;
|
||||
}
|
||||
convertible_ostream &convertible_ostream::operator<<(const char rh)
|
||||
{
|
||||
std::cout << rh;
|
||||
return *this;
|
||||
}
|
||||
convertible_ostream &convertible_ostream::operator<<(const std::wstring &rh)
|
||||
{
|
||||
std::wcout << rh;
|
||||
return *this;
|
||||
}
|
||||
convertible_ostream &convertible_ostream::operator<<(const void *rh)
|
||||
{
|
||||
std::cout << rh;
|
||||
return *this;
|
||||
}
|
||||
convertible_ostream &convertible_ostream::operator<<(const convertible_string &rh)
|
||||
{
|
||||
return *this << std::string(rh);
|
||||
}
|
||||
|
||||
convertible_ostream::operator std::ostream &()
|
||||
{
|
||||
return std::cout;
|
||||
}
|
||||
convertible_ostream::operator std::wostream &()
|
||||
{
|
||||
return std::wcout;
|
||||
}
|
||||
|
||||
#ifdef QT
|
||||
convertible_ostream::operator QDebug()
|
||||
{
|
||||
return qDebug();
|
||||
}
|
||||
convertible_ostream &convertible_ostream::operator<<(const QString &rh)
|
||||
{
|
||||
qDebug() << rh;
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,37 @@
|
||||
/* Copyright (C) 2019 G'k
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
#pragma once
|
||||
|
||||
#include "convertible_string.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace libbsarch {
|
||||
class convertible_ostream
|
||||
{
|
||||
public:
|
||||
convertible_ostream &operator<<(const std::string &rh);
|
||||
convertible_ostream &operator<<(const char *rh);
|
||||
convertible_ostream &operator<<(const char rh);
|
||||
convertible_ostream &operator<<(const std::wstring &rh);
|
||||
convertible_ostream &operator<<(const void *rh);
|
||||
convertible_ostream &operator<<(const convertible_string &rh);
|
||||
|
||||
template<typename number, //real type
|
||||
typename = typename std::enable_if<std::is_arithmetic<number>::value, number>::type>
|
||||
convertible_ostream &operator<<(const number &num)
|
||||
{
|
||||
std::cout << num;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator std::ostream &();
|
||||
operator std::wostream &();
|
||||
|
||||
#ifdef QT
|
||||
operator QDebug();
|
||||
convertible_ostream &operator<<(const QString &rh);
|
||||
#endif
|
||||
};
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,128 @@
|
||||
/* Copyright (C) 2019 G'k
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "convertible_string.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
namespace libbsarch {
|
||||
/* conversion ctors */
|
||||
convertible_string::convertible_string(std::string value, bool to_native_path)
|
||||
: str_(std::move(value))
|
||||
, auto_convert_to_native_path(to_native_path)
|
||||
{
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
}
|
||||
|
||||
convertible_string::convertible_string(const char *const val_array, bool to_native_path)
|
||||
: str_(std::string(val_array))
|
||||
, auto_convert_to_native_path(to_native_path)
|
||||
|
||||
{
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
}
|
||||
convertible_string::convertible_string(const std::wstring &wvalue, bool to_native_path)
|
||||
: str_(to_string(wvalue))
|
||||
, auto_convert_to_native_path(to_native_path)
|
||||
|
||||
{
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
}
|
||||
convertible_string::convertible_string(wchar_t const *wval_array, bool to_native_path)
|
||||
: str_(to_string(std::wstring(wval_array)))
|
||||
, auto_convert_to_native_path(to_native_path)
|
||||
{
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
}
|
||||
|
||||
#ifdef QT
|
||||
convertible_string::convertible_string(const QString &qsvalue, bool to_native_path)
|
||||
: str_(to_string(qsvalue))
|
||||
, auto_convert_to_native_path(to_native_path)
|
||||
{
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* assignment operators */
|
||||
convertible_string &convertible_string::operator=(const std::string &value)
|
||||
{
|
||||
str_ = value;
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
return *this;
|
||||
}
|
||||
convertible_string &convertible_string::operator=(const std::wstring &wvalue)
|
||||
{
|
||||
str_ = to_string(wvalue);
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
return *this;
|
||||
}
|
||||
|
||||
convertible_string &convertible_string::operator=(const wchar_t *wvalue)
|
||||
{
|
||||
str_ = to_string(std::wstring(wvalue));
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef QT
|
||||
convertible_string &convertible_string::operator=(const QString &qsvalue)
|
||||
{
|
||||
str_ = to_string(qsvalue);
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* implicit conversion operators */
|
||||
convertible_string::operator std::string() const
|
||||
{
|
||||
return str_;
|
||||
}
|
||||
convertible_string::operator std::wstring() const
|
||||
{
|
||||
return to_wstring(str_);
|
||||
}
|
||||
convertible_string::operator const wchar_t *() const
|
||||
{
|
||||
const std::wstring wstr = to_wstring(str_);
|
||||
wchar_t *wchar_array = new wchar_t[wstr.length() + 1];
|
||||
wcscpy_s(wchar_array, wstr.length() + 1, wstr.c_str());
|
||||
return wchar_array;
|
||||
}
|
||||
#ifdef QT
|
||||
convertible_string::operator QString() const
|
||||
{
|
||||
return to_qstring(str_);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Util */
|
||||
bool convertible_string::remove_substring(const convertible_string &sub_str)
|
||||
{
|
||||
size_t pos = str_.find(sub_str);
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
str_.erase(pos, std::string(sub_str).length());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
convertible_string &convertible_string::to_native_path()
|
||||
{
|
||||
std::filesystem::path path(str_);
|
||||
str_ = path.make_preferred().string();
|
||||
return *this;
|
||||
}
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,54 @@
|
||||
/* Copyright (C) 2019 G'k
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
#pragma once
|
||||
|
||||
//See https://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string
|
||||
|
||||
#include "string_convert.hpp"
|
||||
#ifdef QT
|
||||
#include <QString>
|
||||
#endif
|
||||
|
||||
namespace libbsarch {
|
||||
class convertible_string
|
||||
{
|
||||
public:
|
||||
// default ctor
|
||||
convertible_string() = default;
|
||||
|
||||
/* conversion ctors */
|
||||
convertible_string(std::string value, bool to_native_path = true);
|
||||
convertible_string(const char *const val_array, bool to_native_path = true);
|
||||
convertible_string(const std::wstring &wvalue, bool to_native_path = true);
|
||||
convertible_string(const wchar_t *const wval_array, bool to_native_path = true);
|
||||
#ifdef QT
|
||||
convertible_string(const QString &qsvalue, bool to_native_path = true);
|
||||
#endif
|
||||
|
||||
/* assignment operators */
|
||||
convertible_string &operator=(const std::string &value);
|
||||
convertible_string &operator=(const std::wstring &wvalue);
|
||||
convertible_string &operator=(const wchar_t *wvalue);
|
||||
#ifdef QT
|
||||
convertible_string &operator=(const QString &qsvalue);
|
||||
#endif
|
||||
|
||||
/* implicit conversion operators */
|
||||
operator std::string() const;
|
||||
operator std::wstring() const;
|
||||
operator const wchar_t *() const;
|
||||
#ifdef QT
|
||||
operator QString() const;
|
||||
#endif
|
||||
|
||||
/* Util */
|
||||
bool remove_substring(const convertible_string &sub_str);
|
||||
convertible_string &to_native_path();
|
||||
|
||||
private:
|
||||
std::string str_;
|
||||
bool auto_convert_to_native_path = true;
|
||||
};
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,49 @@
|
||||
/* Copyright (C) 2019 G'k
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
#include "string_convert.hpp"
|
||||
|
||||
namespace libbsarch {
|
||||
#ifdef QT
|
||||
std::wstring to_wstring(const QString &str)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
return std::wstring(reinterpret_cast<const wchar_t *>(str.utf16()));
|
||||
#else
|
||||
return str.toStdWString();
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string to_string(const QString &str)
|
||||
{
|
||||
return str.toStdString();
|
||||
}
|
||||
|
||||
QString to_qstring(const std::string &str)
|
||||
{
|
||||
return QString::fromStdString(str);
|
||||
}
|
||||
|
||||
QString to_qstring(const std::wstring &str)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
return QString::fromUtf16(reinterpret_cast<const ushort *>(str.c_str()));
|
||||
#else
|
||||
return QString::fromStdWString(str);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> s_converter;
|
||||
std::string to_string(const std::wstring &str)
|
||||
{
|
||||
return s_converter.to_bytes(str);
|
||||
}
|
||||
|
||||
std::wstring to_wstring(const std::string &str)
|
||||
{
|
||||
auto ws = s_converter.from_bytes(str);
|
||||
return ws;
|
||||
}
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,24 @@
|
||||
/* Copyright (C) 2019 G'k
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
#pragma once
|
||||
|
||||
#ifdef QT
|
||||
#include <QDebug>
|
||||
#endif
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
|
||||
namespace libbsarch {
|
||||
#ifdef QT
|
||||
std::wstring to_wstring(const QString &str);
|
||||
std::string to_string(const QString &str);
|
||||
QString to_qstring(const std::string &str);
|
||||
QString to_qstring(const std::wstring &str);
|
||||
#endif
|
||||
|
||||
std::string to_string(const std::wstring &str);
|
||||
std::wstring to_wstring(const std::string &str);
|
||||
} // namespace libbsarch
|
||||
Reference in New Issue
Block a user