Revision: 70728 http://sourceforge.net/p/brlcad/code/70728 Author: starseeker Date: 2018-02-22 19:08:06 +0000 (Thu, 22 Feb 2018) Log Message: ----------- handle comments better
Modified Paths: -------------- brlcad/trunk/src/libanalyze/nirt.cxx Modified: brlcad/trunk/src/libanalyze/nirt.cxx =================================================================== --- brlcad/trunk/src/libanalyze/nirt.cxx 2018-02-22 16:43:54 UTC (rev 70727) +++ brlcad/trunk/src/libanalyze/nirt.cxx 2018-02-22 19:08:06 UTC (rev 70728) @@ -403,6 +403,18 @@ return substrs; } +HIDDEN void +_nirt_trim_whitespace(std::string &s) +{ + size_t ep = s.find_last_not_of(" \t"); + size_t sp = s.find_first_not_of(" \t"); + if (sp == std::string::npos) { + s.clear(); + return; + } + s = s.substr(sp, ep+1); +} + #if 0 HIDDEN std::string _nirt_dbl_to_str(double d) @@ -2629,7 +2641,7 @@ int i = 0; int ret = 0; char **av = NULL; - size_t q_start, q_end, pos; + size_t q_start, q_end, pos, cmt; std::string entry; if (!ns || !cmdstr || strlen(cmdstr) > entry.max_size()) return -1; std::string s(cmdstr); @@ -2639,6 +2651,15 @@ ss.clear(); ss.seekg(0, ss.beg); + /* If part of the line is commented, skip that part */ + cmt = _nirt_find_first_unescaped(s, "#", 0); + if (cmt != std::string::npos) { + s.erase(cmt); + } + + _nirt_trim_whitespace(s); + if (!s.length()) return 0; + /* Start by initializing the position markers for quoted substrings. */ q_start = _nirt_find_first_unescaped(s, "\"", 0); q_end = (q_start != std::string::npos) ? _nirt_find_first_unescaped(s, "\"", q_start + 1) : std::string::npos; @@ -2695,12 +2716,16 @@ std::string cmd; struct bu_vls tcmd = BU_VLS_INIT_ZERO; size_t pos = 0; - size_t q_start, q_end; + size_t q_start, q_end, cmt; - /* TODO - eat leading whitespace, potentially masking a comment char */ + /* If part of the line is commented, skip that part */ + cmt = _nirt_find_first_unescaped(s, "#", 0); + if (cmt != std::string::npos) { + s.erase(cmt); + } - /* If this line is a comment, we're done */ - if (script[0] == '#') return 0; + _nirt_trim_whitespace(s); + if (!s.length()) return 0; /* Start by initializing the position markers for quoted substrings. */ q_start = _nirt_find_first_unescaped(s, "\"", 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits