From c7d87e9a9fc66e2a196230a4d131362565610989 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 16 Dec 2018 19:59:48 -0500 Subject: [PATCH] Add stringsutil header --- CMakeLists.txt | 3 ++- include/stringutils.h | 6 ++++++ src/main.cpp | 17 ++--------------- src/stringutils.cpp | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 include/stringutils.h create mode 100644 src/stringutils.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 252d962..a946266 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,8 @@ set(GRAPH_SRC src/dofpass.cpp src/skypass.cpp src/shadowpass.cpp - src/config.cpp) + src/config.cpp + src/stringutils.cpp) if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(GRAPH_SRC diff --git a/include/stringutils.h b/include/stringutils.h new file mode 100644 index 0000000..968afd4 --- /dev/null +++ b/include/stringutils.h @@ -0,0 +1,6 @@ +#pragma once + +#include +#include + +std::vector tokenize(const std::string& str); diff --git a/src/main.cpp b/src/main.cpp index 80346ff..315463f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include #include + #include #include #include @@ -21,6 +22,7 @@ #include "cinematic.h" #include "material.h" #include "config.h" +#include "stringutils.h" SDL_Window* window = nullptr; Renderer* renderer = nullptr; @@ -138,21 +140,6 @@ Mesh* loadMesh(const std::string& path) { return mesh; } -std::vector tokenize(const std::string& str) { - size_t lastPos = str.find_first_not_of(',', 0); - size_t pos = str.find_first_of(',', lastPos); - - std::vector tokens; - while(pos != std::string::npos || lastPos != std::string::npos) { - tokens.push_back(str.substr(lastPos, pos - lastPos)); - - lastPos = str.find_first_not_of(',', pos); - pos = str.find_first_of(',', lastPos); - } - - return tokens; -} - Material* loadMaterial(const std::string& path) { std::ifstream file("data/" + path); diff --git a/src/stringutils.cpp b/src/stringutils.cpp new file mode 100644 index 0000000..4cd2751 --- /dev/null +++ b/src/stringutils.cpp @@ -0,0 +1,17 @@ +#include "stringutils.h" + +std::vector tokenize(const std::string& str) { + size_t lastPos = str.find_first_not_of(',', 0); + size_t pos = str.find_first_of(',', lastPos); + + std::vector tokens; + while(pos != std::string::npos || lastPos != std::string::npos) { + tokens.push_back(str.substr(lastPos, pos - lastPos)); + + lastPos = str.find_first_not_of(',', pos); + pos = str.find_first_of(',', lastPos); + } + + return tokens; +} +