Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / filters / EliminateWhiteSpaces / EliminateWhiteSpaces.groovy @ 1000

History | View | Annotate | Download (2 kB)

1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.scripts.filters.EliminateWhiteSpaces;
29

    
30
import org.txm.importer.scripts.filters.*;
31
import java.util.regex.*;
32

    
33
// TODO: Auto-generated Javadoc
34
/**
35
 * The Class EliminatingWhiteSpaces.
36
 */
37
class EliminatingWhiteSpaces extends Filter {
38
        
39
        /** The counter. */
40
        int counter;
41
        
42
        /** The old. */
43
        def old;
44

    
45
        /* (non-Javadoc)
46
         * @see org.txm.importer.filters.Filter#SetUsedParam(java.lang.Object)
47
         */
48
        void SetUsedParam(Object args) {
49

    
50
        }
51

    
52
        /* (non-Javadoc)
53
         * @see org.txm.importer.filters.Filter#before()
54
         */
55
        boolean before() {
56
                counter = 0;
57
        }
58

    
59
        /* (non-Javadoc)
60
         * @see org.txm.importer.filters.Filter#after()
61
         */
62
        void after()
63
        {
64
                println "Deleted $counter whitespaces \n";
65
        }
66

    
67
        /* (non-Javadoc)
68
         * @see org.txm.importer.filters.Filter#filter()
69
         */
70
        void filter()
71
        {
72
                def m;
73
                def segment;
74
                // Write your code here, but don't forget to write in the output
75
                // ex : output.write("TheStringToWrite " + line );
76
                // in the var line is the current line
77
                old = line;
78
                line = (line =~ /\s+<\/w>/).replaceAll("<\\/w>");
79

    
80
                if( old != line)
81
                        counter++;
82
                
83
                output.write(line+lineSeparator);
84
                // End
85
        }
86
}