[cfe-dev] [patch] Add configure option for C include search path

Daniel Dunbar daniel at zuster.org
Wed Nov 11 11:03:38 PST 2009


On Wed, Nov 11, 2009 at 10:25 AM, Rafael Espindola <espindola at google.com> wrote:
>> I want to kill StringExtras.h. I would propose implementing split() on
>> StringRef, with a KeepEmpty argument (which should default to true).
>> Python's MaxSplit is also incredibly useful. See PCHReader:splitLines
>> for the StringRef version of this.
>>
>> The only caveat is this can't import std::vector, because StringRef.h
>> is everywhere and we want to keep its includes as minimal as possible.
>
> I just noticed your work on StringRef spilt. My current idea is to implement a
>
> std::vector<StringRef> SplitAll(StringRef str, StringRef delimiters)
>
> Would this be ok if I put the declaration in a header other then
> StringRef.h and the definition in a .cpp file?

If we can put the implementation on StringRef (without pulling in more
headers), I personally think it is a lot nicer to have such methods on
a class rather than as random utility functions. The problem with
utility functions is people frequently reimplement them because they
aren't aware of them, and they are more of a pain to use -- StringRef
has already killed a lot of instances of this.

What about this:
--
namespace std {
  template<typename _Tp>
  class allocator;

  template<typename _Tp, typename _Alloc>
  class vector;
}

class StringRef {
...
public:
...
  void split(std::vector<StringRef, std::allocator<StringRef> > &A,
             StringRef Separators, unsigned MaxSplit = 0, bool
KeepEmpty = false);
...
};
--
(or the SmallVector version of the same)

I prefer having a MaxSplit argument, which is easier to support, than
making SplitAll.

 - Daniel

> I still think that the SplitString in StringExtrans.h should be called
> something else, but if it is going away that is better :-)
>
>>  - Daniel
>
>
> Cheers,
> --
> Rafael Ávila de Espíndola
>




More information about the cfe-dev mailing list