Remove carriage returns and don't actually reinvent the erase-remove idiom

This commit is contained in:
clobber
2014-07-22 21:02:42 -05:00
parent b816c248d9
commit fccfcdca60
2 changed files with 3 additions and 21 deletions
+2 -21
View File
@@ -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;
}
// ----------------------------------------------------------------------------
+1
View File
@@ -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]);