compilation: fix std::find() == 0 misuse

cppcheck correctly warns about the old code as less efficient (looks
at entire string instead of just the start). Using boost::starts_with
is less obscure and avoids the warning.
This commit is contained in:
Patrick Ohly 2016-08-29 04:52:49 -07:00
parent f7dbb2ed72
commit d560aeda07
3 changed files with 3 additions and 3 deletions

View File

@ -306,7 +306,7 @@ void Session::setNamedConfig(const std::string &configName,
/** generate new sources in the config map */
for (ReadOperations::Config_t::const_iterator it = config.begin(); it != config.end(); ++it) {
string sourceName = it->first;
if(sourceName.find("source/") == 0) {
if (boost::starts_with(sourceName, "source/")) {
sourceName = sourceName.substr(7); ///> 7 is the length of "source/"
from->getSyncSourceNodes(sourceName);
}

View File

@ -198,7 +198,7 @@ bool Cmdline::parse(vector<string> &parsed)
m_template = m_argv[opt];
m_configure = true;
string temp = boost::trim_copy (m_template);
if (temp.find ("?") == 0){
if (boost::starts_with(temp, "?")) {
m_printTemplates = true;
m_dontrun = true;
m_template = temp.substr (1);

View File

@ -1691,7 +1691,7 @@ boost::shared_ptr<TransportAgent> SyncContext::createTransportAgent(void *gmainl
InitializeTransport(agent, timeout);
return agent;
#endif
} else if (url.find("obex-bt://") ==0) {
} else if (boost::starts_with(url, "obex-bt://")) {
#ifdef ENABLE_BLUETOOTH
std::string btUrl = url.substr (strlen ("obex-bt://"), std::string::npos);
boost::shared_ptr<ObexTransportAgent> agent(new ObexTransportAgent(ObexTransportAgent::OBEX_BLUETOOTH,