Skip to content

Commit

Permalink
change string to namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Jun 24, 2021
1 parent b8439ab commit 1f2a220
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 82 deletions.
Empty file added examples/detour.md
Empty file.
Empty file added examples/encryption.md
Empty file.
Empty file added examples/filesystem.md
Empty file.
Empty file added examples/http.md
Empty file.
Empty file added examples/memory.md
Empty file.
Empty file added examples/socket.md
Empty file.
Empty file added examples/symbol.md
Empty file.
114 changes: 46 additions & 68 deletions libpsutil/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,93 +4,71 @@

namespace libpsutil
{
char va_buffer[0x1000];
const char* string::va(const char* fmt, ...)
namespace string
{
memset(va_buffer, 0, 0x1000);

va_list ap;
va_start(ap, fmt);
vsprintf(va_buffer, fmt, ap);
va_end(ap);
char va_buffer[0x1000];
const char* va(const char* fmt, ...)
{
memset(va_buffer, 0, 0x1000);

return va_buffer;
}
va_list ap;
va_start(ap, fmt);
vsprintf(va_buffer, fmt, ap);
va_end(ap);

std::string string::to_lower(const std::string& text)
{
auto output = text;
return va_buffer;
}

std::transform(output.begin(), output.end(), output.begin(), [](const char input)
std::string to_lower(const std::string& text)
{
return static_cast<char>(std::tolower(input));
});
auto output = text;

return output;
}
std::transform(output.begin(), output.end(), output.begin(), [](const char input)
{
return static_cast<char>(std::tolower(input));
});

std::string string::to_upper(const std::string& text)
{
auto output = text;
return output;
}

std::transform(output.begin(), output.end(), output.begin(), [](const char input)
std::string to_upper(const std::string& text)
{
return static_cast<char>(std::toupper(input));
});
auto output = text;

return output;
}
std::transform(output.begin(), output.end(), output.begin(), [](const char input)
{
return static_cast<char>(std::toupper(input));
});

bool string::begins_with(const std::string& text, const std::string& search)
{
return (text.size() >= search.size() && text.substr(0, search.size()) == search);
}

bool string::ends_with(const std::string& text, const std::string& search)
{
return (text.size() >= search.size() && text.substr(text.size() - search.size(), search.size()) == search);
}

std::vector<std::string> string::split(const std::string& text, char delimiter)
{
std::vector<std::string> out;
std::string::size_type prev_pos = 0, pos = 0;
return output;
}

while ((pos = text.find(delimiter, pos)) != std::string::npos)
bool begins_with(const std::string& text, const std::string& search)
{
std::string substring(text.substr(prev_pos, pos - prev_pos));

out.push_back(substring);

prev_pos = ++pos;
return (text.size() >= search.size() && text.substr(0, search.size()) == search);
}

out.push_back(text.substr(prev_pos, pos - prev_pos));
return out;
}
bool ends_with(const std::string& text, const std::string& search)
{
return (text.size() >= search.size() && text.substr(text.size() - search.size(), search.size()) == search);
}

std::string string::to_lower()
{
return string::to_lower(*this);
}
std::vector<std::string> split(const std::string& text, char delimiter)
{
std::vector<std::string> out;
std::string::size_type prev_pos = 0, pos = 0;

std::string string::to_upper()
{
return string::to_upper(*this);
}
while ((pos = text.find(delimiter, pos)) != std::string::npos)
{
std::string substring(text.substr(prev_pos, pos - prev_pos));

bool string::begins_with(const std::string& search)
{
return string::begins_with(*this, search);
}
out.push_back(substring);

bool string::ends_with(const std::string& search)
{
return string::ends_with(*this, search);
}
prev_pos = ++pos;
}

std::vector<std::string> string::split(char delimiter)
{
return string::split(*this, delimiter);
out.push_back(text.substr(prev_pos, pos - prev_pos));
return out;
}
}
}
21 changes: 7 additions & 14 deletions libpsutil/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@

namespace libpsutil
{
class string : public std::string
namespace string
{
public:
static const char* va(const char* fmt, ...);
const char* va(const char* fmt, ...);

static std::string to_lower(const std::string& text);
static std::string to_upper(const std::string& text);
static bool begins_with(const std::string& text, const std::string& search);
static bool ends_with(const std::string& text, const std::string& search);
static std::vector<std::string> split(const std::string& text, char delimiter);

std::string to_lower();
std::string to_upper();
bool begins_with(const std::string& search);
bool ends_with(const std::string& search);
std::vector<std::string> split(char delimiter);
std::string to_lower(const std::string& text);
std::string to_upper(const std::string& text);
bool begins_with(const std::string& text, const std::string& search);
bool ends_with(const std::string& text, const std::string& search);
std::vector<std::string> split(const std::string& text, char delimiter);
};
}

0 comments on commit 1f2a220

Please sign in to comment.