1 #include <qtextstream.h>
4 ///////////////////////////////////////////////////////////
6 // (c) Kevin Krammer <kevin.krammer@gmx.at>
10 // automatically extracts a structure from
11 // http://www.loc.gov/standards/iso639-2/englangn.html
13 // see also extractlang.README
15 ///////////////////////////////////////////////////////////
20 void parseLanguage(QString name
, QString three
, QString two
)
22 int star
= three
.find('*');
24 three
.remove(star
, 1);
26 QString three_1
= three
;
28 int slash
= three_1
.find('/');
30 three_1
.remove(slash
, 1);
31 three_1
.insert(slash
, ", ");
34 if (!two
.contains(" ")) {
35 twoLangs
.append("\t{{\"");
37 twoLangs
.append("\"}, {\"");
38 twoLangs
.append(three_1
);
39 twoLangs
.append("\"}, {I18N_NOOP(\"");
40 twoLangs
.append(name
);
41 twoLangs
.append("\")}},\n");
46 slash
= three
.find('/');
48 if (two
.length() == 0)
49 two
= three
.mid(slash
+1);
50 three
.remove(slash
, three
.length());
53 threeLangs
.append("\t{{\"");
54 threeLangs
.append(two
);
55 threeLangs
.append("\"}, {\"");
56 threeLangs
.append(three
);
57 threeLangs
.append("\"}, {I18N_NOOP(\"");
58 threeLangs
.append(name
);
59 threeLangs
.append("\")}},\n");
62 QString
parseTD(QString
& line
)
64 QCString cline
= line
.local8Bit();
65 uint clineLength
= cline
.length();
66 QCString result
= cline
;
70 for (uint i
= 0; i
< clineLength
; ++i
)
74 else if (cline
[i
] == '>')
79 result
[pos
] = cline
[i
];
83 QString
retVal(result
);
84 retVal
= retVal
.left(pos
+1);
86 return retVal
.simplifyWhiteSpace();
89 bool parseTR(QString
& line
, QTextIStream
& in
)
99 while (line
.contains("<td"))
104 text
[count
] = parseTD(line
);
106 line
= in
.readLine();
111 parseLanguage(text
[0], text
[2], text
[3]);
114 if (line
.contains("/tr"))
123 bool readNext
= true;
125 QTextIStream
in(stdin
);
126 QTextOStream
out(stdout
);
131 line
= in
.readLine();
133 if (line
.contains("<tr"))
135 readNext
= parseTR(line
, in
);
141 out
<< "struct KV_ISO639_Code {\n"
142 " const char *iso1code;\n"
143 " const char *iso2code;\n"
144 " const char *langname;\n"
148 out
<< "KV_ISO639_Code kv_iso639_1[] = {\n"
149 << twoLangs
.left(twoLangs
.length()-1) << endl
150 << "\t{{0}, {0}, {0}}\n"
155 out
<< "KV_ISO639_Code kv_iso639_2[] = {\n"
156 << threeLangs
.left(threeLangs
.length()-1) << endl
157 <<"\t{{0}, {0}, {0}}\n"