Skip to content

Commit bbabfb1

Browse files
author
brichard19
committed
Remove newlines and carriage return when reading addresses
-Remove any newline or carriage returns when reading addresses from file
1 parent 547d36d commit bbabfb1

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

KeyFinderLib/KeyFinder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void KeyFinder::setTargets(std::string targetsFile)
126126
std::string line;
127127
Logger::log(LogLevel::Info, "Loading addresses from '" + targetsFile + "'");
128128
while(std::getline(inFile, line)) {
129+
util::removeNewline(line);
129130
if(line.length() > 0) {
130131
if(!Address::verifyAddress(line)) {
131132
Logger::log(LogLevel::Error, "Invalid address '" + line + "'");

util/util.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,26 @@ namespace util {
250250

251251
return std::string(buf);
252252
}
253+
254+
void removeNewline(std::string &s)
255+
{
256+
int len = s.length();
257+
258+
int toRemove = 0;
259+
260+
if(len >= 2) {
261+
if(s[len - 2] == '\r' || s[len - 2] == '\n') {
262+
toRemove++;
263+
}
264+
}
265+
if(len >= 1) {
266+
if(s[len - 1] == '\r' || s[len - 1] == '\n') {
267+
toRemove++;
268+
}
269+
}
270+
271+
if(toRemove) {
272+
s.erase(len - toRemove);
273+
}
274+
}
253275
}

util/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ std::string format(const char *formatStr, double value);
3535
std::string format(uint32_t value);
3636
std::string format(uint64_t value);
3737
std::string format(int value);
38+
void removeNewline(std::string &s);
3839

3940
}
4041

0 commit comments

Comments
 (0)