Would an easier fix be to simply replace
s += "\n";
with
s += delimstr[0];

- Noel

On 2 July 2011 21:51, Jiahao Chen <jia...@mit.edu> wrote:
> Hi all,
>
> I am currently implementing some changes to the MOPAC file format
> reader which requires use of the tokenize() function (the variant that
> takes 3 inputs) in tokenst.cpp.
>
> However, this appears to contain a bug where the last token is
> sometimes not parsed:
>
> tokenize(vs, "a.b.", ".") results in vs.size()=2, vs[0] = "a", vs[1] = "b"
> but tokenize(vs, "a.b", ".") results in vs.size()=1, vs[0] = "a" only.
>
> I have a patch that will fix this behavior sufficiently for my
> purposes. I would like to commit this upstream, but I thought I would
> ask first since this would modify a core utility function and could
> very well break code that expects this behavior.
>
> ===================================================================
> --- tokenst.cpp (revision 4519)
> +++ tokenst.cpp (working copy)
> @@ -43,14 +43,20 @@
>     string s(buf);
>     s += "\n";
>     size_t startpos=0,endpos=0;
> +    size_t s_size = s.size();
>
>     for (;;)
>       {
>         startpos = s.find_first_not_of(delimstr,startpos);
>         endpos = s.find_first_of(delimstr,startpos);
>
> -        if (endpos <= s.size() && startpos <= s.size())
> +        if (endpos <= s_size && startpos <= s_size)
>           vcr.push_back(s.substr(startpos,endpos-startpos));
> +       else if (startpos < s_size) //process last token - cjh 2011-07-02
> +       {
> +          vcr.push_back(s.substr(startpos,s_size-startpos));
> +         break;
> +       }
>         else
>           break;
>
> Thanks,
>
>  · Jiahao Chen · MIT Chemistry ·
>
> ------------------------------------------------------------------------------
> All of the data generated in your IT infrastructure is seriously valuable.
> Why? It contains a definitive record of application performance, security
> threats, fraudulent activity, and more. Splunk takes this data and makes
> sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-d2d-c2
> _______________________________________________
> OpenBabel-Devel mailing list
> OpenBabel-Devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openbabel-devel
>

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel

Reply via email to