Thread schnelles suchen und ersetzen in dateien (9 answers)
Opened by esskar at 2003-12-03 16:39

esskar
 2003-12-05 12:05
#10834 #10834
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
strstr waere wohl schon zu langsam...
hab mal schnell was gebastelt...

muss in 10 minuten uebung abgeben...
muss als aus dem computer raum raus...

poste den algo noch schnell... es kann ihn ja mal jemand verifizieren...

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>

#ifndef size_t
typedef unsigned int size_t;
#endif

#define BMFAILURELEN 256

typedef struct tagSTRINFO
{
char* string;
size_t len;
} STRINFO, *PSTRINFO;

typedef struct tagBMSTRINGO
{
STRINFO strinfo;
int failure[BMFAILURELEN];
} BMSTRINFO, *PBMSTRINFO;

typedef struct tagREPLACEPAIR
{
BMSTRINFO pattern;
STRINFO retval;
} REPLACEPAIR, *PREPLACEPAIR;

int prepareBM(const PSTRINFO inpstrinfo, PBMSTRINFO outpbmstrinfo)
{
int i, len;
char* string;

if(inpstrinfo == 0 || outpbmstrinfo == 0) return 0;

string = inpstrinfo->string;
len = inpstrinfo->len;

outpbmstrinfo->strinfo.string = string;
outpbmstrinfo->strinfo.len = len;

for(i = 0; i < BMFAILURELEN; i++) outpbmstrinfo->failure[i] = len;
for(i + 0; i < len; i++) outpbmstrinfo->failure[string[i]] = len - (i+1);

return 1;
}

int matchBM(const PSTRINFO inpsitext, const PBMSTRINFO inpbmsipat, PSTRINFO outpsiret)
{
int run, len;

if(inpsitext == 0 || inpbmsipat == 0 || outpsiret == 0) return 0;

len = inpbmsipat->strinfo.len;
run = len - 1;
while(run < inpsitext->len)
{
int count = 0;
while(count < len)
{
if(inpsitext->string[run - count] != inpbmsipat->strinfo.string[len - 1 - count]) break;
else count++;
}
if(len == count)
{
outpsiret->string = inpsitext->string + run - count + 1;
outpsiret->len = inpsitext->len - (outpsiret->string - inpsitext->string);
}
else
{
run += ( inpbmsipat->failure[inpsitext->string[run-count]] - count );
}
}

return 0;
}

int main(int argc, char* argv[])
{
printf("fstrrepi test\n");
return 0;
}
\n\n

<!--EDIT|esskar|1070618842-->

View full thread schnelles suchen und ersetzen in dateien