From fe84792ced1e4b9b9b4f6719b220775be309216c Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sun, 26 Jun 2022 02:35:51 -0400 Subject: [PATCH 1/2] Add TextSplit --- include/Functions.hpp | 9 +++++++++ tests/raylib_cpp_test.cpp | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/include/Functions.hpp b/include/Functions.hpp index 7ae95302..fe472f64 100644 --- a/include/Functions.hpp +++ b/include/Functions.hpp @@ -342,6 +342,15 @@ RLAPI inline std::string TextInsert(const std::string& text, const std::string& return ""; } +/** + * Split text into multiple strings + */ +RLAPI inline std::vector TextSplit(const std::string& text, char delimiter) { + int count; + const char** split = ::TextSplit(text.c_str(), delimiter, &count); + return std::vector(split, split + count); +} + /** * Find first text occurrence within a string */ diff --git a/tests/raylib_cpp_test.cpp b/tests/raylib_cpp_test.cpp index d3e25ee1..301e45a3 100644 --- a/tests/raylib_cpp_test.cpp +++ b/tests/raylib_cpp_test.cpp @@ -94,6 +94,12 @@ int main(int argc, char *argv[]) { AssertEqual(output, "World"); } + { + std::vector output = raylib::TextSplit("Hello|How|Are|You", '|'); + AssertEqual(output.size(), 4); + AssertEqual(output[1], "How"); + } + // Wave { raylib::Wave wave(path + "/resources/weird.wav"); From 0dc14c038a3ee242efb750a73b0cb5448f5423ca Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 29 Jun 2022 23:11:26 -0400 Subject: [PATCH 2/2] Update tests/raylib_cpp_test.cpp --- tests/raylib_cpp_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/raylib_cpp_test.cpp b/tests/raylib_cpp_test.cpp index 301e45a3..915f6d0f 100644 --- a/tests/raylib_cpp_test.cpp +++ b/tests/raylib_cpp_test.cpp @@ -94,6 +94,7 @@ int main(int argc, char *argv[]) { AssertEqual(output, "World"); } + // TextSplit { std::vector output = raylib::TextSplit("Hello|How|Are|You", '|'); AssertEqual(output.size(), 4);