Skip to content

Commit 2a58400

Browse files
theuniJeff Garzik
authored andcommitted
core_read's ParseScript(): minor cleanups
- use .empty() rather than .size() == 0 - use a const_iterator rather than BOOST_FOREACH - validate iterators before creating a string from them
1 parent b2aeaa7 commit 2a58400

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/core_read.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ CScript ParseScript(std::string s)
2121

2222
static map<string, opcodetype> mapOpNames;
2323

24-
if (mapOpNames.size() == 0)
24+
if (mapOpNames.empty())
2525
{
2626
for (int op = 0; op <= OP_NOP10; op++)
2727
{
@@ -43,36 +43,36 @@ CScript ParseScript(std::string s)
4343
vector<string> words;
4444
split(words, s, is_any_of(" \t\n"), token_compress_on);
4545

46-
BOOST_FOREACH(string w, words)
46+
for (std::vector<std::string>::const_iterator w = words.begin(); w != words.end(); ++w)
4747
{
48-
if (w.size() == 0)
48+
if (w->empty())
4949
{
5050
// Empty string, ignore. (boost::split given '' will return one word)
5151
}
52-
else if (all(w, is_digit()) ||
53-
(starts_with(w, "-") && all(string(w.begin()+1, w.end()), is_digit())))
52+
else if (all(*w, is_digit()) ||
53+
(starts_with(*w, "-") && all(string(w->begin()+1, w->end()), is_digit())))
5454
{
5555
// Number
56-
int64_t n = atoi64(w);
56+
int64_t n = atoi64(*w);
5757
result << n;
5858
}
59-
else if (starts_with(w, "0x") && IsHex(string(w.begin()+2, w.end())))
59+
else if (starts_with(*w, "0x") && (w->begin()+2 != w->end()) && IsHex(string(w->begin()+2, w->end())))
6060
{
6161
// Raw hex data, inserted NOT pushed onto stack:
62-
std::vector<unsigned char> raw = ParseHex(string(w.begin()+2, w.end()));
62+
std::vector<unsigned char> raw = ParseHex(string(w->begin()+2, w->end()));
6363
result.insert(result.end(), raw.begin(), raw.end());
6464
}
65-
else if (w.size() >= 2 && starts_with(w, "'") && ends_with(w, "'"))
65+
else if (w->size() >= 2 && starts_with(*w, "'") && ends_with(*w, "'"))
6666
{
6767
// Single-quoted string, pushed as data. NOTE: this is poor-man's
6868
// parsing, spaces/tabs/newlines in single-quoted strings won't work.
69-
std::vector<unsigned char> value(w.begin()+1, w.end()-1);
69+
std::vector<unsigned char> value(w->begin()+1, w->end()-1);
7070
result << value;
7171
}
72-
else if (mapOpNames.count(w))
72+
else if (mapOpNames.count(*w))
7373
{
7474
// opcode, e.g. OP_ADD or ADD:
75-
result << mapOpNames[w];
75+
result << mapOpNames[*w];
7676
}
7777
else
7878
{

0 commit comments

Comments
 (0)