aboutsummaryrefslogtreecommitdiff
path: root/src/core_read.cpp
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2014-06-23 19:32:54 -0400
committerJeff Garzik <jgarzik@bitpay.com>2014-07-29 11:13:27 -0400
commit2a5840096fd3b6235a4ff4b8488f8d4494414765 (patch)
treedfe49dad65c52ef87e2c5111ac432853a788daf9 /src/core_read.cpp
parentb2aeaa79393608132104183eba117fcbf583148e (diff)
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
Diffstat (limited to 'src/core_read.cpp')
-rw-r--r--src/core_read.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/core_read.cpp b/src/core_read.cpp
index d5d3cca480..1ecd6db324 100644
--- a/src/core_read.cpp
+++ b/src/core_read.cpp
@@ -21,7 +21,7 @@ CScript ParseScript(std::string s)
static map<string, opcodetype> mapOpNames;
- if (mapOpNames.size() == 0)
+ if (mapOpNames.empty())
{
for (int op = 0; op <= OP_NOP10; op++)
{
@@ -43,36 +43,36 @@ CScript ParseScript(std::string s)
vector<string> words;
split(words, s, is_any_of(" \t\n"), token_compress_on);
- BOOST_FOREACH(string w, words)
+ for (std::vector<std::string>::const_iterator w = words.begin(); w != words.end(); ++w)
{
- if (w.size() == 0)
+ if (w->empty())
{
// Empty string, ignore. (boost::split given '' will return one word)
}
- else if (all(w, is_digit()) ||
- (starts_with(w, "-") && all(string(w.begin()+1, w.end()), is_digit())))
+ else if (all(*w, is_digit()) ||
+ (starts_with(*w, "-") && all(string(w->begin()+1, w->end()), is_digit())))
{
// Number
- int64_t n = atoi64(w);
+ int64_t n = atoi64(*w);
result << n;
}
- else if (starts_with(w, "0x") && IsHex(string(w.begin()+2, w.end())))
+ else if (starts_with(*w, "0x") && (w->begin()+2 != w->end()) && IsHex(string(w->begin()+2, w->end())))
{
// Raw hex data, inserted NOT pushed onto stack:
- std::vector<unsigned char> raw = ParseHex(string(w.begin()+2, w.end()));
+ std::vector<unsigned char> raw = ParseHex(string(w->begin()+2, w->end()));
result.insert(result.end(), raw.begin(), raw.end());
}
- else if (w.size() >= 2 && starts_with(w, "'") && ends_with(w, "'"))
+ else if (w->size() >= 2 && starts_with(*w, "'") && ends_with(*w, "'"))
{
// Single-quoted string, pushed as data. NOTE: this is poor-man's
// parsing, spaces/tabs/newlines in single-quoted strings won't work.
- std::vector<unsigned char> value(w.begin()+1, w.end()-1);
+ std::vector<unsigned char> value(w->begin()+1, w->end()-1);
result << value;
}
- else if (mapOpNames.count(w))
+ else if (mapOpNames.count(*w))
{
// opcode, e.g. OP_ADD or ADD:
- result << mapOpNames[w];
+ result << mapOpNames[*w];
}
else
{