summaryrefslogtreecommitdiffstats
path: root/libtdepim/tests/testutf7encoder.cpp
blob: 46fbd4d84a500ccded6d67159aebe1bcdfe3c14a (plain)
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
#include "qutf7codec.h"
#include "qutf7codec.cpp"
#include <iostream.h>
#include <string.h>

void main( int argc, char * argv[] ) {
  if ( argc == 2 ) {
    TQUtf7Codec * codec = new TQUtf7Codec;

    TQTextEncoder * enc;

    TQString arg = TQString::fromLatin1( argv[1] );
    int len;

    cout << "Original string:\n"
	 << "\"" << argv[1] << "\"\n" << endl;

    cout << "Encode optional direct set and whitespace:\n" << endl;
    codec->setEncodeWhitespace(TRUE);
    codec->setEncodeOptionalDirect(TRUE);
    enc = codec->makeEncoder();

    len = arg.length();
    cout << (enc->fromUnicode( arg, len )).data()
	 << "\n" << endl;

    cout << "Same as above, but call fromUnicode() char-wise:\n" << endl;

    delete enc;
    enc = codec->makeEncoder();

    for ( int i = 0 ; i < arg.length() ; i++ ) {
      len = 1;
      cout << (enc->fromUnicode( TQString(arg[i]), len )).data();
    }
    cout << "\n" << endl;

    

    delete enc;

    cout << "Encode optional direct set and not whitespace:\n" << endl;
    codec->setEncodeWhitespace(FALSE);
    codec->setEncodeOptionalDirect(TRUE);
    enc = codec->makeEncoder();

    len = arg.length();
    cout << (enc->fromUnicode( arg, len )).data()
	 << "\n" << endl;

    delete enc;
    

    cout << "Don't encode optional direct set, but whitespace:\n" << endl;
    codec->setEncodeWhitespace(TRUE);
    codec->setEncodeOptionalDirect(FALSE);
    enc = codec->makeEncoder();

    len = arg.length();
    cout << (enc->fromUnicode( arg, len )).data()
	 << "\n" << endl;

    delete enc;
    

    cout << "Encode neither optional direct set, nor whitespace:\n" << endl;
    codec->setEncodeWhitespace(FALSE);
    codec->setEncodeOptionalDirect(FALSE);
    enc = codec->makeEncoder();

    len = arg.length();
    cout << (enc->fromUnicode( arg, len )).data()
	 << "\n" << endl;

    cout << "Same as above, but call fromUnicode() char-wise:\n" << endl;

    delete enc;
    enc = codec->makeEncoder();

    for ( int i = 0 ; i < arg.length() ; i++ ) {
      len = 1;
      cout << (enc->fromUnicode( TQString(arg[i]), len )).data();
    }
    cout << "\n" << endl;

    
    delete enc;
    
    delete codec;
  } else {
    tqWarning("usage: testutf7encoder string_to_encode\n");
  }
}