ICU-3517 remove HexToUnicode and UnicodeToHex transliterators

X-SVN-Rev: 14589
This commit is contained in:
Alan Liu 2004-02-25 23:02:26 +00:00
parent e9985abfd4
commit 56f27d5462
12 changed files with 37 additions and 2277 deletions

View File

@ -1,378 +0,0 @@
/*
**********************************************************************
* Copyright (C) 1999-2003, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Date Name Description
* 11/17/99 aliu Creation.
**********************************************************************
*/
#include "unicode/utypes.h"
#if !UCONFIG_NO_TRANSLITERATION
#include "unicode/rep.h"
#include "unicode/unifilt.h"
#include "unicode/uchar.h"
#include "hextouni.h"
U_NAMESPACE_BEGIN
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(HexToUnicodeTransliterator)
/**
* ID for this transliterator.
*/
const char CURR_ID[] = "Hex-Any";
/**
* This pattern encodes the following specs for the default constructor:
* \\u0000
* \\U0000
* u+0000
* U+0000
* The multiple backslashes resolve to a single backslash
* in the effective prefix.
*/
static const UChar DEFAULT_PATTERN[] = {
0x5C, 0x5C, 0x75, 0x30, 0x30, 0x30, 0x30, 0x3B, /* "\\u0000;" */
0x5C, 0x5C, 0x55, 0x30, 0x30, 0x30, 0x30, 0x3B, /* "\\U0000;" */
0x75, 0x2B, 0x30, 0x30, 0x30, 0x30, 0x3B, /* "u+0000;" */
0x55, 0x2B, 0x30, 0x30, 0x30, 0x30, 0 /* "U+0000" */
}; /* "\\u0000;\\U0000;u+0000;U+0000" */
static const UChar gQuadA[] = {
0x41, 0x41, 0x41, 0x41, 0
}; /* "AAAA" */
HexToUnicodeTransliterator::~HexToUnicodeTransliterator() {}
/**
* Constructs a transliterator.
*/
HexToUnicodeTransliterator::HexToUnicodeTransliterator(UnicodeFilter* adoptedFilter) :
Transliterator(UnicodeString(CURR_ID, ""), adoptedFilter) {
// We don't need to pass the status back to the caller because
// we know that the DEFAULT_PATTERN parses.
UErrorCode status = U_ZERO_ERROR;
applyPattern(DEFAULT_PATTERN, status);
}
/**
* Constructs a transliterator.
*/
HexToUnicodeTransliterator::HexToUnicodeTransliterator(const UnicodeString& thePattern,
UErrorCode& status) :
Transliterator(UnicodeString(CURR_ID, ""), 0) {
applyPattern(thePattern, status);
}
/**
* Constructs a transliterator.
*/
HexToUnicodeTransliterator::HexToUnicodeTransliterator(const UnicodeString& thePattern,
UnicodeFilter* adoptedFilter,
UErrorCode& status) :
Transliterator(UnicodeString(CURR_ID, ""), adoptedFilter) {
applyPattern(thePattern, status);
}
/**
* Copy constructor.
*/
HexToUnicodeTransliterator::HexToUnicodeTransliterator(const HexToUnicodeTransliterator& o) :
Transliterator(o),
pattern(o.pattern),
affixes(o.affixes),
affixCount(o.affixCount) {
}
/**
* Assignment operator.
*/
HexToUnicodeTransliterator& HexToUnicodeTransliterator::operator=(
const HexToUnicodeTransliterator& o) {
Transliterator::operator=(o);
pattern = o.pattern;
affixes = o.affixes;
affixCount = o.affixCount;
return *this;
}
/**
* Transliterator API.
*/
Transliterator* HexToUnicodeTransliterator::clone(void) const {
return new HexToUnicodeTransliterator(*this);
}
void HexToUnicodeTransliterator::applyPattern(const UnicodeString& thePattern,
UErrorCode& status) {
if (U_FAILURE(status)) {
return;
}
/* The pattern is processed and stored in affixes. The pattern
* consists of zero or more affixes. Each affix is parsed to
* determine the prefix, suffix, minimum digit count, and maximum
* digit count. These values are then stored as a four character
* header. That is, their numeric values are cast to UChars and
* stored in the string. Following these four characters, the prefix
* characters, then suffix characters are stored. Each spec takes
* n+4 characters, where n is the total length of the prefix and
* suffix.
*/
// POSSIBILE FUTURE MODIFICATION
// Parse thePattern, and if this succeeds, set pattern to thePattern.
// If it fails, call applyPattern(pattern) to restore the original
// conditions.
pattern = thePattern;
affixes.truncate(0);
affixCount = 0;
/* The mode specifies where we are in each spec.
* mode 0 = in prefix
* mode 1 = in optional digits (#)
* mode 2 = in required digits (0)
* mode 3 = in suffix
*/
int32_t mode = 0;
int32_t prefixLen = 0, suffixLen = 0, minDigits = 0, maxDigits = 0;
int32_t start = 0;
/* To make parsing easier, we append a virtual ';' at the end of
* the pattern string, if there isn't one already. When we get to
* the index pattern.length() (that is, one past the end), we
* create a virtual ';' if necessary.
*/
UChar c = 0; // These are outside the loop so we can see the
UBool isLiteral = FALSE; // previous character...
for (int32_t i=0; i<=pattern.length(); ++i) {
// Create the virtual trailing ';' if necessary
if (i == pattern.length()) {
// If the last character was not a non-literal ';'...
if (i > 0 && !(c == SEMICOLON && !isLiteral)) {
c = SEMICOLON;
isLiteral = FALSE;
} else {
break;
}
} else {
c = pattern.charAt(i);
isLiteral = FALSE;
}
if (c == BACKSLASH) {
if ((i+1)<pattern.length()) {
isLiteral = TRUE;
c = pattern.charAt(++i);
} else {
// Trailing '\\'
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
}
if (!isLiteral) {
switch (c) {
case POUND:
// Seeing a '#' moves us from mode 0 (prefix) to mode 1
// (optional digits).
if (mode == 0) {
++mode;
} else if (mode != 1) {
// Unquoted '#'
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
++maxDigits;
break;
case ZERO:
// Seeing a '0' moves us to mode 2 (required digits)
if (mode < 2) {
mode = 2;
} else if (mode != 2) {
// Unquoted '0'
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
++minDigits;
++maxDigits;
break;
case SEMICOLON:
if (minDigits < 1 || maxDigits > 4
// Invalid min/max digit count
|| prefixLen > 0xFFFF || suffixLen > 0xFFFF) {
// Suffix or prefix too long
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
// If there was no prefix and no suffix, then the
// header will not have been allocated yet. We need
// allocate the header now.
if (start == affixes.length()) {
affixes.append(gQuadA);
}
// Fill in 4-character header
affixes.setCharAt(start++, (UChar) prefixLen);
affixes.setCharAt(start++, (UChar) suffixLen);
affixes.setCharAt(start++, (UChar) minDigits);
affixes.setCharAt(start++, (UChar) maxDigits);
start = affixes.length();
++affixCount;
prefixLen = suffixLen = minDigits = maxDigits = mode = 0;
break;
default:
isLiteral = TRUE;
break;
}
}
if (isLiteral) {
if (start == affixes.length()) {
// Make space for the header. Append any four
// characters as place holders for the header values.
// We fill these in when we parse the ';'.
affixes.append(gQuadA);
}
affixes.append(c);
if (mode == 0) {
++prefixLen;
} else {
// Any literal outside the prefix moves us into mode 3
// (suffix)
mode = 3;
++suffixLen;
}
}
}
}
const UnicodeString& HexToUnicodeTransliterator::toPattern(void) const {
return pattern;
}
void HexToUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
UBool isIncremental) const {
int32_t cursor = offsets.start;
int32_t limit = offsets.limit;
int32_t i, j, ipat;
while (cursor < limit) {
// Loop over the specs in affixes. If affixCount is zero (an
// empty pattern), then we do nothing. We exit this loop when
// we match one of the specs. We exit this function (by
// jumping to exit: below) if a partial match is detected and
// isIncremental is true.
for (j=0, ipat=0; j<affixCount; ++j) {
// Read the header
int32_t prefixLen = affixes.charAt(ipat++);
int32_t suffixLen = affixes.charAt(ipat++);
int32_t minDigits = affixes.charAt(ipat++);
int32_t maxDigits = affixes.charAt(ipat++);
// curs is a copy of cursor that is advanced over the
// characters as we parse them.
int32_t curs = cursor;
UBool match = TRUE;
for (i=0; i<prefixLen; ++i) {
if (curs >= limit) {
if (i > 0) {
// We've already matched a character. This is
// a partial match, so we return if in
// incremental mode. In non-incremental mode,
// go to the next spec.
if (isIncremental) {
goto exit;
}
match = FALSE;
break;
}
}
UChar c = text.charAt(curs++);
if (c != affixes.charAt(ipat + i)) {
match = FALSE;
break;
}
}
if (match) {
UChar u = 0;
int32_t digitCount = 0;
for (;;) {
if (curs >= limit) {
// Check for partial match in incremental mode.
if (curs > cursor && isIncremental) {
goto exit;
}
break;
}
int32_t digit = u_digit(text.charAt(curs), 16);
if (digit < 0) {
break;
}
++curs;
u <<= 4;
u |= digit;
if (++digitCount == maxDigits) {
break;
}
}
match = (digitCount >= minDigits);
if (match) {
for (i=0; i<suffixLen; ++i) {
if (curs >= limit) {
// Check for partial match in incremental mode.
if (curs > cursor && isIncremental) {
goto exit;
}
match = FALSE;
break;
}
UChar c = text.charAt(curs++);
if (c != affixes.charAt(ipat + prefixLen + i)) {
match = FALSE;
break;
}
}
if (match) {
// This is a temporary one-character string
UnicodeString str(u);
// At this point, we have a match
text.handleReplaceBetween(cursor, curs, str);
limit -= curs - cursor - 1;
// The following break statement leaves the
// loop that is traversing the specs in
// affixes. We then parse the next input
// character.
break;
}
}
}
ipat += prefixLen + suffixLen;
}
++cursor;
}
exit:
offsets.contextLimit += limit - offsets.limit;
offsets.limit = limit;
offsets.start = cursor;
}
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_TRANSLITERATION */

View File

@ -1,173 +0,0 @@
/*
**********************************************************************
* Copyright (C) 1999-2003, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Date Name Description
* 11/17/99 aliu Creation.
**********************************************************************
*/
#ifndef HEXTOUNI_H
#define HEXTOUNI_H
#include "unicode/utypes.h"
#if !UCONFIG_NO_TRANSLITERATION
#include "unicode/translit.h"
U_NAMESPACE_BEGIN
/**
* A transliterator that converts from hexadecimal Unicode escape
* sequences to the characters they represent. For example, "U+0040"
* and '\u0040'. A default HexToUnicodeTransliterator recognizes the
* prefixes "U+", "u+", "&#92;U", and "&#92;u". Hex values may be
* upper- or lowercase. By calling the applyPattern() method, one
* or more custom prefix/suffix pairs may be specified. See
* applyPattern() for details.
*
* @author Alan Liu
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
class U_I18N_API HexToUnicodeTransliterator : public Transliterator {
// Character constants defined here to avoid ASCII dependency
enum {
SEMICOLON = 0x003B, // ';'
ZERO = 0x0030, // '0'
POUND = 0x0023, // '#'
BACKSLASH = 0x005C // '\\'
};
/**
* The pattern for this transliterator
*/
UnicodeString pattern;
/**
* The processed pattern specification. See applyPattern() for
* details.
*/
UnicodeString affixes;
/**
* The number of different affix sets in affixes.
*/
int32_t affixCount;
public:
/**
* Constructs a transliterator that recognizes the standard
* prefixes "&#92;u", "&#92;U", "u+", and "U+", each with no
* suffix.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
HexToUnicodeTransliterator(UnicodeFilter* adoptedFilter = 0);
/**
* Constructs a custom transliterator with the given pattern.
* @see #applyPattern
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
HexToUnicodeTransliterator(const UnicodeString& pattern,
UErrorCode& status);
/**
* Constructs a custom transliterator with the given pattern
* and filter.
* @see #applyPattern
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
HexToUnicodeTransliterator(const UnicodeString& pattern,
UnicodeFilter* adoptedFilter,
UErrorCode& status);
/**
* Destructor.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
virtual ~HexToUnicodeTransliterator();
/**
* Copy constructor.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
HexToUnicodeTransliterator(const HexToUnicodeTransliterator&);
/**
* Assignment operator.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
HexToUnicodeTransliterator& operator=(const HexToUnicodeTransliterator&);
/**
* Transliterator API.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
Transliterator* clone(void) const;
/**
* Set the patterns recognized by this transliterator. One or
* more patterns may be specified, separated by semicolons (';').
* Each pattern contains zero or more prefix characters, one or
* more digit characters, and zero or more suffix characters. The
* digit characters indicates optional digits ('#') followed by
* required digits ('0'). The total number of digits cannot
* exceed 4, and must be at least 1 required digit. Use a
* backslash ('\\') to escape any of the special characters. An
* empty pattern is allowed; it specifies a transliterator that
* does nothing.
*
* <p>Example: "U+0000;<###0>" specifies two patterns. The first
* has a prefix of "U+", exactly four digits, and no suffix. The
* second has a prefix of "<", between one and four digits, and a
* suffix of ">".
*
* <p><pre>
* pattern := spec | ( pattern ';' spec )
* spec := prefix-char* digit-spec suffix-char*
* digit-spec := '#'* '0'+
* prefix-char := [^special-char] | '\\' special-char
* suffix-char := [^special-char] | '\\' special-char
* special-char := ';' | '0' | '#' | '\\'
* </pre>
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
void applyPattern(const UnicodeString& thePattern, UErrorCode& status);
/**
* Return this transliterator's pattern.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
const UnicodeString& toPattern(void) const;
/**
* Implements {@link Transliterator#handleTransliterate}.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
UBool isIncremental) const;
/**
* ICU "poor man's RTTI", returns a UClassID for the actual class.
*
* @draft ICU 2.2
*/
virtual UClassID getDynamicClassID() const;
/**
* ICU "poor man's RTTI", returns a UClassID for this class.
*
* @draft ICU 2.2
*/
static UClassID getStaticClassID();
};
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_TRANSLITERATION */
#endif

View File

@ -670,22 +670,6 @@ SOURCE=.\usrchimp.h
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\buddhcal.cpp
# End Source File
# Begin Source File
SOURCE=.\buddhcal.h
# End Source File
# Begin Source File
SOURCE=.\islamcal.cpp
# End Source File
# Begin Source File
SOURCE=.\islamcal.h
# End Source File
# Begin Source File
SOURCE=.\astro.cpp
# End Source File
# Begin Source File
@ -694,26 +678,18 @@ SOURCE=.\astro.h
# End Source File
# Begin Source File
SOURCE=.\buddhcal.cpp
# End Source File
# Begin Source File
SOURCE=.\buddhcal.h
# End Source File
# Begin Source File
SOURCE=.\calendar.cpp
# End Source File
# Begin Source File
SOURCE=.\chnsecal.cpp
# End Source File
# Begin Source File
SOURCE=.\chnsecal.h
# End Source File
# Begin Source File
SOURCE=.\hebrwcal.cpp
# End Source File
# Begin Source File
SOURCE=.\hebrwcal.h
# End Source File
# Begin Source File
SOURCE=.\unicode\calendar.h
!IF "$(CFG)" == "i18n - Win32 Release"
@ -761,6 +737,14 @@ InputPath=.\unicode\calendar.h
# End Source File
# Begin Source File
SOURCE=.\chnsecal.cpp
# End Source File
# Begin Source File
SOURCE=.\chnsecal.h
# End Source File
# Begin Source File
SOURCE=.\choicfmt.cpp
# End Source File
# Begin Source File
@ -1232,6 +1216,22 @@ SOURCE=.\gregoimp.h
# End Source File
# Begin Source File
SOURCE=.\hebrwcal.cpp
# End Source File
# Begin Source File
SOURCE=.\hebrwcal.h
# End Source File
# Begin Source File
SOURCE=.\islamcal.cpp
# End Source File
# Begin Source File
SOURCE=.\islamcal.h
# End Source File
# Begin Source File
SOURCE=.\japancal.cpp
# End Source File
# Begin Source File
@ -1982,14 +1982,6 @@ SOURCE=.\funcrepl.h
# End Source File
# Begin Source File
SOURCE=.\hextouni.cpp
# End Source File
# Begin Source File
SOURCE=.\hextouni.h
# End Source File
# Begin Source File
SOURCE=.\name2uni.cpp
# End Source File
# Begin Source File
@ -2189,57 +2181,6 @@ SOURCE=.\uni2name.h
# End Source File
# Begin Source File
SOURCE=.\unifltlg.cpp
# End Source File
# Begin Source File
SOURCE=.\unicode\unifltlg.h
!IF "$(CFG)" == "i18n - Win32 Release"
# Begin Custom Build
InputPath=.\unicode\unifltlg.h
"..\..\include\unicode\unifltlg.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy $(InputPath) ..\..\include\unicode
# End Custom Build
!ELSEIF "$(CFG)" == "i18n - Win32 Debug"
# Begin Custom Build
InputPath=.\unicode\unifltlg.h
"..\..\include\unicode\unifltlg.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy $(InputPath) ..\..\include\unicode
# End Custom Build
!ELSEIF "$(CFG)" == "i18n - Win64 Release"
# Begin Custom Build
InputPath=.\unicode\unifltlg.h
"..\..\include\unicode\unifltlg.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy $(InputPath) ..\..\include\unicode
# End Custom Build
!ELSEIF "$(CFG)" == "i18n - Win64 Debug"
# Begin Custom Build
InputPath=.\unicode\unifltlg.h
"..\..\include\unicode\unifltlg.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy $(InputPath) ..\..\include\unicode
# End Custom Build
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\unicode\unirepl.h
!IF "$(CFG)" == "i18n - Win32 Release"
@ -2287,14 +2228,6 @@ InputPath=.\unicode\unirepl.h
# End Source File
# Begin Source File
SOURCE=.\unitohex.cpp
# End Source File
# Begin Source File
SOURCE=.\unitohex.h
# End Source File
# Begin Source File
SOURCE=.\utrans.cpp
# End Source File
# Begin Source File

View File

@ -1,275 +0,0 @@
/*
**********************************************************************
* Copyright (C) 1999-2003, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Date Name Description
* 11/17/99 aliu Creation.
**********************************************************************
*/
#include "unicode/utypes.h"
#if !UCONFIG_NO_TRANSLITERATION
#include "unicode/rep.h"
#include "unicode/unifilt.h"
#include "unitohex.h"
U_NAMESPACE_BEGIN
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UnicodeToHexTransliterator)
/**
* ID for this transliterator.
*/
const char CURR_ID[] = "Any-Hex";
static const UChar HEX_DIGITS[32] = {
// Use Unicode hex values for EBCDIC compatibility
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // 01234567
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, // 89abcdef
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // 01234567
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, // 89ABCDEF
};
UnicodeToHexTransliterator::~UnicodeToHexTransliterator() {}
/**
* Constructs a transliterator.
*/
UnicodeToHexTransliterator::UnicodeToHexTransliterator(
const UnicodeString& thePattern,
UBool isUppercase,
UnicodeFilter* adoptedFilter,
UErrorCode& status) :
Transliterator(UnicodeString(CURR_ID, ""), adoptedFilter),
uppercase(isUppercase)
{
if (U_FAILURE(status)) {
return;
}
applyPattern(thePattern, status);
}
/**
* Constructs a transliterator.
*/
UnicodeToHexTransliterator::UnicodeToHexTransliterator(
const UnicodeString& thePattern,
UErrorCode& status) :
Transliterator(UnicodeString(CURR_ID, ""), 0),
uppercase(TRUE) {
if (U_FAILURE(status)) {
return;
}
applyPattern(thePattern, status);
}
/**
* Constructs a transliterator with the default prefix "&#092;u"
* that outputs four uppercase hex digits.
*/
UnicodeToHexTransliterator::UnicodeToHexTransliterator(
UnicodeFilter* adoptedFilter) :
Transliterator(UnicodeString(CURR_ID, ""), adoptedFilter),
pattern("\\\\u0000", ""),
prefix("\\u", 2, ""),
suffix(),
minDigits(4),
uppercase(TRUE) {
}
/**
* Copy constructor.
*/
UnicodeToHexTransliterator::UnicodeToHexTransliterator(
const UnicodeToHexTransliterator& other) :
Transliterator(other),
pattern(other.pattern),
prefix(other.prefix),
suffix(other.suffix),
minDigits(other.minDigits),
uppercase(other.uppercase) {
}
/**
* Assignment operator.
*/
UnicodeToHexTransliterator&
UnicodeToHexTransliterator::operator=(const UnicodeToHexTransliterator& other) {
Transliterator::operator=(other);
pattern = other.pattern;
prefix = other.prefix;
suffix = other.suffix;
minDigits = other.minDigits;
uppercase = other.uppercase;
return *this;
}
Transliterator*
UnicodeToHexTransliterator::clone(void) const {
return new UnicodeToHexTransliterator(*this);
}
void UnicodeToHexTransliterator::applyPattern(const UnicodeString& thePattern,
UErrorCode& status) {
if (U_FAILURE(status)) {
return;
}
// POSSIBILE FUTURE MODIFICATION
// Parse thePattern, and if this succeeds, set pattern to thePattern.
// If it fails, call applyPattern(pattern) to restore the original
// conditions.
pattern = thePattern;
prefix.truncate(0);
suffix.truncate(0);
minDigits = 0;
int32_t maxDigits = 0;
/* The mode specifies where we are in each spec.
* mode 0 = in prefix
* mode 1 = in optional digits (#)
* mode 2 = in required digits (0)
* mode 3 = in suffix
*/
int32_t mode = 0;
for (int32_t i=0; i<pattern.length(); ++i) {
UChar c = pattern.charAt(i);
UBool isLiteral = FALSE;
if (c == BACKSLASH) {
if ((i+1)<pattern.length()) {
isLiteral = TRUE;
c = pattern.charAt(++i);
} else {
// Trailing '\\'
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
}
if (!isLiteral) {
switch (c) {
case POUND:
// Seeing a '#' moves us from mode 0 (prefix) to mode 1
// (optional digits).
if (mode == 0) {
++mode;
} else if (mode != 1) {
// Unquoted '#'
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
++maxDigits;
break;
case ZERO:
// Seeing a '0' moves us to mode 2 (required digits)
if (mode < 2) {
mode = 2;
} else if (mode != 2) {
// Unquoted '0'
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
++minDigits;
++maxDigits;
break;
default:
isLiteral = TRUE;
break;
}
}
if (isLiteral) {
if (mode == 0) {
prefix.append(c);
} else {
// Any literal outside the prefix moves us into mode 3
// (suffix)
mode = 3;
suffix.append(c);
}
}
}
if (minDigits < 1 || maxDigits > 4) {
// Invalid min/max digit count
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
}
const UnicodeString& UnicodeToHexTransliterator::toPattern(void) const {
return pattern;
}
/**
* Returns true if this transliterator outputs uppercase hex digits.
*/
UBool UnicodeToHexTransliterator::isUppercase(void) const {
return uppercase;
}
/**
* Sets if this transliterator outputs uppercase hex digits.
*
* <p>Callers must take care if a transliterator is in use by
* multiple threads. The uppercase mode should not be changed by
* one thread while another thread may be transliterating.
* @param outputUppercase if true, then this transliterator
* outputs uppercase hex digits.
*/
void UnicodeToHexTransliterator::setUppercase(UBool outputUppercase) {
uppercase = outputUppercase;
}
/**
* Implements {@link Transliterator#handleTransliterate}.
*/
void UnicodeToHexTransliterator::handleTransliterate(Replaceable& text, UTransPosition& offsets,
UBool /*isIncremental*/) const {
/**
* Performs transliteration changing all characters to
* Unicode hexadecimal escapes. For example, '@' -> "U+0040",
* assuming the prefix is "U+".
*/
int32_t cursor = offsets.start;
int32_t limit = offsets.limit;
UnicodeString hex;
while (cursor < limit) {
UChar c = text.charAt(cursor);
hex = prefix;
UBool showRest = FALSE;
for (int32_t i=3; i>=0; --i) {
/* Get each nibble from left to right */
int32_t d = (c >> (i<<2)) & 0xF;
if (showRest || (d != 0) || minDigits > i) {
hex.append(HEX_DIGITS[uppercase ? (d|16) : d]);
showRest = TRUE;
}
}
hex.append(suffix);
text.handleReplaceBetween(cursor, cursor+1, hex);
int32_t len = hex.length();
cursor += len; // Advance cursor by 1 and adjust for new text
--len;
limit += len;
}
offsets.contextLimit += limit - offsets.limit;
offsets.limit = limit;
offsets.start = cursor;
}
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_TRANSLITERATION */

View File

@ -1,215 +0,0 @@
/*
**********************************************************************
* Copyright (C) 1999-2003, International Business Machines Corporation and others. All Rights Reserved.
**********************************************************************
* Date Name Description
* 11/17/99 aliu Creation.
**********************************************************************
*/
#ifndef UNITOHEX_H
#define UNITOHEX_H
#include "unicode/utypes.h"
#if !UCONFIG_NO_TRANSLITERATION
#include "unicode/translit.h"
#include "unicode/unistr.h"
U_NAMESPACE_BEGIN
class UnicodeFilter;
/**
* A transliterator that converts from Unicode characters to
* hexadecimal Unicode escape sequences. It outputs a
* prefix specified in the constructor and optionally converts the hex
* digits to uppercase.
*
* <p>The format of the output is set by a pattern. This pattern
* follows the same syntax as <code>HexToUnicodeTransliterator</code>,
* except it does not allow multiple specifications. The pattern sets
* the prefix string, suffix string, and minimum and maximum digit
* count. There are no setters or getters for these attributes; they
* are set only through the pattern.
*
* <p>The setUppercase() and isUppercase() methods control whether 'a'
* through 'f' or 'A' through 'F' are output as hex digits. This is
* not controlled through the pattern; only through the methods. The
* default is uppercase.
*
* @author Alan Liu
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
class U_I18N_API UnicodeToHexTransliterator : public Transliterator {
private:
// Character constants defined here to avoid ASCII dependency
enum {
ZERO = 0x0030, // '0'
POUND = 0x0023, // '#'
BACKSLASH = 0x005C // '\\'
};
/**
* The pattern set by applyPattern() and returned by toPattern().
*/
UnicodeString pattern;
/**
* The string preceding the hex digits, parsed from the pattern.
*/
UnicodeString prefix;
/**
* The string following the hex digits, parsed from the pattern.
*/
UnicodeString suffix;
/**
* The minimum number of hex digits to output, between 1 and 4,
* inclusive. Parsed from the pattern.
*/
int8_t minDigits;
/**
* If TRUE, output uppercase hex digits; otherwise output
* lowercase. Set by setUppercase() and returned by isUppercase().
*/
UBool uppercase;
public:
/**
* Constructs a transliterator.
* @param pattern The pattern for this transliterator. See
* applyPattern() for pattern syntax.
* @param isUppercase if true, the four hex digits will be
* converted to uppercase; otherwise they will be lowercase.
* @param adoptedFilter the filter for this transliterator, or
* NULL if none. Adopted by this transliterator.
* @param status Error code indicating success or failure
* to parse pattern.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
UnicodeToHexTransliterator(const UnicodeString& pattern,
UBool isUppercase,
UnicodeFilter* adoptedFilter,
UErrorCode& status);
/**
* Constructs an uppercase transliterator with no filter.
* @param pattern The pattern for this transliterator. See
* applyPattern() for pattern syntax.
* @param status Error code indicating success or failure
* to parse pattern.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
UnicodeToHexTransliterator(const UnicodeString& pattern,
UErrorCode& status);
/**
* Constructs a transliterator with the default prefix "\u"
* that outputs uppercase hex digits.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
UnicodeToHexTransliterator(UnicodeFilter* adoptedFilter = 0);
/**
* Destructor.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
virtual ~UnicodeToHexTransliterator();
/**
* Copy constructor.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
UnicodeToHexTransliterator(const UnicodeToHexTransliterator&);
/**
* Assignment operator.
* @stable ICU 2.0
*/
UnicodeToHexTransliterator& operator=(const UnicodeToHexTransliterator&);
/**
* Transliterator API.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
virtual Transliterator* clone(void) const;
/**
* Set the pattern recognized by this transliterator. The pattern
* must contain zero or more prefix characters, one or more digit
* characters, and zero or more suffix characters. The digit
* characters indicates optional digits ('#') followed by required
* digits ('0'). The total number of digits cannot exceed 4, and
* must be at least 1 required digit. Use a backslash ('\\') to
* escape any of the special characters. An empty pattern is not
* allowed.
*
* <p>Example: "U+0000" specifies a prefix of "U+", exactly four
* digits, and no suffix. "<###0>" has a prefix of "<", between
* one and four digits, and a suffix of ">".
*
* <p><pre>
* pattern := prefix-char* digit-spec suffix-char*
* digit-spec := '#'* '0'+
* prefix-char := [^special-char] | '\\' special-char
* suffix-char := [^special-char] | '\\' special-char
* special-char := ';' | '0' | '#' | '\\'
* </pre>
*
* <p>Limitations: There is no way to set the uppercase attribute
* in the pattern. (applyPattern() does not alter the uppercase
* attribute.)
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
void applyPattern(const UnicodeString& thePattern, UErrorCode& status);
/**
* Return this transliterator's pattern.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
const UnicodeString& toPattern(void) const;
/**
* Returns true if this transliterator outputs uppercase hex digits.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
virtual UBool isUppercase(void) const;
/**
* Sets if this transliterator outputs uppercase hex digits.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
virtual void setUppercase(UBool outputUppercase);
/**
* Implements {@link Transliterator#handleTransliterate}.
* @internal Use transliterator factory methods instead since this class will be removed in that release.
*/
virtual void handleTransliterate(Replaceable& text, UTransPosition& offsets,
UBool isIncremental) const;
/**
* ICU "poor man's RTTI", returns a UClassID for the actual class.
*
* @draft ICU 2.2
*/
virtual UClassID getDynamicClassID() const;
/**
* ICU "poor man's RTTI", returns a UClassID for this class.
*
* @draft ICU 2.2
*/
static UClassID getStaticClassID();
};
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_TRANSLITERATION */
#endif

View File

@ -1,444 +0,0 @@
/***************************************************************************
*
* Copyright (C) 2000-2003, International Business Machines
* Corporation and others. All Rights Reserved.
*
************************************************************************
* Date Name Description
* 03/17/2000 Madhu Creation.
************************************************************************/
#include "unicode/utypes.h"
#if !UCONFIG_NO_TRANSLITERATION
#include "ittrans.h"
#include "hxuntrts.h"
#include "unicode/utypes.h"
#include "unicode/translit.h"
#include "unicode/unifilt.h"
#include "unicode/uchar.h"
#include "hextouni.h"
#include "intltest.h"
#include "cmemory.h"
#include <string.h>
#include <stdio.h>
/*converts a Unicodestring to integer*/
static int32_t getInt(UnicodeString str)
{
int32_t result = 0;
int32_t len = str.length();
int32_t i = 0;
for(i=0; i<len; i++) {
result = result*10+u_charDigitValue(str.char32At(i));
}
return result;
}
//---------------------------------------------
// runIndexedTest
//---------------------------------------------
void HexToUniTransliteratorTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
{
if (exec) logln((UnicodeString)"TestSuite HexadecimalToUnicode Transliterator API ");
switch (index) {
case 0: name = "TestConstruction"; if (exec) TestConstruction(); break;
case 1: name = "TestCloneEqual"; if (exec) TestCloneEqual(); break;
case 2: name = "TestPattern"; if (exec) TestPattern(); break;
case 3: name = "TestSimpleTransliterate"; if (exec) TestSimpleTransliterate(); break;
case 4: name = "TestTransliterate"; if (exec) TestTransliterate(); break;
default: name = ""; break; /*needed to end loop*/
}
}
/**
* Used by TestConstruction() and TestTransliterate.
*/
uint32_t gTestHexFilterClassID = 0;
class TestHexFilter : public UnicodeFilter {
virtual UClassID getDynamicClassID() const { return &gTestHexFilterClassID; }
virtual UnicodeFunctor* clone() const {
return new TestHexFilter(*this);
}
virtual UBool contains(UChar32 c) const {
if(c == 0x0061 || c == 0x0063 )
return FALSE;
else
return TRUE;
}
// Stubs
virtual UnicodeString& toPattern(UnicodeString& result,
UBool /*escapeUnprintable*/) const {
return result;
}
virtual UBool matchesIndexValue(uint8_t /*v*/) const {
return FALSE;
}
virtual void addMatchSetTo(UnicodeSet& /*toUnionTo*/) const {}
};
void HexToUniTransliteratorTest::TestConstruction(){
UErrorCode status=U_ZERO_ERROR;
logln("Testing the construction HexToUnicodeTransliterator()");
HexToUnicodeTransliterator *trans1=new HexToUnicodeTransliterator();
if(trans1==0){
errln("HexToUnicodeTransliterator construction failed Error=" + (UnicodeString)u_errorName(status));
return;
}
delete trans1;
logln("Testing the cosntruction HexToUnicodeTransliterator(pattern, status)");
UnicodeString pattern("\\\\U+0000abc");
trans1=new HexToUnicodeTransliterator(pattern, status);
if(U_FAILURE(status)){
errln("HexToUnicodeTransliterator construction failed with pattern =" + pattern + " Error=" + (UnicodeString)u_errorName(status));
status=U_ZERO_ERROR;
return;
}
delete trans1;
logln("Testing the construction HexToUnicodeTransliterator(pattern, status) with illegal pattern");
UnicodeString pattern2("\\X+");
trans1=new HexToUnicodeTransliterator(pattern2, status);
if(U_FAILURE(status)){
logln("OK: HexToUnicodeTransliterator construction for illegal pattern failed, as expected");
status=U_ZERO_ERROR;
} else {
errln("Error: calling the HexToUnicodeTransliterator constructor with illegal pattern should fail");
}
delete trans1;
logln("Testing the construction HexToUnicodeTransliterator(pattern, adoptedFilter, status)");
trans1=new HexToUnicodeTransliterator(pattern, NULL, status);
if(U_FAILURE(status)){
errln("HexToUnicodeTransliterator construction failed. Error=" + (UnicodeString)u_errorName(status));
status=U_ZERO_ERROR;
return;
}
logln("Testing the copy construction");
HexToUnicodeTransliterator *trans1copy=new HexToUnicodeTransliterator(*trans1);
if(trans1->toPattern() != trans1copy->toPattern() ||
trans1->getID() != trans1copy->getID() ){
errln("Copy construction failed");
}
delete trans1copy;
delete trans1;
logln("Testing the construction HexToUnicodeTransliterator(adoptedFilter)");
trans1=new HexToUnicodeTransliterator(new TestHexFilter);
if(trans1 == 0){
errln("HexToUnicodeTransliterator construction failed. Error=" + (UnicodeString)u_errorName(status));
return;
}
logln("Testing the copy construction");
trans1copy=new HexToUnicodeTransliterator(*trans1);
if(trans1->getFilter() == NULL || trans1copy->getFilter() == NULL ||
trans1->toPattern() != trans1copy->toPattern() ||
trans1->getID() != trans1copy->getID() ){
errln("Copy construction failed");
}
delete trans1copy;
delete trans1;
}
void HexToUniTransliteratorTest::TestCloneEqual(){
UErrorCode status=U_ZERO_ERROR;
HexToUnicodeTransliterator *transdefault=new HexToUnicodeTransliterator();
UnicodeString pattern1("\\U##00");
UnicodeString pattern2("\\\\uni0000");
HexToUnicodeTransliterator *trans1=new HexToUnicodeTransliterator(pattern1, status);
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
errln("HexToUnicodeTransliterator construction failed");
status=U_ZERO_ERROR;
return;
}
HexToUnicodeTransliterator *trans2=new HexToUnicodeTransliterator(pattern2, status);
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
errln("HexToUnicodeTransliterator construction failed");
status=U_ZERO_ERROR;
return;
}
logln("Testing the clone() API of the HexToUnicodeTransliterator");
HexToUnicodeTransliterator *transdefaultclone=(HexToUnicodeTransliterator*)transdefault->clone();
HexToUnicodeTransliterator *trans1clone=(HexToUnicodeTransliterator*)trans1->clone();
HexToUnicodeTransliterator *trans2clone=(HexToUnicodeTransliterator*)trans2->clone();
if(transdefault->toPattern() != transdefaultclone->toPattern() ||
trans1->toPattern() != trans1clone->toPattern() ||
trans2->toPattern() != trans2clone->toPattern() ||
transdefault->toPattern() == trans1->toPattern() ||
trans1->toPattern() == trans2clone->toPattern() ||
trans2->toPattern() == transdefault->toPattern() ) {
errln("Error: clone() failed");
}
logln("Testing the =operator of the HexToUnicodeTransliterator");
HexToUnicodeTransliterator *transdefaultequal=new HexToUnicodeTransliterator();
HexToUnicodeTransliterator *trans1equal=new HexToUnicodeTransliterator();
HexToUnicodeTransliterator *trans2equal=new HexToUnicodeTransliterator();
*transdefaultequal=*transdefault;
*trans1equal=*trans1;
*trans2equal=*trans2;
if(transdefault->toPattern() != transdefaultequal->toPattern() ||
trans1->toPattern() != trans1equal->toPattern() ||
trans2->toPattern() != trans2equal->toPattern() ||
transdefault->toPattern() == trans1->toPattern() ||
trans1->toPattern() == trans2equal->toPattern() ||
trans2->toPattern() == transdefault->toPattern() ) {
errln("Error: equal() failed");
}
if(transdefaultclone->toPattern() != transdefaultequal->toPattern() ||
trans1equal->toPattern() != trans1clone->toPattern() ||
trans2clone->toPattern() != trans2equal->toPattern() ){
errln("Error: equal() or clone() failed");
}
delete transdefaultclone;
delete trans1clone;
delete trans2clone;
delete transdefaultequal;
delete trans1equal;
delete trans2equal;
delete transdefault;
delete trans1;
delete trans2;
}
void HexToUniTransliteratorTest::TestPattern(){
logln("Testing the applyPattern() and toPattern() API of HexToUnicodeTransliterator");
UErrorCode status = U_ZERO_ERROR;
/*default transliterator has pattern \\u0000*/
HexToUnicodeTransliterator *transdefault=new HexToUnicodeTransliterator();
if(transdefault == 0){
errln("HexToUnicodeTransliterator construction failed. Error=" + (UnicodeString)u_errorName(status));
return;
}
UnicodeString defaultpattern=transdefault->toPattern();
UnicodeString pattern1("\\\\U+0000", "");
HexToUnicodeTransliterator *trans1=new HexToUnicodeTransliterator(pattern1, NULL, status);
if(U_FAILURE(status) ){
errln("HexToUnicodeTransliterator construction failed with pattern =" + pattern1);
status=U_ZERO_ERROR;
return;
}
/*test toPattern() */
if(transdefault->toPattern() == trans1->toPattern() ||
transdefault->toPattern() != UnicodeString("\\\\u0000;\\\\U0000;u+0000;U+0000", "") ||
trans1->toPattern() != pattern1 ){
errln("Error: toPattern() failed "+ transdefault->toPattern());
}
/*apply patterns for transdefault*/
UnicodeString str("abKf");
expectPattern(*transdefault, pattern1, UnicodeString("\\U+0061\\U+0062\\U+004B\\U+0066", ""), str);
expectPattern(*transdefault, UnicodeString("\\U##00,", ""), UnicodeString("U61,U62,U4B,U66,", ""), str);
expectPattern(*transdefault, defaultpattern, UnicodeString("\\u0061\\u0062\\u004B\\u0066", ""), str);
expectPattern(*trans1, UnicodeString("\\uni0000", ""), UnicodeString("uni0061uni0062uni004Buni0066", ""), str);
expectPattern(*trans1, UnicodeString("\\\\S-0000-E", ""), UnicodeString("\\S-0061-E\\S-0062-E\\S-004B-E\\S-0066-E", ""), str);
expectPattern(*trans1, UnicodeString("\\u##0000", ""), UnicodeString("\\u##0061\\u##0062", ""), "FAIL");
expectPattern(*trans1, UnicodeString("\\*0000", ""), UnicodeString("*0061*0062*004B*0066", ""), str);
expectPattern(*trans1, UnicodeString("\\u####", ""), UnicodeString("\\u##0061\\u##0062", ""), "FAIL");
delete trans1;
delete transdefault;
}
void HexToUniTransliteratorTest::TestSimpleTransliterate(){
logln("Testing the handleTransliterate() API of HexToUnicodeTransliterator");
UErrorCode status=U_ZERO_ERROR;
UnicodeString pattern1("\\\\U+0000", "");
HexToUnicodeTransliterator *trans1=new HexToUnicodeTransliterator(pattern1, NULL, status);
if(U_FAILURE(status)){
errln("HexToUnicodeTransliterator construction failed with pattern =" + pattern1 + "Error: " + (UnicodeString)u_errorName(status));
status=U_ZERO_ERROR;
return;
}
UnicodeString source("He\\U+006C\\U+006C\\U+006F", "");
UnicodeString rsource(source);
UTransPosition index;
index.contextStart =1;
index.contextLimit = source.length();
index.start = 2;
index.limit =source.length();
UnicodeString expected("Hello");
trans1->handleTransliterate(rsource, index, FALSE);
expectAux(trans1->getID() + ":handleTransliterator ", source + "-->" + rsource, rsource==expected, expected);
expect(*trans1, "", UnicodeString("\\U+0048\\U+0065\\U+006C\\U+006C\\U+006F", ""), expected);
delete trans1;
HexToUnicodeTransliterator *trans2=new HexToUnicodeTransliterator(new TestHexFilter);
expect(*trans2, "with Filter(0x0061, 0x0063) ", CharsToUnicodeString("\\u0061\\u0062\\u0063"),
CharsToUnicodeString("\\u0061b\\u0063") );
delete trans2;
}
void HexToUniTransliteratorTest::TestTransliterate(){
UErrorCode status=U_ZERO_ERROR;
UnicodeString Data[]={
//pattern, source, index.contextStart, index.contextLimit, index.start, expectedResult,
UnicodeString("U+##00", ""), UnicodeString("abU+63", ""), "1", "7", "2", UnicodeString("abc", ""),
UnicodeString("\\\\u0000", ""), UnicodeString("a\\u0062c", ""), "1", "7", "1", UnicodeString("abc", ""),
UnicodeString("Uni0000", ""), UnicodeString("abUni0063", ""), "1", "9", "2", UnicodeString("abc", ""),
UnicodeString("U[0000]", ""), UnicodeString("heU[006C]U[006C]o", ""), "0", "16", "2", UnicodeString("hello", ""),
UnicodeString("prefix-0000-suffix", ""), UnicodeString("aprefix-0062-suffixprefix-0063-suffix", ""), "1", "39", "1", UnicodeString("abc", ""),
UnicodeString("*##00*", ""), UnicodeString("hell*6F**74**68**65*re", ""), "1", "20", "4", UnicodeString("hellothere", ""),
};
uint32_t i;
for(i=0;i<sizeof(Data)/sizeof(Data[0]);i=i+6){
HexToUnicodeTransliterator *trans1=new HexToUnicodeTransliterator(Data[i+0], NULL, status);
if(U_FAILURE(status)){
errln("HexToUnicodeTransliterator construction failed with pattern =" + Data[i+0]);
status=U_ZERO_ERROR;
continue;
}
expectTranslit(*trans1, "", Data[i+1], getInt(Data[i+2]), getInt(Data[i+3]), getInt(Data[i+4]), Data[i+5] );
delete trans1;
}
}
//======================================================================
// Support methods
//======================================================================
void HexToUniTransliteratorTest::expectTranslit(const HexToUnicodeTransliterator& t,
const UnicodeString& message,
const UnicodeString& source,
int32_t start, int32_t limit, int32_t cursor,
const UnicodeString& expectedResult){
UTransPosition _index;
_index.contextStart =start;
_index.contextLimit = limit;
_index.start = cursor;
_index.limit = limit;
UTransPosition index;
uprv_memcpy(&index, &_index, sizeof(index));
UnicodeString rsource(source);
t.handleTransliterate(rsource, index, FALSE);
expectAux(t.getID() + ":handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource, rsource==expectedResult, expectedResult);
UnicodeString rsource2(source);
uprv_memcpy(&index, &_index, sizeof(index));
t.handleTransliterate(rsource2, index, TRUE);
expectAux(t.getID() + ":handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
/*ceates a copy constructor and checks the transliteration*/
HexToUnicodeTransliterator *copy=new HexToUnicodeTransliterator(t);
rsource2.remove();
rsource2.append(source);
uprv_memcpy(&index, &_index, sizeof(index));
copy->handleTransliterate(rsource2, index, FALSE);
expectAux(t.getID() + "COPY:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
rsource2.remove();
rsource2.append(source);
uprv_memcpy(&index, &_index, sizeof(index));
copy->handleTransliterate(rsource2, index, TRUE);
expectAux(t.getID() + "COPY:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
delete copy;
/*creates a clone and tests transliteration*/
HexToUnicodeTransliterator *clone=(HexToUnicodeTransliterator*)t.clone();
rsource2.remove();
rsource2.append(source);
uprv_memcpy(&index, &_index, sizeof(index));
clone->handleTransliterate(rsource2, index, FALSE);
expectAux(t.getID() + "CLONE:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
rsource2.remove();
rsource2.append(source);
uprv_memcpy(&index, &_index, sizeof(index));
clone->handleTransliterate(rsource2, index, TRUE);
expectAux(t.getID() + "CLONE:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
delete clone;
/*Uses the assignment operator to create a transliterator and tests transliteration*/
HexToUnicodeTransliterator equal=t;
rsource2.remove();
rsource2.append(source);
uprv_memcpy(&index, &_index, sizeof(index));
equal.handleTransliterate(rsource2, index, FALSE);
expectAux(t.getID() + "=OPERATOR:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
rsource2.remove();
rsource2.append(source);
uprv_memcpy(&index, &_index, sizeof(index));
equal.handleTransliterate(rsource2, index, TRUE);
expectAux(t.getID() + "=OPERATOR:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
}
void HexToUniTransliteratorTest::expectPattern(HexToUnicodeTransliterator& t,
const UnicodeString& pattern,
const UnicodeString& source,
const UnicodeString& expectedResult){
UErrorCode status=U_ZERO_ERROR;
t.applyPattern(pattern, status);
if(expectedResult == "FAIL"){
if(U_FAILURE(status)){
logln("OK: calling applyPattern() with illegal pattern failed as expected. Error=" + (UnicodeString)u_errorName(status));
status=U_ZERO_ERROR;
return;
}
}
else{
if(U_FAILURE(status)){
errln("Error: applyPattern() failed with pattern =" + pattern + "--->" + (UnicodeString)u_errorName(status));
return;
}else {
if(t.toPattern() != pattern) {
errln("Error: applyPattern or toPatten failed. Expected: " + pattern + "Got: " + t.toPattern());
}
else{
logln("OK: applyPattern passed. Testing transliteration");
expect(t, " with pattern "+pattern, source, expectedResult);
}
}
}
}
void HexToUniTransliteratorTest::expect(const HexToUnicodeTransliterator& t,
const UnicodeString& message,
const UnicodeString& source,
const UnicodeString& expectedResult) {
UnicodeString rsource(source);
t.transliterate(rsource);
expectAux(t.getID() + ":Replaceable " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
// Test handleTransliterate (incremental) transliteration --
rsource.remove();
rsource.append(source);
UTransPosition index;
index.contextStart =0;
index.contextLimit =source.length();
index.start=0;
index.limit = source.length();
t.handleTransliterate(rsource, index, TRUE);
expectAux(t.getID() + ":handleTransliterate " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
}
void HexToUniTransliteratorTest::expectAux(const UnicodeString& tag,
const UnicodeString& summary, UBool pass,
const UnicodeString& expectedResult) {
if (pass) {
logln(UnicodeString("(")+tag+") " + prettify(summary));
} else {
errln(UnicodeString("FAIL: (")+tag+") "
+ prettify(summary)
+ ", expected " + prettify(expectedResult));
}
}
#endif /* #if !UCONFIG_NO_TRANSLITERATION */

View File

@ -1,69 +0,0 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2003, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************
************************************************************************
* Date Name Description
* 03/17/2000 Madhu Creation.
************************************************************************/
#ifndef HEXTOUNITRTST_H
#define HEXTOUNITRTST_H
#include "unicode/utypes.h"
#if !UCONFIG_NO_TRANSLITERATION
#include "unicode/translit.h"
#include "hextouni.h"
#include "intltest.h"
/**
* @test
* @summary General test of HexadecimalToUnicodeTransliterator
*/
class HexToUniTransliteratorTest : public IntlTest {
public:
void runIndexedTest(int32_t index, UBool exec, const char* &name, char* par=NULL);
/*Tests the constructors */
void TestConstruction(void);
/*Tests the function clone, and operator==()*/
void TestCloneEqual(void);
/*Tests the function getTransliterator() and setTransliterators() and adoptTransliterators()*/
void TestPattern(void);
/*Tests the function handleTransliterate()*/
void TestSimpleTransliterate(void);
/*Tests the function handleTransliterate()*/
void TestTransliterate(void);
//======================================================================
// Support methods
//======================================================================
void expectTranslit(const HexToUnicodeTransliterator& t,
const UnicodeString& message,
const UnicodeString& source,
int32_t start, int32_t limit, int32_t cursor,
const UnicodeString& expectedResult);
void expectPattern(HexToUnicodeTransliterator& t,
const UnicodeString& pattern,
const UnicodeString& source,
const UnicodeString& expectedResult);
void expect(const HexToUnicodeTransliterator& t,
const UnicodeString& message,
const UnicodeString& source,
const UnicodeString& expectedResult);
void expectAux(const UnicodeString& tag,
const UnicodeString& summary, UBool pass,
const UnicodeString& expectedResult);
};
#endif /* #if !UCONFIG_NO_TRANSLITERATION */
#endif

View File

@ -960,14 +960,6 @@ SOURCE=.\cpdtrtst.h
# End Source File
# Begin Source File
SOURCE=.\hxuntrts.cpp
# End Source File
# Begin Source File
SOURCE=.\hxuntrts.h
# End Source File
# Begin Source File
SOURCE=.\ittrans.cpp
# End Source File
# Begin Source File
@ -1014,22 +1006,6 @@ SOURCE=.\trnserr.cpp
SOURCE=.\trnserr.h
# End Source File
# Begin Source File
SOURCE=.\ufltlgts.cpp
# End Source File
# Begin Source File
SOURCE=.\ufltlgts.h
# End Source File
# Begin Source File
SOURCE=.\unhxtrts.cpp
# End Source File
# Begin Source File
SOURCE=.\unhxtrts.h
# End Source File
# End Group
# End Target
# End Project

View File

@ -20,9 +20,6 @@
#include "transtst.h"
#include "transapi.h"
#include "cpdtrtst.h"
#include "unhxtrts.h"
#include "hxuntrts.h"
#include "ufltlgts.h"
#include "transrt.h"
#include "usettest.h"
#include "jamotest.h"
@ -45,13 +42,11 @@ void IntlTestTransliterator::runIndexedTest( int32_t index, UBool exec, const ch
CASE(0, TransliteratorTest);
CASE(1, TransliteratorAPITest);
CASE(2, CompoundTransliteratorTest);
CASE(3, UniToHexTransliteratorTest);
CASE(4, HexToUniTransliteratorTest);
CASE(5, TransliteratorRoundTripTest);
CASE(6, UnicodeSetTest);
CASE(7, JamoTest);
CASE(8, TransliteratorErrorTest);
CASE(9, ReplaceableTest);
CASE(3, TransliteratorRoundTripTest);
CASE(4, UnicodeSetTest);
CASE(5, JamoTest);
CASE(6, TransliteratorErrorTest);
CASE(7, ReplaceableTest);
#if !UCONFIG_NO_TRANSLITERATION && defined(U_USE_UNICODE_FILTER_LOGIC_OBSOLETE_2_8)
CASE(10, UnicodeFilterLogicTest);
#endif

View File

@ -1,515 +0,0 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2003, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/***********************************************************************
************************************************************************
* Date Name Description
* 03/15/2000 Madhu Creation.
************************************************************************/
#include "unicode/utypes.h"
#if !UCONFIG_NO_TRANSLITERATION
#include "ittrans.h"
#include "unhxtrts.h"
#include "unicode/utypes.h"
#include "unicode/translit.h"
#include "unicode/unifilt.h"
#include "unicode/uchar.h"
#include "intltest.h"
#include "unitohex.h"
/*converts a Unicodestring to integer*/
static int32_t getInt(UnicodeString str)
{
int32_t result = 0;
int32_t len = str.length();
int32_t i = 0;
for(i=0; i<len; i++) {
result = result*10+u_charDigitValue(str.char32At(i));
}
return result;
}
//---------------------------------------------
// runIndexedTest
//---------------------------------------------
void UniToHexTransliteratorTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
{
if (exec) logln((UnicodeString)"TestSuite UnicodeToHexadecimal Transliterator API ");
switch (index) {
case 0: name = "TestConstruction"; if (exec) TestConstruction(); break;
case 1: name = "TestCloneEqual"; if (exec) TestCloneEqual(); break;
case 2: name = "TestUpperCase"; if (exec) TestUpperCase(); break;
case 3: name = "TestPattern"; if (exec) TestPattern(); break;
case 4: name = "TestSimpleTransliterate"; if (exec) TestSimpleTransliterate(); break;
case 5: name = "TestTransliterate"; if (exec) TestTransliterate(); break;
default: name = ""; break; /*needed to end loop*/
}
}
// This test used to call handleTransliterate. That is a protected
// method that isn't supposed to be called externally. This method is
// a workaround to make it call the correct method.
static void pseudoHandleTransliterate(const Transliterator* t,
Replaceable& text,
UTransPosition& index,
UBool incremental) {
if (incremental) {
UErrorCode status = U_ZERO_ERROR;
t->transliterate(text, index, status);
} else {
t->finishTransliteration(text, index);
}
}
/**
* Used by TestConstruction() and TestTransliterate.
*/
int32_t gTestUniFilterClassID;
class TestUniFilter : public UnicodeFilter {
virtual UClassID getDynamicClassID() const { return &gTestUniFilterClassID; }
virtual UnicodeFunctor* clone() const {
return new TestUniFilter(*this);
}
virtual UBool contains(UChar32 c) const {
if(c==0x0063 || c==0x0061 || c==0x0043 || c==0x0041)
return FALSE;
else
return TRUE;
}
// Stubs
virtual UnicodeString& toPattern(UnicodeString& result,
UBool /*escapeUnprintable*/) const {
return result;
}
virtual UBool matchesIndexValue(uint8_t /*v*/) const {
return FALSE;
}
virtual void addMatchSetTo(UnicodeSet& /*toUnionTo*/) const {}
};
void UniToHexTransliteratorTest::TestConstruction(){
UErrorCode status=U_ZERO_ERROR;
logln("Testing the construction UnicodeToHexTransliterator()");
UnicodeToHexTransliterator *trans1=new UnicodeToHexTransliterator();
if(trans1==0){
errln("UnicodeToHexTransliterator construction failed Error=" + (UnicodeString)u_errorName(status));
return;
}
delete trans1;
logln("Testing the cosntruction UnicodeToHexTransliterator(pattern, status)");
UnicodeString pattern("\\\\U+0000abc");
trans1=new UnicodeToHexTransliterator(pattern, status);
if(U_FAILURE(status)){
errln("UnicodeToHexTransliterator construction failed with pattern =" + pattern + " Error=" + (UnicodeString)u_errorName(status));
status=U_ZERO_ERROR;
return;
}
delete trans1;
logln("Testing the cosntruction UnicodeToHexTransliterator(pattern, status) with illegal pattern");
UnicodeString pattern2("\\X+");
trans1=new UnicodeToHexTransliterator(pattern2, status);
if(U_FAILURE(status)){
logln("OK: UnicodeToHexTransliterator construction for illegal pattern failed, as expected");
status=U_ZERO_ERROR;
} else {
errln("Error: calling the UnicodeToHexTransliterator constructor with illegal pattern should fail");
}
delete trans1;
logln("Testing the construction UnicodeToHexTransliterator(pattern, isUppercase, adoptedFilter, status)");
trans1=new UnicodeToHexTransliterator(pattern, FALSE, NULL, status);
if(U_FAILURE(status)){
errln("UnicodeToHexTransliterator construction failed. Error=" + (UnicodeString)u_errorName(status));
status=U_ZERO_ERROR;
return;
}
logln("Testing the copy construction");
UnicodeToHexTransliterator *trans1copy=new UnicodeToHexTransliterator(*trans1);
if(trans1->toPattern() != trans1copy->toPattern() || trans1->isUppercase() != trans1copy->isUppercase() ||
trans1->getID() != trans1copy->getID()){
errln("Copy construction failed");
}
delete trans1copy;
delete trans1;
logln("Testing the construction UnicodeToHexTransliterator(pattern, isUppercase, adoptedFilter, status)");
trans1=new UnicodeToHexTransliterator(pattern, TRUE, new TestUniFilter, status);
if(U_FAILURE(status)){
errln("UnicodeToHexTransliterator construction failed Error=" + (UnicodeString)u_errorName(status));
status=U_ZERO_ERROR;
return;
}
logln("Testing the copy construction");
trans1copy=new UnicodeToHexTransliterator(*trans1);
if(trans1->toPattern() != trans1copy->toPattern() || trans1->isUppercase() != trans1copy->isUppercase() ||
trans1->getID() != trans1copy->getID() ||
trans1->getFilter() == NULL || trans1copy->getFilter() == NULL ){
errln("Copy construction failed");
}
delete trans1copy;
delete trans1;
}
void UniToHexTransliteratorTest::TestCloneEqual(){
UErrorCode status=U_ZERO_ERROR;
UnicodeToHexTransliterator *transdefault=new UnicodeToHexTransliterator();
UnicodeString pattern1("\\U##00");
UnicodeString pattern2("\\\\uni0000");
UnicodeToHexTransliterator *trans1=new UnicodeToHexTransliterator(pattern1, status);
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
errln("UnicodeToHexTransliterator construction failed");
status=U_ZERO_ERROR;
return;
}
UnicodeToHexTransliterator *trans2=new UnicodeToHexTransliterator(pattern2, status);
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
errln("UnicodeToHexTransliterator construction failed");
status=U_ZERO_ERROR;
return;
}
logln("Testing the clone() API of the UnicodeToHexTransliterator");
UnicodeToHexTransliterator *transdefaultclone=(UnicodeToHexTransliterator*)transdefault->clone();
UnicodeToHexTransliterator *trans1clone=(UnicodeToHexTransliterator*)trans1->clone();
UnicodeToHexTransliterator *trans2clone=(UnicodeToHexTransliterator*)trans2->clone();
if(transdefault->toPattern() != transdefaultclone->toPattern() ||
transdefault->isUppercase() != transdefaultclone->isUppercase() ||
trans1->toPattern() != trans1clone->toPattern() ||
trans1->isUppercase() != trans1clone->isUppercase() ||
trans2->toPattern() != trans2clone->toPattern() ||
trans2->isUppercase() != trans2clone->isUppercase() ||
transdefault->toPattern() == trans1->toPattern() ||
trans1->toPattern() == trans2clone->toPattern() ||
trans2->toPattern() == transdefault->toPattern() ) {
errln("Error: clone() failed");
}
logln("Testing the =operator of the UnicodeToHexTransliterator");
UnicodeToHexTransliterator *transdefaultequal=new UnicodeToHexTransliterator();
UnicodeToHexTransliterator *trans1equal=new UnicodeToHexTransliterator();
UnicodeToHexTransliterator *trans2equal=new UnicodeToHexTransliterator();
*transdefaultequal=*transdefault;
*trans1equal=*trans1;
*trans2equal=*trans2;
if(transdefault->toPattern() != transdefaultequal->toPattern() ||
transdefault->isUppercase() != transdefaultequal->isUppercase() ||
trans1->toPattern() != trans1equal->toPattern() ||
trans1->isUppercase() != trans1equal->isUppercase() ||
trans2->toPattern() != trans2equal->toPattern() ||
trans2->isUppercase() != trans2equal->isUppercase() ||
transdefault->toPattern() == trans1->toPattern() ||
trans1->toPattern() == trans2equal->toPattern() ||
trans2->toPattern() == transdefault->toPattern() ) {
errln("Error: equal() failed");
}
if(transdefaultclone->toPattern() != transdefaultequal->toPattern() ||
transdefaultclone->isUppercase() != transdefaultequal->isUppercase() ||
trans1equal->toPattern() != trans1clone->toPattern() ||
trans1equal->isUppercase() != trans1clone->isUppercase() ||
trans2clone->toPattern() != trans2equal->toPattern() ||
trans2clone->isUppercase() != trans2equal->isUppercase() ) {
errln("Error: equal() or clone() failed");
}
delete transdefaultclone;
delete trans1clone;
delete trans2clone;
delete transdefaultequal;
delete trans1equal;
delete trans2equal;
delete transdefault;
delete trans1;
delete trans2;
}
void UniToHexTransliteratorTest::TestUpperCase(){
logln("Testing the isUppercase() and setUppercase() API of UnicodeToHexTransliterator");
UErrorCode status = U_ZERO_ERROR;
UnicodeString str("abk");
/*default transliterator has upper case TRUE*/
UnicodeToHexTransliterator *transdefault=new UnicodeToHexTransliterator();
if(transdefault == 0){
errln("UnicodeToHexTransliterator construction failed");
return;
}
expect(*transdefault, "where uppercase=default", str, UnicodeString("\\u0061\\u0062\\u006B", ""));
UnicodeString pattern("\\\\u0000", "");
/*transliterator with Uppercase FALSE*/
UnicodeToHexTransliterator *trans1=new UnicodeToHexTransliterator(pattern, FALSE, NULL, status);
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
errln("UnicodeToHexTransliterator construction failed with pattern =" + pattern);
status=U_ZERO_ERROR;
return;
}
expect(*trans1, "where uppercase=FALSE", str, UnicodeString("\\u0061\\u0062\\u006b", "")); /*doesn't display uppercase*/
if(transdefault->isUppercase() != TRUE || trans1->isUppercase() != FALSE ){
errln("isUpperCase() failed");
}
/*changing the outputhexdigits to lower case for the default transliterator*/
transdefault->setUppercase(trans1->isUppercase());
if(transdefault->isUppercase() != trans1->isUppercase() || transdefault->isUppercase() != FALSE){
errln("setUppercase() failed");
}
/*doesn't ouput uppercase hex, since transdefault's uppercase is set to FALSE using setUppercase*/
expect(*transdefault, "where uppercase=FALSE", str, UnicodeString("\\u0061\\u0062\\u006b", ""));
/*trying round trip*/
transdefault->setUppercase(TRUE);
if(transdefault->isUppercase() != TRUE || transdefault->isUppercase() == trans1->isUppercase() ){
errln("setUppercase() failed");
}
/*displays upper case since it is set to TRUE*/
expect(*transdefault, "where uppercase=TRUE", str, UnicodeString("\\u0061\\u0062\\u006B", ""));
delete transdefault;
delete trans1;
}
void UniToHexTransliteratorTest::TestPattern(){
logln("Testing the applyPattern() and toPattern() API of UnicodeToHexTransliterator");
UErrorCode status = U_ZERO_ERROR;
/*default transliterator has pattern \\u0000*/
UnicodeToHexTransliterator *transdefault=new UnicodeToHexTransliterator();
if(transdefault == 0){
errln("UnicodeToHexTransliterator construction failed");
return;
}
UnicodeString defaultpattern=transdefault->toPattern();
UnicodeString pattern1("\\\\U+0000", "");
UnicodeToHexTransliterator *trans1=new UnicodeToHexTransliterator(pattern1, TRUE, NULL, status);
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
errln("UnicodeToHexTransliterator construction failed with pattern =" + pattern1);
status=U_ZERO_ERROR;
return;
}
/*test toPattern() */
if(transdefault->toPattern() == trans1->toPattern() ||
transdefault->toPattern() != UnicodeString("\\\\u0000", "") ||
trans1->toPattern() != pattern1 ){
errln("Error: toPattern() failed");
}
/*apply patterns for transdefault*/
UnicodeString str("abKf");
expectPattern(*transdefault, pattern1, str, UnicodeString("\\U+0061\\U+0062\\U+004B\\U+0066", ""));
expectPattern(*transdefault, UnicodeString("\\U##00,", ""), str, UnicodeString("U61,U62,U4B,U66,", ""));
expectPattern(*transdefault, defaultpattern, str, UnicodeString("\\u0061\\u0062\\u004B\\u0066", ""));
expectPattern(*trans1, UnicodeString("\\uni0000", ""), str, UnicodeString("uni0061uni0062uni004Buni0066", ""));
expectPattern(*trans1, UnicodeString("\\\\S-0000-E", ""), str, UnicodeString("\\S-0061-E\\S-0062-E\\S-004B-E\\S-0066-E", ""));
expectPattern(*trans1, UnicodeString("\\u##0000", ""), str, UnicodeString("FAIL", ""));
expectPattern(*trans1, UnicodeString("\\*0000", ""), str, UnicodeString("*0061*0062*004B*0066", ""));
expectPattern(*trans1, UnicodeString("\\u####", ""), str, UnicodeString("FAIL", ""));
delete trans1;
delete transdefault;
}
void UniToHexTransliteratorTest::TestSimpleTransliterate(){
UErrorCode status=U_ZERO_ERROR;
UnicodeString pattern1("\\\\U+0000", "");
UnicodeToHexTransliterator *trans1=new UnicodeToHexTransliterator(pattern1, TRUE, NULL, status);
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
errln("UnicodeToHexTransliterator construction failed with pattern =" + pattern1);
status=U_ZERO_ERROR;
return;
}
UTransPosition index={1,5,2,5};
UnicodeString source("Hello");
UnicodeString rsource(source);
UnicodeString expected("He\\U+006C\\U+006C\\U+006F", "");
pseudoHandleTransliterate(trans1, rsource, index, FALSE);
expectAux(trans1->getID() + ":handleTransliterator ", source + "-->" + rsource, rsource==expected, expected);
delete trans1;
}
void UniToHexTransliteratorTest::TestTransliterate(){
UErrorCode status=U_ZERO_ERROR;
UnicodeString Data[]={
//pattern, source, index.contextStart, index.contextLimit, index.start, expectedResult, expectedResult using filter(a, b)
UnicodeString("U+##00", ""), UnicodeString("abc", ""), "1", "3", "2", UnicodeString("abU+63", ""), UnicodeString("abc", ""),
UnicodeString("\\\\u0000", ""), UnicodeString("abc", ""), "1", "2", "1", UnicodeString("a\\u0062c", ""), UnicodeString("a\\u0062c", ""),
UnicodeString("Uni0000", ""), UnicodeString("abc", ""), "1", "3", "2", UnicodeString("abUni0063", ""), UnicodeString("abc", ""),
UnicodeString("U[0000]", ""), UnicodeString("hello", ""), "0", "4", "2", UnicodeString("heU[006C]U[006C]o", ""), UnicodeString("heU[006C]U[006C]o", ""),
UnicodeString("prefix-0000-suffix", ""), UnicodeString("abc", ""), "1", "3", "1", UnicodeString("aprefix-0062-suffixprefix-0063-suffix", ""), UnicodeString("aprefix-0062-suffixc", ""),
UnicodeString("*##00*", ""), UnicodeString("hellothere", ""), "1", "8", "4", UnicodeString("hell*6F**74**68**65*re", ""), UnicodeString("hell*6F**74**68**65*re", ""),
};
uint32_t i;
for(i=0;i<sizeof(Data)/sizeof(Data[0]);i=i+7){
UnicodeToHexTransliterator *trans1=new UnicodeToHexTransliterator(Data[i+0], TRUE, NULL, status);
if(U_FAILURE(status)){
errln("UnicodeToHexTransliterator construction failed with pattern =" + Data[i+0]);
status=U_ZERO_ERROR;
continue;
}
expectTranslit(*trans1, "", Data[i+1], getInt(Data[i+2]), getInt(Data[i+3]), getInt(Data[i+4]), Data[i+5] );
delete trans1;
UnicodeToHexTransliterator *trans2=new UnicodeToHexTransliterator(Data[i+0], TRUE, new TestUniFilter, status);
if(U_FAILURE(status)){
errln("UnicodeToHexTransliterator construction failed with pattern=" + Data[i+0] + "with filter(a,c)" );
status=U_ZERO_ERROR;
continue;
}
expectTranslit(*trans2, " with filter(a,A,c,C)", Data[i+1], getInt(Data[i+2]), getInt(Data[i+3]), getInt(Data[i+4]), Data[i+6] );
delete trans2;
}
}
//======================================================================
// Support methods
//======================================================================
void UniToHexTransliteratorTest::expectTranslit(const UnicodeToHexTransliterator& t,
const UnicodeString& message,
const UnicodeString& source,
int32_t start, int32_t limit, int32_t cursor,
const UnicodeString& expectedResult){
UTransPosition _index;
_index.contextStart=start;
_index.contextLimit= limit;
_index.start = cursor;
_index.limit = limit;
UTransPosition index = _index;
UnicodeString rsource(source);
pseudoHandleTransliterate(&t, rsource, index, FALSE);
expectAux(t.getID() + ":handleTransliterator(increment=FALSE) " + message, source + "-->" + rsource, rsource==expectedResult, expectedResult);
UnicodeString rsource2(source);
index=_index;
pseudoHandleTransliterate(&t, rsource2, index, TRUE);
expectAux(t.getID() + ":handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
/*ceates a copy constructor and checks the transliteration*/
UnicodeToHexTransliterator *copy=new UnicodeToHexTransliterator(t);
rsource2.remove();
rsource2.append(source);
index=_index;
pseudoHandleTransliterate(copy, rsource2, index, FALSE);
expectAux(t.getID() + "COPY:handleTransliterator(increment=FALSE) " + message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
rsource2.remove();
rsource2.append(source);
index=_index;
pseudoHandleTransliterate(copy, rsource2, index, TRUE);
expectAux(t.getID() + "COPY:handleTransliterator(increment=TRUE) " + message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
delete copy;
/*creates a clone and tests transliteration*/
UnicodeToHexTransliterator *clone=(UnicodeToHexTransliterator*)t.clone();
rsource2.remove();
rsource2.append(source);
index=_index;
pseudoHandleTransliterate(clone, rsource2, index, FALSE);
expectAux(t.getID() + "CLONE:handleTransliterator(increment=FALSE) "+ message,source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
rsource2.remove();
rsource2.append(source);
index=_index;
pseudoHandleTransliterate(clone, rsource2, index, TRUE);
expectAux(t.getID() + "CLONE:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
delete clone;
/*Uses the assignment operator to create a transliterator and tests transliteration*/
UnicodeToHexTransliterator equal=t;
rsource2.remove();
rsource2.append(source);
index=_index;
pseudoHandleTransliterate(&equal, rsource2, index, FALSE);
expectAux(t.getID() + "=OPERATOR:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
rsource2.remove();
rsource2.append(source);
index=_index;
pseudoHandleTransliterate(&equal, rsource2, index, TRUE);
expectAux(t.getID() + "=OPERATOR:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
}
void UniToHexTransliteratorTest::expectPattern(UnicodeToHexTransliterator& t,
const UnicodeString& pattern,
const UnicodeString& source,
const UnicodeString& expectedResult){
UErrorCode status=U_ZERO_ERROR;
t.applyPattern(pattern, status);
if(expectedResult == "FAIL"){
if(U_FAILURE(status)){
logln("OK: calling applyPattern() with illegal pattern failed as expected. Error=" + (UnicodeString)u_errorName(status));
status=U_ZERO_ERROR;
return;
}
}
else{
if(U_FAILURE(status)){
errln("Error: applyPattern() failed with pattern =" + pattern + "--->" + (UnicodeString)u_errorName(status));
return;
}else {
if(t.toPattern() != pattern) {
errln("Error: applyPattern or toPatten failed. Expected: " + pattern + "Got: " + t.toPattern());
}
else{
logln("OK: applyPattern passed. Testing transliteration");
expect(t, (UnicodeString)" with pattern "+pattern, source, expectedResult);
}
}
}
}
void UniToHexTransliteratorTest::expect(const UnicodeToHexTransliterator& t,
const UnicodeString& message,
const UnicodeString& source,
const UnicodeString& expectedResult) {
UnicodeString rsource(source);
t.transliterate(rsource);
expectAux(t.getID() + ":Replaceable " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
// Test handleTransliterate (incremental) transliteration --
rsource.remove();
rsource.append(source);
UTransPosition index;
index.contextStart=0;
index.contextLimit = source.length();
index.start =0;
index.limit=source.length();
pseudoHandleTransliterate(&t, rsource, index, TRUE);
expectAux(t.getID() + ":handleTransliterate " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
}
void UniToHexTransliteratorTest::expectAux(const UnicodeString& tag,
const UnicodeString& summary, UBool pass,
const UnicodeString& expectedResult) {
if (pass) {
logln(UnicodeString("(")+tag+") " + prettify(summary));
} else {
errln(UnicodeString("FAIL: (")+tag+") "
+ prettify(summary)
+ ", expected " + prettify(expectedResult));
}
}
#endif /* #if !UCONFIG_NO_TRANSLITERATION */

View File

@ -1,71 +0,0 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2003, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************
************************************************************************
* Date Name Description
* 03/15/2000 Madhu Creation.
************************************************************************/
#ifndef UNITOHEXTRTST_H
#define UNITOHEXTRTST_H
#include "unicode/utypes.h"
#if !UCONFIG_NO_TRANSLITERATION
#include "unicode/translit.h"
#include "unitohex.h"
#include "intltest.h"
/**
* @test
* @summary General test of UnicodeToHexadecimal Transliterator
*/
class UniToHexTransliteratorTest : public IntlTest {
public:
void runIndexedTest(int32_t index, UBool exec, const char* &name, char* par=NULL);
/*Tests the constructors */
void TestConstruction(void);
/*Tests the function clone, and operator==()*/
void TestCloneEqual(void);
/*Tests the function isUppercase and setUppercase()*/
void TestUpperCase(void);
/*Tests the function getTransliterator() and setTransliterators() and adoptTransliterators()*/
void TestPattern(void);
/*Tests the function handleTransliterate()*/
void TestSimpleTransliterate();
/*Tests the function handleTransliterate()*/
void TestTransliterate();
//======================================================================
// Support methods
//======================================================================
void expectTranslit(const UnicodeToHexTransliterator& t,
const UnicodeString& message,
const UnicodeString& source,
int32_t start, int32_t limit, int32_t cursor,
const UnicodeString& expectedResult);
void expectPattern(UnicodeToHexTransliterator& t,
const UnicodeString& pattern,
const UnicodeString& source,
const UnicodeString& expectedResult);
void expect(const UnicodeToHexTransliterator& t,
const UnicodeString& message,
const UnicodeString& source,
const UnicodeString& expectedResult);
void expectAux(const UnicodeString& tag,
const UnicodeString& summary, UBool pass,
const UnicodeString& expectedResult);
};
#endif /* #if !UCONFIG_NO_TRANSLITERATION */
#endif

View File

@ -130,8 +130,6 @@ UObject *UObjectTest::testClass(UObject *obj,
#include "cpdtrans.h"
#include "rbt.h"
#include "rbt_data.h"
#include "hextouni.h"
#include "unitohex.h"
#include "nultrans.h"
#include "anytrans.h"
#include "digitlst.h"
@ -254,8 +252,6 @@ void UObjectTest::testIDs()
#if !UCONFIG_NO_TRANSLITERATION
TESTCLASSID_DEFAULT(HexToUnicodeTransliterator);
TESTCLASSID_DEFAULT(UnicodeToHexTransliterator);
TESTCLASSID_TRANSLIT(AnyTransliterator, "Any-Latin");
TESTCLASSID_TRANSLIT(CompoundTransliterator, "Latin-Greek");
TESTCLASSID_TRANSLIT(EscapeTransliterator, "Any-Hex");