mirror of
https://github.com/fedddddd/iw5-gsc-utils.git
synced 2025-04-20 21:05:44 +00:00
Add some string functions
This commit is contained in:
parent
14d0f401fb
commit
7b995b3348
46
src/component/string.cpp
Normal file
46
src/component/string.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include <stdinc.hpp>
|
||||||
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
|
#include "gsc.hpp"
|
||||||
|
|
||||||
|
#include <utils/string.hpp>
|
||||||
|
|
||||||
|
namespace string
|
||||||
|
{
|
||||||
|
class component final : public component_interface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void post_unpack() override
|
||||||
|
{
|
||||||
|
gsc::function::add("toupper", [](const gsc::function_args& args)
|
||||||
|
{
|
||||||
|
return utils::string::to_upper(args[0].as<std::string>());
|
||||||
|
});
|
||||||
|
|
||||||
|
gsc::function::add("getchar", [](const gsc::function_args& args)
|
||||||
|
{
|
||||||
|
auto index = 0;
|
||||||
|
if (args.size() > 1)
|
||||||
|
{
|
||||||
|
index = args[1].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto string = args[0].as<std::string>();
|
||||||
|
if (index >= static_cast<int>(string.size()))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Char index out of bounds");
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<int>(string[index]);
|
||||||
|
});
|
||||||
|
|
||||||
|
gsc::function::add("chartostring", [](const gsc::function_args& args)
|
||||||
|
{
|
||||||
|
const auto char_ = static_cast<char>(args[0].as<int>());
|
||||||
|
return std::string(1, char_);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
REGISTER_COMPONENT(string::component)
|
Loading…
x
Reference in New Issue
Block a user