Repository navigation
Expand file tree
/
Copy pathuprinter.cpp
More file actions
118 lines (108 loc) · 2.78 KB
/
Copy pathuprinter.cpp
File metadata and controls
118 lines (108 loc) · 2.78 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// © 2017 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
*
* Copyright (C) 2003, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
*
* File uprinter.cpp
*
* Modification History:
*
* Date Name Description
* 03/18/2003 weiv Creation.
*******************************************************************************
*/
#include "uprinter.h"
UPrinter::UPrinter(FILE *file, const char *locale, const char *encoding, UBool transliterateNonPrintable) {
_on = TRUE;
out = u_finit(file, locale, encoding);
strcpy(_locale, locale);
if(transliterateNonPrintable) {
UErrorCode status = U_ZERO_ERROR;
UTransliterator *anyHex = utrans_open("[^\\u000d\\u000a\\u0009\\u0020-\\u007f] Any-Hex/Java", UTRANS_FORWARD, NULL, 0, NULL, &status);
u_fsettransliterator(out, U_WRITE, anyHex, &status);
}
};
UPrinter::UPrinter(const char *name, const char *locale, const char *encoding, UTransliterator *trans, UBool transliterateNonPrintable) {
_on = TRUE;
out = u_fopen(name, "wb", locale, encoding);
u_fputc(0xFEFF, out); // emit a BOM
strcpy(_locale, locale);
if(transliterateNonPrintable) {
UErrorCode status = U_ZERO_ERROR;
if(trans == NULL) {
UTransliterator *anyHex = utrans_open("[^\\u000d\\u000a\\u0009\\u0020-\\u007f] Any-Hex/Java", UTRANS_FORWARD, NULL, 0, NULL, &status);
u_fsettransliterator(out, U_WRITE, anyHex, &status);
} else {
u_fsettransliterator(out, U_WRITE, trans, &status);
}
}
};
UPrinter::~UPrinter() {
u_fclose(out);
}
void
UPrinter::log(const UnicodeString &string, UBool nl) {
if(_on) {
log(((UnicodeString)string).getTerminatedBuffer(), nl);
}
}
void
UPrinter::log(const UChar *string, UBool nl) {
if(_on) {
u_fprintf(out, "%S", string);
if(nl) {
u_fprintf(out, "\n");
}
u_fflush(out);
}
}
/*
void
UPrinter::log(const char *string, UBool nl) {
if(_on) {
u_fprintf(out, "%s", string);
if(nl) {
u_fprintf(out, "\n");
}
}
}
*/
void
UPrinter::log(const Line *line, UBool nl) {
if(_on) {
log(line->name);
if(line->expLen) {
log("/");
log(line->expansionString);
}
if(nl) {
u_fprintf(out, "\n");
u_fflush(out);
}
}
}
void UPrinter::log(const char *fmt, ...)
{
UChar buffer[4000];
va_list ap;
va_start(ap, fmt);
/* sprintf it just to make sure that the information is valid */
u_vsprintf(buffer, _locale, fmt, ap);
va_end(ap);
if( _on ) {
log(buffer);
}
}
void
UPrinter::on(void) {
_on = TRUE;
}
void
UPrinter::off(void) {
_on = FALSE;
}