Skip to content

Commit

Permalink
chore: remove redundant template.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trico-Everfire committed May 7, 2024
1 parent 48bee80 commit 08649b0
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 158 deletions.
314 changes: 158 additions & 156 deletions include/sourcepp/detail/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <utility>
#include <vector>
#include <iostream>
#include <cstring>

namespace sourcepp::detail {

Expand All @@ -25,193 +26,194 @@ void trim(std::string& s, std::string_view c);
std::vector<std::string> split(std::string_view s, char delim);

class UtilStringView
{
std::string owningString;
std::string_view string;
bool selfOwning = false;
public:
template<typename T>
UtilStringView(T str)
{

if( std::is_same<T, std::string_view>::value) {
string = str;
return;
}
{
std::string owningString;
std::string_view string;
bool selfOwning = false;
public:

if(std::is_same<T, std::string>::value || std::is_same<T, char*>::value)
{
owningString = std::move(str);
string = std::string_view(owningString);
selfOwning = true;
return;
}
UtilStringView(const char* str)
{
owningString = str;
string = std::string_view(owningString);
selfOwning = true;
}

}
UtilStringView(std::string& str)
{
owningString = std::move(str);
string = std::string_view(owningString);
selfOwning = true;
}

UtilStringView() = default;
UtilStringView(std::string_view str)
{
string = str;
}

~UtilStringView() = default;
UtilStringView() = default;

template<typename T>
explicit UtilStringView(const UtilStringView& t){
if(t.selfOwning) {
owningString = t.owningString;
string = std::string_view(owningString);
} else
string = t.string;
}
~UtilStringView() = default;

template<typename T>
explicit UtilStringView(UtilStringView&& t)
template<typename T>
explicit UtilStringView(const UtilStringView& t){
if(t.selfOwning) {
owningString = t.owningString;
string = std::string_view(owningString);
} else
string = t.string;
}

{
if(t.selfOwning) {
owningString = std::move(t.owningString);
string = std::string_view(owningString);
this->selfOwning = true;
} else
string = t.string;
}
template<typename T>
explicit UtilStringView(UtilStringView&& t)

std::string_view operator ->() const
{
return this->string;
}

operator std::string_view() const {
return this->string;
}
{
if(t.selfOwning) {
owningString = std::move(t.owningString);
string = std::string_view(owningString);
this->selfOwning = true;
} else
string = t.string;
}

std::string_view operator ->() const
{
return this->string;
}

explicit operator std::string() const {
{
if(this->selfOwning)
return this->owningString;
return std::string(string);
}
}
operator std::string_view() const {
return this->string;
}

bool operator==( const std::string& str ) const
explicit operator std::string() const {
{
return string == str;
if(this->selfOwning)
return this->owningString;
return std::string(string);
}
}

bool operator==( const std::string_view& str ) const
{
return string == str;
}
bool operator==( const std::string& str ) const
{
return string == str;
}

bool operator==( const char* str) const
{
return string == str;
}
bool operator==( const std::string_view& str ) const
{
return string == str;
}

UtilStringView& operator=(const char* str)
{
owningString = str;
string = owningString;
selfOwning = true;
return *this;
}
bool operator==( const char* str) const
{
return string == str;
}

UtilStringView& operator=(std::string str)
{
owningString = std::move(str);
string = owningString;
selfOwning = true;
return *this;
}
UtilStringView& operator=(const char* str)
{
owningString = str;
string = owningString;
selfOwning = true;
return *this;
}

UtilStringView& operator=(std::string_view str)
{
string = str;
return *this;
}
UtilStringView& operator=(std::string str)
{
owningString = std::move(str);
string = owningString;
selfOwning = true;
return *this;
}

UtilStringView& operator<<(const char* str)
{
this->append(str);
return *this;
}
UtilStringView& operator=(std::string_view str)
{
string = str;
return *this;
}

UtilStringView& operator<<(std::string_view str)
{
this->append(str);
return *this;
}
UtilStringView& operator<<(const char* str)
{
this->append(str);
return *this;
}

UtilStringView& operator<<(const std::string& str)
{
this->append(str);
return *this;
}
UtilStringView& operator<<(std::string_view str)
{
this->append(str);
return *this;
}

static UtilStringView make_self_owning(std::string_view str)
{
UtilStringView selfOwningView = {};
selfOwningView.owningString = str;
selfOwningView.string = selfOwningView.owningString;
selfOwningView.selfOwning = true;
return selfOwningView;
}
UtilStringView& operator<<(const std::string& str)
{
this->append(str);
return *this;
}

static UtilStringView make_view(std::string_view str)
{
UtilStringView string_view = {};
string_view.string = str;
return string_view;
}
static UtilStringView make_self_owning(std::string_view str)
{
UtilStringView selfOwningView = {};
selfOwningView.owningString = str;
selfOwningView.string = selfOwningView.owningString;
selfOwningView.selfOwning = true;
return selfOwningView;
}

static UtilStringView make_view(std::string_view str)
{
UtilStringView string_view = {};
string_view.string = str;
return string_view;
}

static UtilStringView make_view(const std::string& str)
{
UtilStringView string_view = {};
string_view.string = str;
return string_view;
}
static UtilStringView make_view(const std::string& str)
{
UtilStringView string_view = {};
string_view.string = str;
return string_view;
}

static UtilStringView make_view(const char* str)
{
UtilStringView string_view = {};
string_view.string = str;
return string_view;
}
static UtilStringView make_view(const char* str)
{
UtilStringView string_view = {};
string_view.string = str;
return string_view;
}

[[nodiscard]] size_t length() const
{
return this->string.length();
}
[[nodiscard]] size_t length() const
{
return this->string.length();
}

[[nodiscard]] const char* data() const
{
return this->string.data();
}
[[nodiscard]] const char* data() const
{
return this->string.data();
}

[[nodiscard]] std::string get_string() const
{
return std::string(string);
}
[[nodiscard]] std::string get_string() const
{
return std::string(string);
}

[[nodiscard]] bool ends_with(std::string_view str) const
{
return this->string.ends_with(str);
}
[[nodiscard]] bool ends_with(std::string_view str) const
{
return this->string.ends_with(str);
}

std::string_view& append(const std::string_view & str)
{
if(!this->selfOwning) {
this->owningString = string;
this->selfOwning = true;
}
this->owningString.append(str);
this->string = std::string_view(owningString);
return this->string;
std::string_view& append(const std::string_view & str)
{
if(!this->selfOwning) {
this->owningString = string;
this->selfOwning = true;
}
this->owningString.append(str);
this->string = std::string_view(owningString);
return this->string;
}

[[nodiscard]] bool isSelfOwning() const
{
return selfOwning;
}
[[nodiscard]] bool isSelfOwning() const
{
return selfOwning;
}

};
};

} // namespace sourcepp::detail
4 changes: 2 additions & 2 deletions test/fgdpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ TEST(fgdpp, parseWriteP2CE)
auto& property = ent.classProperties.emplace_back();
property.name = "base";
auto& pp = property.classProperties.emplace_back();
pp.properties.emplace_back(std::string("func_brush"));
pp.properties.emplace_back("func_brush" );

ent.entityDescription.emplace_back() << quoted("An entity designed for having too many bitches.");
ent.entityDescription.emplace_back( quoted("An entity designed for having too many bitches.") );

auto& io = ent.inputOutput.emplace_back();
io.name = "cosume_flesh";
Expand Down

0 comments on commit 08649b0

Please sign in to comment.