Add stringsutil header
This commit is contained in:
parent
001a7ce38a
commit
c7d87e9a9f
4 changed files with 27 additions and 16 deletions
|
@ -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
|
||||
|
|
6
include/stringutils.h
Normal file
6
include/stringutils.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
std::vector<std::string> tokenize(const std::string& str);
|
17
src/main.cpp
17
src/main.cpp
|
@ -1,5 +1,6 @@
|
|||
#include <SDL.h>
|
||||
#include <SDL_vulkan.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
@ -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<std::string> tokenize(const std::string& str) {
|
||||
size_t lastPos = str.find_first_not_of(',', 0);
|
||||
size_t pos = str.find_first_of(',', lastPos);
|
||||
|
||||
std::vector<std::string> 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);
|
||||
|
||||
|
|
17
src/stringutils.cpp
Normal file
17
src/stringutils.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "stringutils.h"
|
||||
|
||||
std::vector<std::string> tokenize(const std::string& str) {
|
||||
size_t lastPos = str.find_first_not_of(',', 0);
|
||||
size_t pos = str.find_first_of(',', lastPos);
|
||||
|
||||
std::vector<std::string> 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;
|
||||
}
|
||||
|
Reference in a new issue