Einzelnen Beitrag anzeigen

new32

Registriert seit: 10. Mai 2005
160 Beiträge
 
Delphi 7 Enterprise
 
#18

Re: %20 in Leerzeichen Umwandeln

  Alt 2. Jul 2006, 20:44
Hi!
Ich hab auch mal ne Lösung für das Problem in 6 Minuten geschrieben(leider C)
kann aber nach veränderungen als dll kompiliert werden und auch in delphi-programmen genutzt werden.

Code:
#include<stdio.h>
#include<string.h>

int itoaY(int i, char *a, int z){
  int v=1,w=0;
  while(i/v>=1) v*=z;v/=z;
  while(v>=1) a[w]=i/v,i-=a[w]*v,a[w]+=(a[w]<=9)?'0':'A'-10,w++,v/=z;
  a[w++]='\0';
  return w;
}

int copy(char *x, char *y){
int i=0;
while(y[i]!='\0') x[i]=y[i++];
x[i+1]='\0';
return i;
}

int cmp(char *a1, char *a2, int n){
  int i;
  i=0;
  while(i<=n-1){
    if(a1[i]!=a2[i]) return i+1;
    i++;
  }
  return 0;
}

int cpy(char *a1, char *a2, int n){
  int i;
  i=0;
  while(i<=n){
    a1[i]=a2[i];
    i++;
  }
  return i;
}

int setlen(char *s, char *dest, int olen, int nlen, char null){
  olen-=nlen;
  while(nlen>=0) (dest[nlen]=(nlen+olen>=0)?s[nlen+olen]:null),nlen--;
  return 0;
}

void C(char c[192][8]){
  int i,j;
  for(i=j=0;i<256;i++,j++){
    i=(i<1)?1:(i==32)?33:(i==47)?58:(i==65)?91:(i==97)?123:i;
    c[j][0]=i;
    c[j][7]=1;
  }
  c[j][0]=' ';
  c[j][7]=1;
}

void URL(char url[192][8]){
  int i,j;
  char t[4];
  for(i=j=0;i<256;i++,j++){
    i=(i<1)?1:(i==32)?33:(i==47)?58:(i==65)?91:(i==97)?123:i;
    url[j][0]='%';
    setlen(t,&(url[j][1]),itoaY(i,t,16),3,'0');
    url[j][7]=3;
  }
  url[127][1]='C';
  url[j][0]='+';
  url[j][7]=1;
}


void HTML(char html[192][8]){
  int i,j;
  for(i=j=0;i<256;i++,j++){
    i=(i<1)?1:(i==32)?33:(i==47)?58:(i==65)?91:(i==97)?123:i;
    html[j][0]='&';
    html[j][1]='#';
    html[j][7]=itoaY(i,&(html[j][2]),10)+2;
    html[j][html[j][7]-1]=';';
  }
  copy(html[9],"
"); html[9][7]=4;
  html[12][7]=0;

  copy(html[63],"&#8364;"); html[63][7]=7;

  copy(html[65],"&#8218;"); html[65][7]=7;
  copy(html[66],"&#402;"); html[66][7]=7;
  copy(html[67],"&#8222;"); html[67][7]=7;
  copy(html[68],"&#8230;"); html[68][7]=7;
  copy(html[69],"&#8224;"); html[69][7]=7;
  copy(html[70],"&#8225;"); html[70][7]=7;
  copy(html[71],"&#710;"); html[71][7]=7;
  copy(html[72],"&#8240;"); html[72][7]=7;
  copy(html[73],"&#352;"); html[73][7]=7;
  copy(html[74],"&#8249;"); html[74][7]=7;
  copy(html[75],"&#338;"); html[75][7]=7;

  copy(html[77],"&#381;"); html[77][7]=7;

  copy(html[80],"&#8216;"); html[80][7]=7;
  copy(html[81],"&#8217;"); html[81][7]=7;
  copy(html[82],"&#8220;"); html[82][7]=7;
  copy(html[83],"&#8221;"); html[83][7]=7;
  copy(html[84],"&#8226;"); html[84][7]=7;
  copy(html[85],"&#8211;"); html[85][7]=7;
  copy(html[86],"&#8212;"); html[86][7]=7;
  copy(html[87],"&#732;"); html[87][7]=7;
  copy(html[88],"&#8482;"); html[88][7]=7;
  copy(html[89],"&#353;"); html[89][7]=7;
  copy(html[90],"&#8250;"); html[90][7]=7;
  copy(html[91],"&#339;"); html[91][7]=7;

  copy(html[93],"&#382;"); html[93][7]=7;
  copy(html[94],"&#376;"); html[94][7]=7;

  html[j][0]=' ';
  html[j][7]=1;
}

int convert(char *in, char *out, void (*fin)(char [192][8]), void (*fout)(char [192][8])){
  int i,j,k=0;
  char io[2][192][8];

  fout(io[0]);
  fin(io[1]);
  for(i=0;in[i]!='\0';i++,k++){
    for(j=0;j<=191 && j!=-1;j++) if(!cmp(&(in[i]),io[1][j],io[1][j][7])) cpy(&(out[k]),io[0][j],io[0][j][7]),i+=io[1][j][7],k+=io[0][j][7],j=-1;
    if(j!=-1) out[k]=in[i];
  }
  out[k++]='\0';
  return k;
}

int GetParamElement(char *s, char *en, char *element){
  int i=0,lp,j=0;
  lp=strlen(en);
  while(cmp(&(s[i]),en,lp) && s[i]!='\0') i++; i+=lp;
  while(s[i]!='&' && s[i]!='\0') element[j++]=s[i++];
  element[j++]='\0';
  return j;
}

int GetParamElementC(char *s, char *en, char *element){
  int i=0,lp,j=0;
  lp=strlen(en);
  while(cmp(&(s[i]),en,lp) && s[i]!='\0') i++; i+=lp;
  while(s[j+i]!='&' && s[j+i]!='\0') j++;
  s[i+j]='\0';
  lp=convert(&(s[i]),element,URL,C);
  s[i+j]='&';
  return lp;
}

int GetParamElementHTML(char *s, char *en, char *element){
  int i=0,lp,j=0;
  lp=strlen(en);
  while(cmp(&(s[i]),en,lp) && s[i]!='\0') i++; i+=lp;
  while(s[j+i]!='&' && s[j+i]!='\0') j++;
  s[i+j]='\0';
  lp=convert(&(s[i]),element,URL,HTML);
  s[i+j]='&';
  return lp;
}

void incHTML(char *x) {
  char c[256];
  FILE *f;
  long l=0;
  if(f=fopen(x,"rb")){   
    while(!feof(f)){   
      fread(c,256,1,f);
      fwrite(c,ftell(f)-l,1,stdout);
      l+=256;
    }
  }
}

int main(void){                                  //Beispiel
  char d[256]="index.exe?pp=Hello+World%21%0A123&ff=11",v[256];

  GetParamElementHTML(d,"pp=",v);
  printf("%s",v);


  return 0;
}
sind noch nen paar Extras dabei(hab die ganze C-Datei kopiert!)

MfG NEW32!
~?&/%§$§%\&?~
8)
  Mit Zitat antworten Zitat