Révision 3398
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/txt/CharListMacro.groovy (revision 3398) | ||
---|---|---|
1 |
package org.txm.macro.txt;
|
|
1 |
package org.txm.macro.txt |
|
2 | 2 |
// STANDARD DECLARATIONS |
3 | 3 |
|
4 | 4 |
import org.kohsuke.args4j.* |
5 | 5 |
import groovy.transform.Field |
6 | 6 |
import org.txm.rcp.swt.widget.parameters.* |
7 |
import java.text.Collator |
|
7 | 8 |
|
8 | 9 |
// BEGINNING OF PARAMETERS |
9 | 10 |
|
10 |
// Declare each parameter here
|
|
11 |
// (available widget types: Query, File, Folder, String, Text, Boolean, Integer, Float and Date)
|
|
11 |
@Field @Option(name="input_file", usage="Input file", widget="File", required=true, def="")
|
|
12 |
def input_file
|
|
12 | 13 |
|
13 |
@Field @Option(name="inputFile", usage="The file to read", widget="File", required=true, def="C:/Temp/foo.txt")
|
|
14 |
def inputFile
|
|
14 |
@Field @Option(name="language", usage="langage (FR, EN...) for alphabetical sort", widget="String", required=true, def="FR")
|
|
15 |
def language
|
|
15 | 16 |
|
17 |
@Field @Option(name="character_encoding", usage="Characters encoding (see ListEncodings for a list of available encodings)", widget="String", required=true, def="UTF-8") |
|
18 |
def character_encoding |
|
19 |
|
|
16 | 20 |
// Open the parameters input dialog box |
17 |
if (!ParametersDialog.open(this)) return;
|
|
21 |
if (!ParametersDialog.open(this)) return |
|
18 | 22 |
|
19 | 23 |
// END OF PARAMETERS |
20 | 24 |
|
21 |
String s = inputFile.getText() |
|
25 |
def collator = Collator.getInstance(new Locale(language)) |
|
26 |
collator.setStrength(Collator.TERTIARY) |
|
22 | 27 |
|
28 |
def s = input_file.getText(character_encoding) |
|
29 |
|
|
23 | 30 |
def dic = [:] |
24 | 31 |
|
25 | 32 |
for (char c : s) { |
... | ... | |
27 | 34 |
dic[c]++ |
28 | 35 |
} |
29 | 36 |
|
30 |
for (def e : dic) { println(sprintf("%c\t%d", [e.getKey(), e.getValue()])) } |
|
37 |
def keys = dic.keySet().collect { it.toString() } |
|
38 |
Collections.sort(keys, collator) |
|
39 |
|
|
40 |
def specials = [java.lang.Character.UNASSIGNED, java.lang.Character.SPACE_SEPARATOR, java.lang.Character.CONTROL, java.lang.Character.FORMAT, java.lang.Character.PRIVATE_USE, java.lang.Character.SURROGATE] |
|
41 |
|
|
42 |
for (def k : keys) { |
|
43 |
|
|
44 |
character = k.charAt(0) |
|
45 |
codepoint = k.codePointAt(0) |
|
46 |
type = Character.getType(codepoint) |
|
47 |
|
|
48 |
if (!specials.contains(type as byte)) println sprintf("%s\t%d", k, dic.get(character)) |
|
49 |
} |
|
50 |
|
|
51 |
for (def k : keys) { |
|
52 |
|
|
53 |
character = k.charAt(0) |
|
54 |
codepoint = k.codePointAt(0) |
|
55 |
type = Character.getType(codepoint) |
|
56 |
|
|
57 |
if (specials.contains(type as byte)) println sprintf("%s\t%d", Character.getName(codepoint), dic.get(character)) |
|
58 |
} |
|
59 |
|
Formats disponibles : Unified diff