[Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Wed, Sep 26, 2001 at 01:35:38AM -0400, Justin Moore wrote:
>
> > > > What about a strdup() in split?
> > >
> > > I could, but I really think all memory allocation and de-allocation
> > > should be done at the same level, so-to-speak.
> >
> > What is the problem? split() will strdup() the string it gets and
> > frees it copy later.
>
> char *buf = " foo bar ";
> char *args[2];
> int found = split("\S", buf, args, 2);
>
> If, within split, I do
> char *copybuf = strdup(buf);
> and mess around with copybuf, I'm going to parse away the first few chars
> of it. args[0] != copybuf, since I've cut away the first few characters.
> How will I know what to free?
I was thinking of that split() will free the copybuf.
> > > On a side note, I'm going to remove the "automatically removes
> > > whitespace" implementation, and require the caller to pass a "\S" as a
> > > token if they want to split on whitespace. If they want to remove
> > > whitespace surrounding other split tokens, they would pass in a "\s". A
> > > "\S" implies "\s".
> > >
> > > split("\s,", buf, args, 5);
> > >
> > > will correctly parse
> > >
> > > Alphabet,Iron Working,Pottery, The Wheel
> > >
> > > Comments?
> >
> > I would rather like to see this explicitly as an argument of split.
>
> I think it's cleaner to keep fewer arguments. I don't want this
> turning into MFCs, where you have to pass 17 NULLs or 0s into a function
> to get it right. ;p Just know some basic regex patters and it works.
Then make a
enum split_flags {
REMOVE_SPLIT_ON_WS=1,
REMOVE_REMOVE_WS=2
};
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"On the eigth day, God started debugging"
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, (continued)
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Reinier Post, 2001/09/20
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Justin Moore, 2001/09/22
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Raimar Falke, 2001/09/22
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Justin Moore, 2001/09/22
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Raimar Falke, 2001/09/23
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Justin Moore, 2001/09/23
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Raimar Falke, 2001/09/24
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Justin Moore, 2001/09/24
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Raimar Falke, 2001/09/25
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Justin Moore, 2001/09/26
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs),
Raimar Falke <=
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Justin Moore, 2001/09/26
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/26
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Raimar Falke, 2001/09/27
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/27
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Reinier Post, 2001/09/28
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/28
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Reinier Post, 2001/09/30
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/30
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Raimar Falke, 2001/09/28
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/28
|
|