|
Boost Users : |
Subject: Re: [Boost-users] [String_Ref] Working with other parts of boost
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2013-11-17 20:36:55
On Nov 17, 2013, at 11:47 AM, Norbert Wenzel <norbert.wenzel.lists_at_[hidden]> wrote:
> Hi,
>
> I wanted to play around with Boost.String_Ref and found some old code that I thought would be the ideal case for string_refs. It's basically a config file reader that stores the whole line and also a key/value pair that may be found in that line. So a single line looked something like this:
>
> std::string line; //original line as is in the file
> boost::string_ref key; //extracted key subpart
> boost::string_ref value; //extracted value subpart
>
>
> But when I wanted to trim the string_refs (eg. for lexical_casting them) I got compile errors, because boost::trim uses erase, which of course is not supported by string_ref. But string_ref has the remove_prefix/suffix member functions, which would be exactly what trim needs. So I quickly hacked an additional overload of trim_*_if that calls the remove_*fix instead of the .erase() member function and it seemed to work.
>
>
> The second problem occurred when I tried to extract my key/value pair from a line using the Tokenizer, which seems to be old, but it still works for simple cases. Tokenizer internally uses assign() to fill an internal buffer with the next token, which of course is no member function of string_ref. Since it seems Tokenizer only uses the assign version that takes two iterators it might be possible to add such an assign() function to string_ref. At least I added one as a testcase locally and it worked in my limited testcase.
>
>
> Are there any plans to add either trim() or Tokenizer support for string_ref? I'm not sure about the Tokenizer/assign stuff, since one would have to change string_ref but I really think the trim() support would be helpful. Anyway, these issues kept me from actually using string_ref, since the code did not compile (or required changes to boost headers in order to compile). And I did not want to redo some of the boost string algorithm stuff in order to use string_refs.
When I get some free time - maybe over the holidays, I'll be taking a long look at Boost.Algorirthm's string algorithm section, and seeing what I can do to make them work with string_ref. They're very general algorithms; I wonder how many people actually call them with anything other that std::string (and other specializations of std::basic_string)
Anyone? Anyone? Bueller?
-- Marshall
Marshall Clow Idio Software <mailto:mclow.lists_at_[hidden]>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
-- Yu Suzuki
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net