Skip to content

Commit fa03dec

Browse files
author
MarcoFalke
committed
refactor: Use C++11 range based for loop in ParseScript
1 parent fad55e7 commit fa03dec

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/core_read.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ CScript ParseScript(const std::string& s)
5959
std::vector<std::string> words;
6060
boost::algorithm::split(words, s, boost::algorithm::is_any_of(" \t\n"), boost::algorithm::token_compress_on);
6161

62-
for (std::vector<std::string>::const_iterator w = words.begin(); w != words.end(); ++w)
62+
for (const std::string& w : words)
6363
{
64-
if (w->empty())
64+
if (w.empty())
6565
{
6666
// Empty string, ignore. (boost::split given '' will return one word)
6767
}
68-
else if (std::all_of(w->begin(), w->end(), ::IsDigit) ||
69-
(w->front() == '-' && w->size() > 1 && std::all_of(w->begin()+1, w->end(), ::IsDigit)))
68+
else if (std::all_of(w.begin(), w.end(), ::IsDigit) ||
69+
(w.front() == '-' && w.size() > 1 && std::all_of(w.begin()+1, w.end(), ::IsDigit)))
7070
{
7171
// Number
72-
int64_t n = LocaleIndependentAtoi<int64_t>(*w);
72+
int64_t n = LocaleIndependentAtoi<int64_t>(w);
7373

7474
//limit the range of numbers ParseScript accepts in decimal
7575
//since numbers outside -0xFFFFFFFF...0xFFFFFFFF are illegal in scripts
@@ -80,23 +80,23 @@ CScript ParseScript(const std::string& s)
8080

8181
result << n;
8282
}
83-
else if (w->substr(0,2) == "0x" && w->size() > 2 && IsHex(std::string(w->begin()+2, w->end())))
83+
else if (w.substr(0,2) == "0x" && w.size() > 2 && IsHex(std::string(w.begin()+2, w.end())))
8484
{
8585
// Raw hex data, inserted NOT pushed onto stack:
86-
std::vector<unsigned char> raw = ParseHex(std::string(w->begin()+2, w->end()));
86+
std::vector<unsigned char> raw = ParseHex(std::string(w.begin()+2, w.end()));
8787
result.insert(result.end(), raw.begin(), raw.end());
8888
}
89-
else if (w->size() >= 2 && w->front() == '\'' && w->back() == '\'')
89+
else if (w.size() >= 2 && w.front() == '\'' && w.back() == '\'')
9090
{
9191
// Single-quoted string, pushed as data. NOTE: this is poor-man's
9292
// parsing, spaces/tabs/newlines in single-quoted strings won't work.
93-
std::vector<unsigned char> value(w->begin()+1, w->end()-1);
93+
std::vector<unsigned char> value(w.begin()+1, w.end()-1);
9494
result << value;
9595
}
9696
else
9797
{
9898
// opcode, e.g. OP_ADD or ADD:
99-
result << ParseOpCode(*w);
99+
result << ParseOpCode(w);
100100
}
101101
}
102102

0 commit comments

Comments
 (0)