From ff4503585ca6e617014846f7ffd88dd0bdb84a32 Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Tue, 20 Oct 2015 16:37:38 +1000 Subject: [PATCH] Gmt module: Using Split instead of manual splitting. --- modules/gmt/modgmt_internals.cpp | 15 ++++++++------- modules/gmt/modgmt_structs.h | 31 +++++++++++++++---------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/modules/gmt/modgmt_internals.cpp b/modules/gmt/modgmt_internals.cpp index 3cbe5b5..732e887 100644 --- a/modules/gmt/modgmt_internals.cpp +++ b/modules/gmt/modgmt_internals.cpp @@ -98,7 +98,8 @@ bool ProjectionRealSize(struct gmt_projection& p, double height) std::string wh; double w,h; double sw=p.width; - size_t pos; + WordList wl; + WordList::const_iterator cw; gmtapi=GMT_Create_Session("ProjectionRealSize",2,GMTMODE,0); if(0==gmtapi) return false; @@ -108,12 +109,12 @@ bool ProjectionRealSize(struct gmt_projection& p, double height) GMT_Destroy_Session(gmtapi); if(0!=ret) return false; - pos=wh.find('\n'); - if(std::string::npos!=pos) wh.erase(pos); - pos=wh.find_first_of(" \t",0,2); - if(std::string::npos==pos) return false; - if(!str2double(std::string(wh.c_str(),wh.c_str()+pos),&w)) return false; - if(!str2double(wh.substr(pos+1),&h)) return false; + wl=Split(wh," \t\n"); + if(2!=wl.size()) return false; + cw=wl.begin(); + if(!str2double(*cw,&w)) return false; + cw++; + if(!str2double(*cw,&h)) return false; if(height>0.0) { p.width=height/h; diff --git a/modules/gmt/modgmt_structs.h b/modules/gmt/modgmt_structs.h index c232646..e163488 100644 --- a/modules/gmt/modgmt_structs.h +++ b/modules/gmt/modgmt_structs.h @@ -33,37 +33,36 @@ struct gmt_coord } bool Convert(const std::string& str) { - size_t bpos=0,pos=str.find(':'); - if(std::string::npos==pos) + WordList wl; + WordList::const_iterator cw; + wl=Split(str,":",true); + if(1==wl.size()) // No dd:mm { isdeg=false; return str2double(str,&r); } + if(0==wl.size() || wl.size()>3) return false; isdeg=true; int64_t res; // degrees - if(! str2int(std::string(str.c_str(),str.c_str()+pos),&res) ) return false; + cw=wl.begin(); + if(!str2int(*cw,&res)) return false; if(res>360 || res<-360) res%=360; - sign=(std::string::npos==str.find('-')); + sign=(std::string::npos==cw->find('-')); d=static_cast(sign?res:-res); // minutes - bpos=pos+1; - pos=str.find(':',bpos); - if(std::string::npos==pos) - { - if(!str2int(str.substr(bpos),&res)) return false; - if(res<0 || res>=60) return false; - m=static_cast(res); - s=0; - return true; - } - if(! str2int(std::string(str.c_str()+bpos,str.c_str()+pos),&res) ) return false; + cw++; + if(!str2int(*cw,&res)) return false; if(res<0 || res>=60) return false; m=static_cast(res); + s=0; + // seconds - if(! str2double(str.substr(pos+1),&s) ) return false; + cw++; + if(wl.end()==cw) return true; // No seconds + if(!str2double(*cw,&s) ) return false; if(s<0.0 || s>=60.0) return false; return true; }