Verified Commit 6cd44e68 authored by RobLoach's avatar RobLoach
Browse files

Move String Methods to ChaiScript_Extras

parent 7ff738e5
......@@ -4,6 +4,10 @@ All notable changes to [ChaiLove](https://github.com/RobLoach/ChaiLove) will be
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## 0.29.1 - Unreleased
### Chores
- Moved String Methods to [ChaiScript_Extras](https://github.com/ChaiScript/ChaiScript_Extras)
## 0.29.0 - 2018-10-13
### Fixes
- Fixed `/libretro/saves` mounting
......
......@@ -5,6 +5,7 @@
#ifdef __HAVE_CHAISCRIPT__
#include "chaiscript/extras/math.hpp"
#include "chaiscript/extras/string_methods.hpp"
using namespace chaiscript;
#endif
......@@ -92,53 +93,8 @@ script::script(const std::string& file) {
chai.add(bootstrap::standard_library::vector_type<std::vector<std::string>>("StringVector"));
chai.add(bootstrap::standard_library::map_type<std::map<std::string, bool>>("StringBoolMap"));
// Global Helpers
// string::replace(std::string search, std::string replace)
chai.add(fun([](const std::string& subject, const std::string& search, const std::string& replace) {
std::string newSubject(subject);
size_t pos = 0;
while ((pos = newSubject.find(search, pos)) != std::string::npos) {
newSubject.replace(pos, search.length(), replace);
pos += replace.length();
}
return newSubject;
}), "replace");
// string::replace(char search, char replace)
chai.add(fun([](const std::string& subject, char search, char replace) {
std::string newSubject(subject);
std::replace(newSubject.begin(), newSubject.end(), search, replace);
return newSubject;
}), "replace");
// string::trim()
chai.add(fun([](const std::string& subject) {
std::string result(subject);
std::string chars = "\t\n\v\f\r ";
result.erase(0, result.find_first_not_of(chars));
result.erase(0, result.find_last_not_of(chars));
return result;
}), "trim");
// string::split()
chai.add(fun([](const std::string& subject, const std::string& token) {
std::string str(subject);
std::vector<std::string> result;
while (str.size()) {
int index = str.find(token);
if (index != std::string::npos) {
result.push_back(str.substr(0, index));
str = str.substr(index + token.size());
if (str.size() == 0) {
result.push_back(str);
}
} else {
result.push_back(str);
str = "";
}
}
return result;
}), "split");
auto stringmethods = chaiscript::extras::string_methods::bootstrap();
chai.add(stringmethods);
// List
auto listModule = std::make_shared<chaiscript::Module>();
......
Subproject commit f1adc0fa4528ff762a1eea3116977228d16cf0da
Subproject commit 76d21cd8acb08e945f0c305ad55334e289fd68a9
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment