kohyphentest.cpp
1//KoHyphenator test, Lukas Tinkl <lukas.tinkl@suse.cz>
2
3#include <stdio.h>
4#include <stdlib.h>
5
6#include <tqstringlist.h>
7
8#include <tdeapplication.h>
9
10#include "kohyphen.h"
11#include <kdebug.h>
12
13static bool check(TQString a, TQString b)
14{
15 if (a.isEmpty())
16 a = TQString();
17 if (b.isEmpty())
18 b = TQString();
19 if (a == b) {
20 kdDebug() << "checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
21 }
22 else {
23 kdDebug() << "checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
24 exit(1);
25 }
26 return true;
27}
28
29KoHyphenator * hypher = 0L;
30
31void check_hyphenation( const TQStringList& tests, const TQStringList& results, const char* lang )
32{
33 TQStringList::ConstIterator it, itres;
34 for ( it = tests.begin(), itres = results.begin(); it != tests.end() ; ++it, ++itres ) {
35 TQString result = hypher->hyphenate((*it), lang);
36 kdDebug() << (*it) << " hyphenates like this: " << result << endl;
37 check( result.replace(TQChar(0xad),'-'), *itres );
38 }
39}
40
41int main (int argc, char ** argv)
42{
43 TDEApplication app(argc, argv, "KoHyphenator test");
44
45 try {
46 hypher = KoHyphenator::self();
47 }
48 catch (KoHyphenatorException &e)
49 {
50 kdDebug() << e.message() << endl;
51 return 1;
52 }
53
54 TQStringList::ConstIterator it, itres;
55
56 //testing Czech language, this text is in UTF-8!
57 TQStringList cs_tests = TQStringList() << "Žluťoučký" << "kůň" << "úpěl" <<
58 "ďábelské" << "ódy";
59
60 for ( it = cs_tests.begin(); it != cs_tests.end() ; ++it )
61 kdDebug() << (*it) << " hyphenates like this: " << hypher->hyphenate((*it), "cs") << endl;
62
63 //testing English
64 TQStringList en_tests = TQStringList() << "Follow" << "white" << "rabbit";
65 TQStringList en_results = TQStringList() << "Fol-low" << "white" << "rab-bit";
66 check_hyphenation( en_tests, en_results, "en" );
67
68 TQStringList fr_tests = TQStringList() << "constitution" ;
69 TQStringList fr_results = TQStringList() << "consti-tu-tion" ;
70 check_hyphenation( fr_tests, fr_results, "fr" );
71
72 return 0;
73}
The KoHyphenator class provides an interface to the libhnj hyphenation library.
Definition kohyphen.h:56
static KoHyphenator * self()
Returns the single KoHyphenator instance (singleton pattern) Beware that this might throw an exceptio...
Definition kohyphen.cpp:41
TQString hyphenate(const TQString &str, const TQString &lang) const
Hyphenates the string str and returns the string with hyphenation marks in it.
Definition kohyphen.cpp:118