From fccfcdca609c3f9f78802c79fe26c9117c5c8fb0 Mon Sep 17 00:00:00 2001 From: clobber Date: Tue, 22 Jul 2014 21:02:42 -0500 Subject: [PATCH] Remove carriage returns and don't actually reinvent the erase-remove idiom --- core/Common.cpp | 23 ++--------------------- core/Database.cpp | 1 + 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/core/Common.cpp b/core/Common.cpp index 5f761c4..19f087c 100755 --- a/core/Common.cpp +++ b/core/Common.cpp @@ -136,27 +136,8 @@ std::string common_Trim(std::string target) { // Remove // ---------------------------------------------------------------------------- std::string common_Remove(std::string target, char value) { - int length = 0; - int index; - for(index = 0; index < target.size( ); index++) { - if(target[index] != value) { - length++; - } - } - - char* buffer = new char[length + 1]; - int count = 0; - for(index = 0; index < target.size( ); index++) { - if(target[index] != value) { - buffer[count] = target[index]; - count++; - } - } - - buffer[length] = 0; - std::string source = buffer; - delete[ ] buffer; - return source; + target.erase(std::remove(target.begin(), target.end(), value), target.end()); + return target; } // ---------------------------------------------------------------------------- diff --git a/core/Database.cpp b/core/Database.cpp index e7c00e7..6f99bb9 100755 --- a/core/Database.cpp +++ b/core/Database.cpp @@ -61,6 +61,7 @@ bool database_Load(std::string digest) { for(int index = 0; index < 7; index++) { fgets(buffer, 256, file); entry[index] = common_Remove(buffer, '\n'); + entry[index] = common_Remove(entry[index], '\r'); } cartridge_title = database_GetValue(entry[0]);