From 52f78e733af35fdd1ac325ea50011f95dbc4f6a6 Mon Sep 17 00:00:00 2001 From: Björn Steinbrink Date: Wed, 19 Oct 2005 19:13:32 +0000 Subject: Fix empty lines not being read from text files. --- src/resources/resourcemanager.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/resources') diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 4f409431..e2839416 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -24,6 +24,7 @@ #include "resourcemanager.h" #include +#include #include #include "image.h" @@ -292,16 +293,11 @@ ResourceManager::loadTextFile(const std::string &fileName) return lines; } - // Reallocate and include terminating 0 character - fileContents = (char*)realloc(fileContents, contentsLength + 1); - fileContents[contentsLength] = '\0'; + std::istringstream iss(std::string(fileContents, contentsLength)); - // Tokenize and add each line separately - char *line = strtok(fileContents, "\n"); - while (line != NULL) - { + std::string line; + while(getline(iss, line, '\n')) { lines.push_back(line); - line = strtok(NULL, "\n"); } free(fileContents); -- cgit v1.2.3-70-g09d2