Thread Board-rewrite: allgemeine Ideen (44 answers)
Opened by jan10001 at 2003-08-25 00:08

Strat
 2003-08-26 15:40
#39388 #39388
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
Habe gerade mal einen Scanner fuer tags geschrieben, in denen nicht mehr weitere Ersetzungen vorgenommen werden (z.B. perl, code, perldoc) und die die Form haben
Code: (dl )
1
2
[perldoc]text[perldoc]
(also nicht: [perldoc=attribute]text[/perldoc]


Taugt der was? oder habe ich was uebersehen?
Code (perl): (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#! /usr/bin/perl
use warnings;
use strict;

use vars qw(@TagsBlocked);
@TagsBlocked = qw(perle codex perldocy);

&#36/ = undef;
my &#36posting = <DATA>;

&ParseText(&#36posting);
# ------------------------------------------------------------
sub ParseText {
    my (&#36text) = @_;

    my @scanned = ();

    foreach my &#36tag (@TagsBlocked) { # @scanned yet empty, start with &#36text
        unless (scalar (@scanned)) {
            @scanned = &PostFilterBlocked(&#36text, &#36tag);
        } # unless

        # @scanned filled, start scanning the rest
        else {
            my @scanned2 = (); # temporary variable
            foreach (@scanned) {
               
               
 # skip already scanned parts               
                push(@scanned2, &#36_), next if ref(&#36_); 

               
                # scan only if scalar
                push (@scanned2, &PostFilterBlocked(&#36_, &#36tag));

            } # foreach
            @scanned = @scanned2;
        } # else

    } # foreach

    use Data::Dumper;
    print "

", Dumper(\@scanned);

} # ParseText
# ------------------------------------------------------------
sub PostFilterBlocked {
    my (&#36text, &#36tag) = @_;

    my &#36startLength = length("[&#36tag]");
    my &#36endLength   = length("[/&#36tag]");

    my @scanned = ();
    
    my &#36startPos = index(&#36text, "[&#36tag]");
    my &#36lastPos = 0;
    
    print "
Scanning for tag [&#36tag]";
    while (&#36startPos != -1) {
        print " &#36startPos";

        # add leading part to @scanned
        my &#36string = substr(&#36text, &#36lastPos, &#36startPos-&#36lastPos);
        push (@scanned, &#36string) if length &#36string;
        
        # check if [&#36tag]...[/&#36tag]-block found
        &#36lastPos = index(&#36text, "[/&#36tag]", &#36startPos+&#36startLength);
        print "-&#36lastPos";
        unless (&#36lastPos == -1) { # if found

            # push reference to @scanned: { &#36tag => &#36string }
            my &#36string = substr(&#36text, &#36startPos+&#36startLength, 
                                &#36lastPos-&#36startPos-&#36startLength);
            push (@scanned, {&#36tag => &#36string}) if length &#36string;

        } # if

        else { # if not found

            # push rest of &#36text to @scanned (as string)
            my &#36string = substr(&#36text, &#36startPos, -1);

            # if last line was in @TagsBlocked, add new array element
            if (ref &#36scanned[-1]) {
               
 push (@scanned, &#36string) if length &#36string;
            }

            # if not, append as text to the last element
            else {
               
 &#36scanned[-1] .= &#36string;
            } # else

            last; # and exit while

        } # else

        # (re-)initialize next search position
        &#36lastPos += &#36endLength; 

        # search for next [tag]
        &#36startPos = index(&#36text, "[&#36tag]", &#36lastPos);

    } # while

    # care for rest of &#36text
    if (&#36lastPos != -1) {
        my &#36string = substr(&#36text, &#36lastPos, -1);
        push (@scanned, &#36string) if length(&#36string);
    } # if

    return @scanned;
} # PostFilterBlocked
# ------------------------------------------------------------

Hallo Leute,

das ist mein erstes Posting:
[perldocy]CGI[/perldocy]
[perle]
#! /usr/bin/perl
use warnings;
use strict;
use CGI ();
my &#36cgi = CGI->new();
[/perle]
und das ist was anderes:
[perldocy]CGI[/perldocy]
[perle]
#! /usr/bin/perl
use warnings;
use strict;
use CGI ();
my &#36cgi = CGI->new();
my &#36string = "[perldocy]CGI[/perldocy]";
[/perle]
normaltext
[codex]
#! /usr/bin/perl
use warnings;
use strict;
use CGI ();
my &#36cgi = CGI->new();
[/codex]
[perle] this is perl without finishing tag
[codex]
#! /usr/bin/perl
[/codex]


Habe perle, codex und perldocy genommen, damit mir das forum nicht dazwischenpfuscht...

<edit>hmmm, irgendwie mag [perl] diesen code nicht... \ n wird durch einen Zeilenumbruch ersetzt, die formatierung ist auch nicht das wahre... wenn jemand den code haben will, einfach eine mail schicken an martin@fabiani.net oder eine nachricht uebers forum\n\n

<!--EDIT|Strat|1061898246-->
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/

View full thread Board-rewrite: allgemeine Ideen