[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]
I suppose I'm duplicating effort a little, but what do people think of
this split function?
char ** splitprotect(char* string,char* on){
int i,j,n=0,l=strlen(string),q=0,b=0;
char** out;
for(i=0;i<l;i++){
if (string[i]=='"')
q=!q;
if (q)
continue;
if (string[i]=='{'){
b++;
continue;
}
if (string[i]=='}'){
b--;
continue;
}
if (!b){
for(j=0;j<strlen(on);j++){
if (string[i]==on[j]){
string[i]=0;
n++;
}
}
}
}
out=(char**)malloc((n+2)*sizeof(char*));
*out=string;
j=1;
for(i=0;i<l;i++){
if (!string[i])
out[j++]=string+i+1;
}
out[n+1]=0;
return(out);
}
It doesn't do regexps, but I don't think we'll need them. It does handle
multiple split characters. It only allocates memory for the specific
array it returns, and it does mangle the input string. I think this is
the function I would want if I were writing the entire parser. If not,
well, I didn't put all that much work into it anayway :)
--Daniel Speyer
"May the /src be with you, always"
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), (continued)
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Justin Moore, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Raimar Falke, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Arien Malec, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Raimar Falke, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Arien Malec, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Raimar Falke, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Daniel L Speyer, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Raimar Falke, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Daniel L Speyer, 2001/10/22
- [Freeciv-Dev] Re: Server Overhaul (was Re: Re: Split patch), Justin Moore, 2001/10/22
[Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs),
Daniel L Speyer <=
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Raimar Falke, 2001/10/05
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Reinier Post, 2001/10/06
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Daniel L Speyer, 2001/10/06
- [Freeciv-Dev] semi-static typing in server config (was: Re: Split patch (was Re: [RFC PATCH] init_techs)), Daniel L Speyer, 2001/10/08
- [Freeciv-Dev] Re: semi-static typing in server config (was: Re: Split patch (was Re: [RFC PATCH] init_techs)), Raimar Falke, 2001/10/08
|
|