Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Libretro
libretro-chailove
Commits
e6e69a70
Verified
Commit
e6e69a70
authored
Oct 11, 2018
by
RobLoach
Browse files
Add string::split()
parent
aaa88afa
Changes
3
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
e6e69a70
...
...
@@ -6,10 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## 0.28.1 - Unreleased
### Fixes
-
Fixed
save_dir
mounting
-
Fixed
`/libretro/saves`
mounting
### Features
-
Added
`string::trim()`
-
Added
`string::split()`
## 0.28.0 - 2018-10-07
### Features
...
...
src/love/script.cpp
View file @
e6e69a70
...
...
@@ -104,14 +104,14 @@ script::script(const std::string& file) {
return
newSubject
;
}),
"replace"
);
//
string::replace(char search, char 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()
// string::trim()
chai
.
add
(
fun
([](
const
std
::
string
&
subject
)
{
std
::
string
result
(
subject
);
std
::
string
chars
=
"
\t\n\v\f\r
"
;
...
...
@@ -120,6 +120,26 @@ script::script(const std::string& file) {
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"
);
// List
auto
listModule
=
std
::
make_shared
<
chaiscript
::
Module
>
();
chaiscript
::
bootstrap
::
standard_library
::
list_type
<
std
::
list
<
chaiscript
::
Boxed_Value
>
>
(
"List"
,
*
listModule
);
...
...
test/unittests/system.chai
View file @
e6e69a70
...
...
@@ -37,3 +37,11 @@ assert_equal(newReplaceString, "Hello World. Hello World.", "string::replace(cha
// string::trim()
var trimSubject = " Hello World! "
assert_equal(trimSubject.trim(), "Hello World!", "string::trim()")
// string::split()
var splitTest = "Hello|How|Are|You"
var splitResult = splitTest.split("|")
assert_equal(splitResult[1], "How", "string::split()")
splitTest = "Rob, John, Loach"
splitResult = splitTest.split(", ")
assert_equal(splitResult[1], "John", " - commas")
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment