diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-02-05 19:23:47 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-02-05 19:23:47 +0300 |
commit | 70e8eb54ce75feb0a7d4ed00d275e56652c0a914 (patch) | |
tree | 12c24aa2bb927729d109e24fe6c4da12cabec172 /moses/Parameter.cpp | |
parent | 53afe08da7dd2b8edb8c0c2fcc500814d806e4fc (diff) |
Using boost for prefix/suffix checks /Jeroen Vermeulen
Diffstat (limited to 'moses/Parameter.cpp')
-rw-r--r-- | moses/Parameter.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/moses/Parameter.cpp b/moses/Parameter.cpp index cd9d3b289..c5677b73b 100644 --- a/moses/Parameter.cpp +++ b/moses/Parameter.cpp @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include <fstream> #include <sstream> #include <algorithm> +#include <boost/algorithm/string/predicate.hpp> #include "Parameter.h" #include "Util.h" #include "InputFileStream.h" @@ -32,6 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "util/exception.hh" using namespace std; +using namespace boost::algorithm; namespace Moses { @@ -270,8 +272,9 @@ bool Parameter::isOption(const char* token) if (! token) return false; std::string tokenString(token); size_t length = tokenString.size(); - if (length > 0 && tokenString.substr(0,1) != "-") return false; - if (length > 1 && tokenString.substr(1,1).find_first_not_of("0123456789") == 0) return true; + if (length <= 1) return false; + if (!starts_with(tokenString, "-")) return false; + if (tokenString.substr(1,1).find_first_not_of("0123456789") == 0) return true; return false; } @@ -975,7 +978,7 @@ void Parameter::WeightOverwrite() for (size_t i = 0; i < toks.size(); ++i) { const string &tok = toks[i]; - if (tok.substr(tok.size() - 1, 1) == "=") { + if (starts_with(tok, "=")) { // start of new feature if (name != "") { |