ICU-7144 merge UTS #46 (IDNA2008) C/C++ feature into trunk, merging in -r 27794:28172 icu/branches/markus/uts46
X-SVN-Rev: 28195
This commit is contained in:
parent
5d2aaca2a9
commit
3360fe4708
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -60,6 +60,7 @@ icu4c/source/data/in/ubidi.icu -text
|
||||
icu4c/source/data/in/ucase.icu -text
|
||||
icu4c/source/data/in/unames.icu -text
|
||||
icu4c/source/data/in/uprops.icu -text
|
||||
icu4c/source/data/in/uts46.nrm -text
|
||||
icu4c/source/data/lang/pool.res -text
|
||||
icu4c/source/data/locales/pool.res -text
|
||||
icu4c/source/data/region/pool.res -text
|
||||
|
@ -91,7 +91,7 @@ utrie.o utrie2.o utrie2_builder.o bmpset.o unisetspan.o uset_props.o uniset_prop
|
||||
uarrsort.o brkiter.o ubrk.o brkeng.o dictbe.o triedict.o \
|
||||
rbbi.o rbbidata.o rbbinode.o rbbirb.o rbbiscan.o rbbisetb.o rbbistbl.o rbbitblb.o \
|
||||
serv.o servnotf.o servls.o servlk.o servlkf.o servrbf.o servslkf.o \
|
||||
uidna.o usprep.o punycode.o \
|
||||
uidna.o usprep.o uts46.o punycode.o \
|
||||
util.o util_props.o parsepos.o locbased.o cwchar.o wintz.o mutex.o dtintrv.o ucnvsel.o propsvec.o \
|
||||
ulist.o uloc_tag.o icudataver.o icuplug.o
|
||||
|
||||
|
@ -2691,6 +2691,46 @@
|
||||
Name="idna"
|
||||
Filter="*.c,*.h"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\unicode\idna.h"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="copy "$(InputPath)" ..\..\include\unicode
"
|
||||
Outputs="..\..\include\unicode\$(InputFileName)"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="copy "$(InputPath)" ..\..\include\unicode
"
|
||||
Outputs="..\..\include\unicode\$(InputFileName)"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="copy "$(InputPath)" ..\..\include\unicode
"
|
||||
Outputs="..\..\include\unicode\$(InputFileName)"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="copy "$(InputPath)" ..\..\include\unicode
"
|
||||
Outputs="..\..\include\unicode\$(InputFileName)"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\punycode.c"
|
||||
>
|
||||
@ -2743,6 +2783,10 @@
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\uts46.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="locales & resources"
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2002-2003, International Business Machines
|
||||
* Copyright (C) 2002-2010, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
@ -245,8 +245,8 @@ u_strToPunycode(const UChar *src, int32_t srcLength,
|
||||
}
|
||||
c=src[j];
|
||||
if(IS_BASIC(c)) {
|
||||
if(destLength<destCapacity) {
|
||||
cpBuffer[srcCPCount++]=0;
|
||||
if(destLength<destCapacity) {
|
||||
dest[destLength]=
|
||||
caseFlags!=NULL ?
|
||||
asciiCaseMap((char)c, caseFlags[j]) :
|
||||
@ -345,14 +345,16 @@ u_strToPunycode(const UChar *src, int32_t srcLength,
|
||||
}
|
||||
|
||||
if(destLength<destCapacity) {
|
||||
dest[destLength++]=digitToBasic(t+(q-t)%(BASE-t), 0);
|
||||
dest[destLength]=digitToBasic(t+(q-t)%(BASE-t), 0);
|
||||
}
|
||||
++destLength;
|
||||
q=(q-t)/(BASE-t);
|
||||
}
|
||||
|
||||
if(destLength<destCapacity) {
|
||||
dest[destLength++]=digitToBasic(q, (UBool)(cpBuffer[j]<0));
|
||||
dest[destLength]=digitToBasic(q, (UBool)(cpBuffer[j]<0));
|
||||
}
|
||||
++destLength;
|
||||
bias=adaptBias(delta, handledCPCount+1, (UBool)(handledCPCount==basicLength));
|
||||
delta=0;
|
||||
++handledCPCount;
|
||||
|
@ -117,6 +117,7 @@ public:
|
||||
* Flush internal buffers.
|
||||
* Some byte sinks use internal buffers or provide buffering
|
||||
* and require calling Flush() at the end of the stream.
|
||||
* The ByteSink should be ready for further Append() calls after Flush().
|
||||
* The default implementation of Flush() does nothing.
|
||||
* @stable ICU 4.2
|
||||
*/
|
||||
@ -156,7 +157,7 @@ public:
|
||||
* @return *this
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
CheckedArrayByteSink& Reset();
|
||||
virtual CheckedArrayByteSink& Reset();
|
||||
/**
|
||||
* Append "bytes[0,n-1]" to this.
|
||||
* @param bytes the pointer to the bytes
|
||||
|
320
icu4c/source/common/unicode/idna.h
Normal file
320
icu4c/source/common/unicode/idna.h
Normal file
@ -0,0 +1,320 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2010, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
* file name: idna.h
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2010mar05
|
||||
* created by: Markus W. Scherer
|
||||
*/
|
||||
|
||||
#ifndef __IDNA_H__
|
||||
#define __IDNA_H__
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Internationalizing Domain Names in Applications (IDNA)
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_IDNA
|
||||
|
||||
#include "unicode/bytestream.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include "unicode/uidna.h"
|
||||
#include "unicode/unistr.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class U_COMMON_API IDNAInfo;
|
||||
|
||||
/**
|
||||
* Abstract base class for IDNA processing.
|
||||
* See http://www.unicode.org/reports/tr46/
|
||||
* and http://www.ietf.org/rfc/rfc3490.txt
|
||||
*
|
||||
* The IDNA class is not intended for public subclassing.
|
||||
*
|
||||
* This C++ API currently only implements UTS #46.
|
||||
* The uidna.h C API implements both UTS #46 (functions using UIDNA service object)
|
||||
* and IDNA2003 (functions that do not use a service object).
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
class U_COMMON_API IDNA : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Returns an IDNA instance which implements UTS #46.
|
||||
* Returns an unmodifiable instance, owned by the caller.
|
||||
* Cache it for multiple operations, and delete it when done.
|
||||
*
|
||||
* UTS #46 defines Unicode IDNA Compatibility Processing,
|
||||
* updated to the latest version of Unicode and compatible with both
|
||||
* IDNA2003 and IDNA2008.
|
||||
*
|
||||
* The worker functions use transitional processing, including deviation mappings,
|
||||
* unless UIDNA_NONTRANSITIONAL_TO_ASCII or UIDNA_NONTRANSITIONAL_TO_UNICODE
|
||||
* is used in which case the deviation characters are passed through without change.
|
||||
*
|
||||
* Disallowed characters are mapped to U+FFFD.
|
||||
*
|
||||
* For available options see the uidna.h header.
|
||||
* Operations with the UTS #46 instance do not support the
|
||||
* UIDNA_ALLOW_UNASSIGNED option.
|
||||
*
|
||||
* By default, the UTS #46 implementation allows all ASCII characters (as valid or mapped).
|
||||
* When the UIDNA_USE_STD3_RULES option is used, ASCII characters other than
|
||||
* letters, digits, hyphen (LDH) and dot/full stop are disallowed and mapped to U+FFFD.
|
||||
*
|
||||
* @param options Bit set to modify the processing and error checking.
|
||||
* See option bit set values in uidna.h.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return the UTS #46 IDNA instance, if successful
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
static IDNA *
|
||||
createUTS46Instance(uint32_t options, UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Converts a single domain name label into its ASCII form for DNS lookup.
|
||||
* If any processing step fails, then info.hasErrors() will be TRUE and
|
||||
* the result might not be an ASCII string.
|
||||
* The label might be modified according to the types of errors.
|
||||
* Labels with severe errors will be left in (or turned into) their Unicode form.
|
||||
*
|
||||
* The UErrorCode indicates an error only in exceptional cases,
|
||||
* such as a U_MEMORY_ALLOCATION_ERROR.
|
||||
*
|
||||
* @param label Input domain name label
|
||||
* @param dest Destination string object
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
labelToASCII(const UnicodeString &label, UnicodeString &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const = 0;
|
||||
|
||||
/**
|
||||
* Converts a single domain name label into its Unicode form for human-readable display.
|
||||
* If any processing step fails, then info.hasErrors() will be TRUE.
|
||||
* The domain name might be modified according to the types of errors.
|
||||
*
|
||||
* The UErrorCode indicates an error only in exceptional cases,
|
||||
* such as a U_MEMORY_ALLOCATION_ERROR.
|
||||
*
|
||||
* @param label Input domain name label
|
||||
* @param dest Destination string object
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
labelToUnicode(const UnicodeString &label, UnicodeString &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const = 0;
|
||||
|
||||
/**
|
||||
* Converts a whole domain name into its ASCII form for DNS lookup.
|
||||
* If any processing step fails, then info.hasErrors() will be TRUE and
|
||||
* the result might not be an ASCII string.
|
||||
* The domain name might be modified according to the types of errors.
|
||||
* Labels with severe errors will be left in (or turned into) their Unicode form.
|
||||
*
|
||||
* The UErrorCode indicates an error only in exceptional cases,
|
||||
* such as a U_MEMORY_ALLOCATION_ERROR.
|
||||
*
|
||||
* @param name Input domain name
|
||||
* @param dest Destination string object
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
nameToASCII(const UnicodeString &name, UnicodeString &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const = 0;
|
||||
|
||||
/**
|
||||
* Converts a whole domain name into its Unicode form for human-readable display.
|
||||
* If any processing step fails, then info.hasErrors() will be TRUE.
|
||||
* The domain name might be modified according to the types of errors.
|
||||
*
|
||||
* The UErrorCode indicates an error only in exceptional cases,
|
||||
* such as a U_MEMORY_ALLOCATION_ERROR.
|
||||
*
|
||||
* @param name Input domain name
|
||||
* @param dest Destination string object
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
virtual UnicodeString &
|
||||
nameToUnicode(const UnicodeString &name, UnicodeString &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const = 0;
|
||||
|
||||
// UTF-8 versions of the processing methods ---------------------------- ***
|
||||
|
||||
/**
|
||||
* Converts a single domain name label into its ASCII form for DNS lookup.
|
||||
* UTF-8 version of labelToASCII(), same behavior.
|
||||
*
|
||||
* @param label Input domain name label
|
||||
* @param dest Destination byte sink; Flush()ed if successful
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
virtual void
|
||||
labelToASCII_UTF8(const StringPiece &label, ByteSink &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const;
|
||||
|
||||
/**
|
||||
* Converts a single domain name label into its Unicode form for human-readable display.
|
||||
* UTF-8 version of labelToUnicode(), same behavior.
|
||||
*
|
||||
* @param label Input domain name label
|
||||
* @param dest Destination byte sink; Flush()ed if successful
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
virtual void
|
||||
labelToUnicodeUTF8(const StringPiece &label, ByteSink &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const;
|
||||
|
||||
/**
|
||||
* Converts a whole domain name into its ASCII form for DNS lookup.
|
||||
* UTF-8 version of nameToASCII(), same behavior.
|
||||
*
|
||||
* @param name Input domain name
|
||||
* @param dest Destination byte sink; Flush()ed if successful
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
virtual void
|
||||
nameToASCII_UTF8(const StringPiece &name, ByteSink &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const;
|
||||
|
||||
/**
|
||||
* Converts a whole domain name into its Unicode form for human-readable display.
|
||||
* UTF-8 version of nameToUnicode(), same behavior.
|
||||
*
|
||||
* @param name Input domain name
|
||||
* @param dest Destination byte sink; Flush()ed if successful
|
||||
* @param info Output container of IDNA processing details.
|
||||
* @param errorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return dest
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
virtual void
|
||||
nameToUnicodeUTF8(const StringPiece &name, ByteSink &dest,
|
||||
IDNAInfo &info, UErrorCode &errorCode) const;
|
||||
|
||||
private:
|
||||
// No ICU "poor man's RTTI" for this class nor its subclasses.
|
||||
virtual UClassID getDynamicClassID() const;
|
||||
};
|
||||
|
||||
class UTS46;
|
||||
|
||||
/**
|
||||
* Output container for IDNA processing errors.
|
||||
* The IDNAInfo class is not suitable for subclassing.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
class U_COMMON_API IDNAInfo : public UMemory {
|
||||
public:
|
||||
/**
|
||||
* Constructor for stack allocation.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
IDNAInfo() : errors(0), labelErrors(0), isTransDiff(FALSE), isBiDi(FALSE), isOkBiDi(TRUE) {}
|
||||
/**
|
||||
* Were there IDNA processing errors?
|
||||
* @return TRUE if there were processing errors
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UBool hasErrors() const { return errors!=0; }
|
||||
/**
|
||||
* Returns a bit set indicating IDNA processing errors.
|
||||
* See UIDNA_ERROR_... constants in uidna.h.
|
||||
* @return bit set of processing errors
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
uint32_t getErrors() const { return errors; }
|
||||
/**
|
||||
* Returns TRUE if transitional and nontransitional processing produce different results.
|
||||
* This is the case when the input label or domain name contains
|
||||
* one or more deviation characters outside a Punycode label (see UTS #46).
|
||||
* <ul>
|
||||
* <li>With nontransitional processing, such characters are
|
||||
* copied to the destination string.
|
||||
* <li>With transitional processing, such characters are
|
||||
* mapped (sharp s/sigma) or removed (joiner/nonjoiner).
|
||||
* </ul>
|
||||
* @return TRUE if transitional and nontransitional processing produce different results
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UBool isTransitionalDifferent() const { return isTransDiff; }
|
||||
|
||||
private:
|
||||
friend class UTS46;
|
||||
|
||||
IDNAInfo(const IDNAInfo &other); // no copying
|
||||
IDNAInfo &operator=(const IDNAInfo &other); // no copying
|
||||
|
||||
void reset() {
|
||||
errors=labelErrors=0;
|
||||
isTransDiff=FALSE;
|
||||
isBiDi=FALSE;
|
||||
isOkBiDi=TRUE;
|
||||
}
|
||||
|
||||
uint32_t errors, labelErrors;
|
||||
UBool isTransDiff;
|
||||
UBool isBiDi;
|
||||
UBool isOkBiDi;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif // UCONFIG_NO_IDNA
|
||||
#endif // __IDNA_H__
|
@ -21,18 +21,474 @@
|
||||
|
||||
#if !UCONFIG_NO_IDNA
|
||||
|
||||
#include "unicode/localpointer.h"
|
||||
#include "unicode/parseerr.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C API: Internationalized Domain Names in Applications Tranformation
|
||||
* \brief C API: Internationalizing Domain Names in Applications (IDNA)
|
||||
*
|
||||
* UIDNA API implements the IDNA protocol as defined in the IDNA RFC
|
||||
* IDNA2008 is implemented according to UTS #46, see the IDNA C++ class in idna.h.
|
||||
*
|
||||
* The C API functions which do take a UIDNA * service object pointer
|
||||
* implement UTS #46 and IDNA2008.
|
||||
* The C API functions which do not take a service object pointer
|
||||
* implement IDNA2003.
|
||||
*/
|
||||
|
||||
/*
|
||||
* IDNA option bit set values.
|
||||
*/
|
||||
enum {
|
||||
/**
|
||||
* Default options value: None of the other options are set.
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
UIDNA_DEFAULT=0,
|
||||
/**
|
||||
* Option to allow unassigned code points in domain names and labels.
|
||||
* This option is ignored by the UTS46 implementation.
|
||||
* (UTS #46 disallows unassigned code points.)
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
UIDNA_ALLOW_UNASSIGNED=1,
|
||||
/**
|
||||
* Option to check whether the input conforms to the STD3 ASCII rules,
|
||||
* for example the restriction of labels to LDH characters
|
||||
* (ASCII Letters, Digits and Hyphen-Minus).
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
UIDNA_USE_STD3_RULES=2,
|
||||
/**
|
||||
* IDNA option to check for whether the input conforms to the BiDi rules.
|
||||
* This option is ignored by the IDNA2003 implementation.
|
||||
* (IDNA2003 always performs a BiDi check.)
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_CHECK_BIDI=4,
|
||||
/**
|
||||
* IDNA option to check for whether the input conforms to the CONTEXTJ rules.
|
||||
* This option is ignored by the IDNA2003 implementation.
|
||||
* (The CONTEXTJ check is new in IDNA2008.)
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_CHECK_CONTEXTJ=8,
|
||||
/**
|
||||
* IDNA option for nontransitional processing in ToASCII().
|
||||
* By default, ToASCII() uses transitional processing.
|
||||
* This option is ignored by the IDNA2003 implementation.
|
||||
* (This is only relevant for compatibility of newer IDNA implementations with IDNA2003.)
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_NONTRANSITIONAL_TO_ASCII=0x10,
|
||||
/**
|
||||
* IDNA option for nontransitional processing in ToUnicode().
|
||||
* By default, ToUnicode() uses transitional processing.
|
||||
* This option is ignored by the IDNA2003 implementation.
|
||||
* (This is only relevant for compatibility of newer IDNA implementations with IDNA2003.)
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_NONTRANSITIONAL_TO_UNICODE=0x20
|
||||
};
|
||||
|
||||
/**
|
||||
* Opaque C service object type for the new IDNA API.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
struct UIDNA;
|
||||
typedef struct UIDNA UIDNA; /**< C typedef for struct UIDNA. @draft ICU 4.6 */
|
||||
|
||||
/**
|
||||
* Returns a UIDNA instance which implements UTS #46.
|
||||
* Returns an unmodifiable instance, owned by the caller.
|
||||
* Cache it for multiple operations, and uidna_close() it when done.
|
||||
*
|
||||
* For details about the UTS #46 implementation see the IDNA C++ class in idna.h.
|
||||
*
|
||||
* @param options Bit set to modify the processing and error checking.
|
||||
* See option bit set values in uidna.h.
|
||||
* @param pErrorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return the UTS #46 UIDNA instance, if successful
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
U_DRAFT UIDNA * U_EXPORT2
|
||||
uidna_openUTS46(uint32_t options, UErrorCode *pErrorCode);
|
||||
|
||||
/**
|
||||
* Closes a UIDNA instance.
|
||||
* @param idna UIDNA instance to be closed
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
U_DRAFT void U_EXPORT2
|
||||
uidna_close(UIDNA *idna);
|
||||
|
||||
#if U_SHOW_CPLUSPLUS_API
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* \class LocalUIDNAPointer
|
||||
* "Smart pointer" class, closes a UIDNA via uidna_close().
|
||||
* For most methods see the LocalPointerBase base class.
|
||||
*
|
||||
* @see LocalPointerBase
|
||||
* @see LocalPointer
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
U_DEFINE_LOCAL_OPEN_POINTER(LocalUIDNAPointer, UIDNA, uidna_close);
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Output container for IDNA processing errors.
|
||||
* Initialize with UIDNA_INFO_INITIALIZER:
|
||||
* \code
|
||||
* UIDNAInfo info = UIDNA_INFO_INITIALIZER;
|
||||
* int32_t length = uidna_nameToASCII(..., &info, &errorCode);
|
||||
* if(U_SUCCESS(errorCode) && info.errors!=0) { ... }
|
||||
* \endcode
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
struct UIDNAInfo {
|
||||
/** sizeof(UIDNAInfo) @draft ICU 4.6 */
|
||||
int16_t size;
|
||||
/**
|
||||
* Set to TRUE if transitional and nontransitional processing produce different results.
|
||||
* For details see C++ IDNAInfo::isTransitionalDifferent().
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UBool isTransitionalDifferent;
|
||||
UBool reservedB3; /**< Reserved field, do not use. @internal */
|
||||
/**
|
||||
* Bit set indicating IDNA processing errors. 0 if no errors.
|
||||
* See UIDNA_ERROR_... constants.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
uint32_t errors;
|
||||
int32_t reservedI2; /**< Reserved field, do not use. @internal */
|
||||
int32_t reservedI3; /**< Reserved field, do not use. @internal */
|
||||
};
|
||||
typedef struct UIDNAInfo UIDNAInfo;
|
||||
|
||||
/**
|
||||
* Static initializer for a UIDNAInfo struct.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
#define UIDNA_INFO_INITIALIZER { \
|
||||
(int16_t)sizeof(UIDNAInfo), \
|
||||
FALSE, FALSE, \
|
||||
0, 0, 0 }
|
||||
|
||||
/**
|
||||
* Converts a single domain name label into its ASCII form for DNS lookup.
|
||||
* If any processing step fails, then pInfo->errors will be non-zero and
|
||||
* the result might not be an ASCII string.
|
||||
* The label might be modified according to the types of errors.
|
||||
* Labels with severe errors will be left in (or turned into) their Unicode form.
|
||||
*
|
||||
* The UErrorCode indicates an error only in exceptional cases,
|
||||
* such as a U_MEMORY_ALLOCATION_ERROR.
|
||||
*
|
||||
* @param idna UIDNA instance
|
||||
* @param label Input domain name label
|
||||
* @param length Label length, or -1 if NUL-terminated
|
||||
* @param dest Destination string buffer
|
||||
* @param capacity Destination buffer capacity
|
||||
* @param pInfo Output container of IDNA processing details.
|
||||
* @param pErrorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return destination string length
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
U_DRAFT int32_t U_EXPORT2
|
||||
uidna_labelToASCII(const UIDNA *idna,
|
||||
const UChar *label, int32_t length,
|
||||
UChar *dest, int32_t capacity,
|
||||
UIDNAInfo *pInfo, UErrorCode *pErrorCode);
|
||||
|
||||
/**
|
||||
* Converts a single domain name label into its Unicode form for human-readable display.
|
||||
* If any processing step fails, then pInfo->errors will be non-zero.
|
||||
* The domain name might be modified according to the types of errors.
|
||||
*
|
||||
* The UErrorCode indicates an error only in exceptional cases,
|
||||
* such as a U_MEMORY_ALLOCATION_ERROR.
|
||||
*
|
||||
* @param idna UIDNA instance
|
||||
* @param label Input domain name label
|
||||
* @param length Label length, or -1 if NUL-terminated
|
||||
* @param dest Destination string buffer
|
||||
* @param capacity Destination buffer capacity
|
||||
* @param pInfo Output container of IDNA processing details.
|
||||
* @param pErrorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return destination string length
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
U_DRAFT int32_t U_EXPORT2
|
||||
uidna_labelToUnicode(const UIDNA *idna,
|
||||
const UChar *label, int32_t length,
|
||||
UChar *dest, int32_t capacity,
|
||||
UIDNAInfo *pInfo, UErrorCode *pErrorCode);
|
||||
|
||||
/**
|
||||
* Converts a whole domain name into its ASCII form for DNS lookup.
|
||||
* If any processing step fails, then pInfo->errors will be non-zero and
|
||||
* the result might not be an ASCII string.
|
||||
* The domain name might be modified according to the types of errors.
|
||||
* Labels with severe errors will be left in (or turned into) their Unicode form.
|
||||
*
|
||||
* The UErrorCode indicates an error only in exceptional cases,
|
||||
* such as a U_MEMORY_ALLOCATION_ERROR.
|
||||
*
|
||||
* @param idna UIDNA instance
|
||||
* @param name Input domain name
|
||||
* @param length Domain name length, or -1 if NUL-terminated
|
||||
* @param dest Destination string buffer
|
||||
* @param capacity Destination buffer capacity
|
||||
* @param pInfo Output container of IDNA processing details.
|
||||
* @param pErrorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return destination string length
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
U_DRAFT int32_t U_EXPORT2
|
||||
uidna_nameToASCII(const UIDNA *idna,
|
||||
const UChar *name, int32_t length,
|
||||
UChar *dest, int32_t capacity,
|
||||
UIDNAInfo *pInfo, UErrorCode *pErrorCode);
|
||||
|
||||
/**
|
||||
* Converts a whole domain name into its Unicode form for human-readable display.
|
||||
* If any processing step fails, then pInfo->errors will be non-zero.
|
||||
* The domain name might be modified according to the types of errors.
|
||||
*
|
||||
* The UErrorCode indicates an error only in exceptional cases,
|
||||
* such as a U_MEMORY_ALLOCATION_ERROR.
|
||||
*
|
||||
* @param idna UIDNA instance
|
||||
* @param name Input domain name
|
||||
* @param length Domain name length, or -1 if NUL-terminated
|
||||
* @param dest Destination string buffer
|
||||
* @param capacity Destination buffer capacity
|
||||
* @param pInfo Output container of IDNA processing details.
|
||||
* @param pErrorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return destination string length
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
U_DRAFT int32_t U_EXPORT2
|
||||
uidna_nameToUnicode(const UIDNA *idna,
|
||||
const UChar *name, int32_t length,
|
||||
UChar *dest, int32_t capacity,
|
||||
UIDNAInfo *pInfo, UErrorCode *pErrorCode);
|
||||
|
||||
/* UTF-8 versions of the processing methods --------------------------------- */
|
||||
|
||||
/**
|
||||
* Converts a single domain name label into its ASCII form for DNS lookup.
|
||||
* UTF-8 version of uidna_labelToASCII(), same behavior.
|
||||
*
|
||||
* @param idna UIDNA instance
|
||||
* @param label Input domain name label
|
||||
* @param length Label length, or -1 if NUL-terminated
|
||||
* @param dest Destination string buffer
|
||||
* @param capacity Destination buffer capacity
|
||||
* @param pInfo Output container of IDNA processing details.
|
||||
* @param pErrorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return destination string length
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
U_DRAFT int32_t U_EXPORT2
|
||||
uidna_labelToASCII_UTF8(const UIDNA *idna,
|
||||
const char *label, int32_t length,
|
||||
char *dest, int32_t capacity,
|
||||
UIDNAInfo *pInfo, UErrorCode *pErrorCode);
|
||||
|
||||
/**
|
||||
* Converts a single domain name label into its Unicode form for human-readable display.
|
||||
* UTF-8 version of uidna_labelToUnicode(), same behavior.
|
||||
*
|
||||
* @param idna UIDNA instance
|
||||
* @param label Input domain name label
|
||||
* @param length Label length, or -1 if NUL-terminated
|
||||
* @param dest Destination string buffer
|
||||
* @param capacity Destination buffer capacity
|
||||
* @param pInfo Output container of IDNA processing details.
|
||||
* @param pErrorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return destination string length
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
U_DRAFT int32_t U_EXPORT2
|
||||
uidna_labelToUnicodeUTF8(const UIDNA *idna,
|
||||
const char *label, int32_t length,
|
||||
char *dest, int32_t capacity,
|
||||
UIDNAInfo *pInfo, UErrorCode *pErrorCode);
|
||||
|
||||
/**
|
||||
* Converts a whole domain name into its ASCII form for DNS lookup.
|
||||
* UTF-8 version of uidna_nameToASCII(), same behavior.
|
||||
*
|
||||
* @param idna UIDNA instance
|
||||
* @param name Input domain name
|
||||
* @param length Domain name length, or -1 if NUL-terminated
|
||||
* @param dest Destination string buffer
|
||||
* @param capacity Destination buffer capacity
|
||||
* @param pInfo Output container of IDNA processing details.
|
||||
* @param pErrorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return destination string length
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
U_DRAFT int32_t U_EXPORT2
|
||||
uidna_nameToASCII_UTF8(const UIDNA *idna,
|
||||
const char *name, int32_t length,
|
||||
char *dest, int32_t capacity,
|
||||
UIDNAInfo *pInfo, UErrorCode *pErrorCode);
|
||||
|
||||
/**
|
||||
* Converts a whole domain name into its Unicode form for human-readable display.
|
||||
* UTF-8 version of uidna_nameToUnicode(), same behavior.
|
||||
*
|
||||
* @param idna UIDNA instance
|
||||
* @param name Input domain name
|
||||
* @param length Domain name length, or -1 if NUL-terminated
|
||||
* @param dest Destination string buffer
|
||||
* @param capacity Destination buffer capacity
|
||||
* @param pInfo Output container of IDNA processing details.
|
||||
* @param pErrorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
* immediately. Check for U_FAILURE() on output or use with
|
||||
* function chaining. (See User Guide for details.)
|
||||
* @return destination string length
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
U_DRAFT int32_t U_EXPORT2
|
||||
uidna_nameToUnicodeUTF8(const UIDNA *idna,
|
||||
const char *name, int32_t length,
|
||||
char *dest, int32_t capacity,
|
||||
UIDNAInfo *pInfo, UErrorCode *pErrorCode);
|
||||
|
||||
/*
|
||||
* IDNA error bit set values.
|
||||
* When a domain name or label fails a processing step or does not meet the
|
||||
* validity criteria, then one or more of these error bits are set.
|
||||
*/
|
||||
enum {
|
||||
/**
|
||||
* A non-final domain name label (or the whole domain name) is empty.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_EMPTY_LABEL=1,
|
||||
/**
|
||||
* A domain name label is longer than 63 bytes.
|
||||
* (See STD13/RFC1034 3.1. Name space specifications and terminology.)
|
||||
* This is only checked in ToASCII operations, and only if the UIDNA_USE_STD3_RULES is set.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_LABEL_TOO_LONG=2,
|
||||
/**
|
||||
* A domain name is longer than 255 bytes in its storage form.
|
||||
* (See STD13/RFC1034 3.1. Name space specifications and terminology.)
|
||||
* This is only checked in ToASCII operations, and only if the UIDNA_USE_STD3_RULES is set.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_DOMAIN_NAME_TOO_LONG=4,
|
||||
/**
|
||||
* A label starts with a hyphen-minus ('-').
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_LEADING_HYPHEN=8,
|
||||
/**
|
||||
* A label ends with a hyphen-minus ('-').
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_TRAILING_HYPHEN=0x10,
|
||||
/**
|
||||
* A label contains hyphen-minus ('-') in the third and fourth positions.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_HYPHEN_3_4=0x20,
|
||||
/**
|
||||
* A label starts with a combining mark.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_LEADING_COMBINING_MARK=0x40,
|
||||
/**
|
||||
* A label or domain name contains disallowed characters.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_DISALLOWED=0x80,
|
||||
/**
|
||||
* A label starts with "xn--" but does not contain valid Punycode.
|
||||
* That is, an xn-- label failed Punycode decoding.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_PUNYCODE=0x100,
|
||||
/**
|
||||
* A label contains a dot=full stop.
|
||||
* This can occur in an input string for a single-label function.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_LABEL_HAS_DOT=0x200,
|
||||
/**
|
||||
* An ACE label does not contain a valid label string.
|
||||
* The label was successfully ACE (Punycode) decoded but the resulting
|
||||
* string had severe validation errors. For example,
|
||||
* it might contain characters that are not allowed in ACE labels,
|
||||
* or it might not be normalized.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_INVALID_ACE_LABEL=0x400,
|
||||
/**
|
||||
* A label does not meet the IDNA BiDi requirements (for right-to-left characters).
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_BIDI=0x800,
|
||||
/**
|
||||
* A label does not meet the IDNA CONTEXTJ requirements.
|
||||
* @draft ICU 4.6
|
||||
*/
|
||||
UIDNA_ERROR_CONTEXTJ=0x1000
|
||||
};
|
||||
|
||||
/* IDNA2003 API ------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* IDNA2003: This function implements the ToASCII operation as defined in the IDNA RFC.
|
||||
* This operation is done on <b>single labels</b> before sending it to something that expects
|
||||
* ASCII names. A label is an individual part of a domain name. Labels are usually
|
||||
* separated by dots; e.g. "www.example.com" is composed of 3 labels "www","example", and "com".
|
||||
*
|
||||
* IDNA2003 API Overview:
|
||||
*
|
||||
* The uidna_ API implements the IDNA protocol as defined in the IDNA RFC
|
||||
* (http://www.ietf.org/rfc/rfc3490.txt).
|
||||
* The RFC defines 2 operations: ToASCII and ToUnicode. Domain labels
|
||||
* containing non-ASCII code points are required to be processed by
|
||||
* The RFC defines 2 operations: ToASCII and ToUnicode. Domain name labels
|
||||
* containing non-ASCII code points are processed by the
|
||||
* ToASCII operation before passing it to resolver libraries. Domain names
|
||||
* that are obtained from resolver libraries are required to be processed by
|
||||
* that are obtained from resolver libraries are processed by the
|
||||
* ToUnicode operation before displaying the domain name to the user.
|
||||
* IDNA requires that implementations process input strings with Nameprep
|
||||
* (http://www.ietf.org/rfc/rfc3491.txt),
|
||||
@ -47,38 +503,6 @@
|
||||
* ToUnicode(ToUnicode(ToUnicode...(ToUnicode(string)))) == ToUnicode(string)
|
||||
* ToASCII(ToASCII(ToASCII...(ToASCII(string))) == ToASCII(string).
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Option to prohibit processing of unassigned codepoints in the input and
|
||||
* do not check if the input conforms to STD-3 ASCII rules.
|
||||
*
|
||||
* @see uidna_toASCII uidna_toUnicode
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
#define UIDNA_DEFAULT 0x0000
|
||||
/**
|
||||
* Option to allow processing of unassigned codepoints in the input
|
||||
*
|
||||
* @see uidna_toASCII uidna_toUnicode
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
#define UIDNA_ALLOW_UNASSIGNED 0x0001
|
||||
/**
|
||||
* Option to check if input conforms to STD-3 ASCII rules
|
||||
*
|
||||
* @see uidna_toASCII uidna_toUnicode
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
#define UIDNA_USE_STD3_RULES 0x0002
|
||||
|
||||
/**
|
||||
* This function implements the ToASCII operation as defined in the IDNA RFC.
|
||||
* This operation is done on <b>single labels</b> before sending it to something that expects
|
||||
* ASCII names. A label is an individual part of a domain name. Labels are usually
|
||||
* separated by dots; e.g. "www.example.com" is composed of 3 labels "www","example", and "com".
|
||||
*
|
||||
*
|
||||
* @param src Input UChar array containing label in Unicode.
|
||||
* @param srcLength Number of UChars in src, or -1 if NUL-terminated.
|
||||
* @param dest Output UChar array with ASCII (ACE encoded) label.
|
||||
@ -119,7 +543,7 @@ uidna_toASCII(const UChar* src, int32_t srcLength,
|
||||
|
||||
|
||||
/**
|
||||
* This function implements the ToUnicode operation as defined in the IDNA RFC.
|
||||
* IDNA2003: This function implements the ToUnicode operation as defined in the IDNA RFC.
|
||||
* This operation is done on <b>single labels</b> before sending it to something that expects
|
||||
* Unicode names. A label is an individual part of a domain name. Labels are usually
|
||||
* separated by dots; for e.g. "www.example.com" is composed of 3 labels "www","example", and "com".
|
||||
@ -142,8 +566,6 @@ uidna_toASCII(const UChar* src, int32_t srcLength,
|
||||
* verification of decoded ACE input by applying toASCII and comparing
|
||||
* its output with source
|
||||
*
|
||||
*
|
||||
*
|
||||
* - UIDNA_USE_STD3_RULES Use STD3 ASCII rules for host name syntax restrictions
|
||||
* If this option is set and the input does not satisfy STD3 rules,
|
||||
* the operation will fail with U_IDNA_STD3_ASCII_RULES_ERROR
|
||||
@ -169,7 +591,7 @@ uidna_toUnicode(const UChar* src, int32_t srcLength,
|
||||
|
||||
|
||||
/**
|
||||
* Convenience function that implements the IDNToASCII operation as defined in the IDNA RFC.
|
||||
* IDNA2003: Convenience function that implements the IDNToASCII operation as defined in the IDNA RFC.
|
||||
* This operation is done on complete domain names, e.g: "www.example.com".
|
||||
* It is important to note that this operation can fail. If it fails, then the input
|
||||
* domain name cannot be used as an Internationalized Domain Name and the application
|
||||
@ -219,7 +641,7 @@ uidna_IDNToASCII( const UChar* src, int32_t srcLength,
|
||||
UErrorCode* status);
|
||||
|
||||
/**
|
||||
* Convenience function that implements the IDNToUnicode operation as defined in the IDNA RFC.
|
||||
* IDNA2003: Convenience function that implements the IDNToUnicode operation as defined in the IDNA RFC.
|
||||
* This operation is done on complete domain names, e.g: "www.example.com".
|
||||
*
|
||||
* <b>Note:</b> IDNA RFC specifies that a conformant application should divide a domain name
|
||||
@ -266,7 +688,7 @@ uidna_IDNToUnicode( const UChar* src, int32_t srcLength,
|
||||
UErrorCode* status);
|
||||
|
||||
/**
|
||||
* Compare two IDN strings for equivalence.
|
||||
* IDNA2003: Compare two IDN strings for equivalence.
|
||||
* This function splits the domain names into labels and compares them.
|
||||
* According to IDN RFC, whenever two labels are compared, they are
|
||||
* considered equal if and only if their ASCII forms (obtained by
|
||||
|
@ -1600,6 +1600,7 @@ public:
|
||||
* Calls u_strToUTF8WithSub().
|
||||
*
|
||||
* @param sink A ByteSink to which the UTF-8 version of the string is written.
|
||||
* sink.Flush() is called at the end.
|
||||
* @stable ICU 4.2
|
||||
* @see toUTF8String
|
||||
*/
|
||||
|
@ -151,7 +151,7 @@ unorm2_getInstance(const char *packageName,
|
||||
* Both are aliased and must not be modified or deleted while this object
|
||||
* is used.
|
||||
* The filter set should be frozen; otherwise the performance will suffer greatly.
|
||||
* @param norm2 wrapped Normalizer2 instance
|
||||
* @param norm2 wrapped UNormalizer2 instance
|
||||
* @param filterSet USet which determines the characters to be normalized
|
||||
* @param pErrorCode Standard ICU error code. Its input value must
|
||||
* pass the U_SUCCESS() test, or else the function returns
|
||||
|
@ -867,6 +867,7 @@ UnicodeString::toUTF8(ByteSink &sink) const {
|
||||
}
|
||||
if(U_SUCCESS(errorCode)) {
|
||||
sink.Append(utf8, length8);
|
||||
sink.Flush();
|
||||
}
|
||||
if(utf8IsOwned) {
|
||||
uprv_free(utf8);
|
||||
|
1333
icu4c/source/common/uts46.cpp
Normal file
1333
icu4c/source/common/uts46.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -227,7 +227,7 @@ package390: $(OUTTMPDIR)/icudata390.lst $(PKGDATA_LIST) ./icupkg.inc packagedata
|
||||
# 2005-may-05 Removed Unicode properties files (unorm.icu, uprops.icu, ucase.icu, ubidi.icu)
|
||||
# from data build. See Jitterbug 4497. (makedata.mak revision 1.117)
|
||||
#
|
||||
DAT_FILES_SHORT=pnames.icu unames.icu cnvalias.icu coll/ucadata.icu coll/invuca.icu nfc.nrm nfkc.nrm nfkc_cf.nrm
|
||||
DAT_FILES_SHORT=pnames.icu unames.icu cnvalias.icu coll/ucadata.icu coll/invuca.icu nfc.nrm nfkc.nrm nfkc_cf.nrm uts46.nrm
|
||||
DAT_FILES=$(DAT_FILES_SHORT:%=$(BUILDDIR)/%)
|
||||
|
||||
## BRK files
|
||||
|
BIN
icu4c/source/data/in/uts46.nrm
Normal file
BIN
icu4c/source/data/in/uts46.nrm
Normal file
Binary file not shown.
@ -586,7 +586,7 @@ icu4j-data-install :
|
||||
copy "$(ICUTMP)\$(ICUPKG).dat" "$(ICUOUT)\$(U_ICUDATA_NAME)$(U_ICUDATA_ENDIAN_SUFFIX).dat"
|
||||
-@erase "$(ICUTMP)\$(ICUPKG).dat"
|
||||
!ELSE
|
||||
"$(ICU_LIB_TARGET)" : $(COMMON_ICUDATA_DEPENDENCIES) $(CNV_FILES) $(CNV_FILES_SPECIAL) "$(ICUBLD_PKG)\unames.icu" "$(ICUBLD_PKG)\pnames.icu" "$(ICUBLD_PKG)\cnvalias.icu" "$(ICUBLD_PKG)\nfc.nrm" "$(ICUBLD_PKG)\nfkc.nrm" "$(ICUBLD_PKG)\nfkc_cf.nrm" "$(ICUBLD_PKG)\$(ICUCOL)\ucadata.icu" "$(ICUBLD_PKG)\$(ICUCOL)\invuca.icu" $(CURR_RES_FILES) $(LANG_RES_FILES) $(REGION_RES_FILES) $(ZONE_RES_FILES) $(BRK_FILES) $(BRK_CTD_FILES) $(BRK_RES_FILES) $(COL_COL_FILES) $(RBNF_RES_FILES) $(TRANSLIT_RES_FILES) $(ALL_RES) $(SPREP_FILES) "$(ICUBLD_PKG)\confusables.cfu"
|
||||
"$(ICU_LIB_TARGET)" : $(COMMON_ICUDATA_DEPENDENCIES) $(CNV_FILES) $(CNV_FILES_SPECIAL) "$(ICUBLD_PKG)\unames.icu" "$(ICUBLD_PKG)\pnames.icu" "$(ICUBLD_PKG)\cnvalias.icu" "$(ICUBLD_PKG)\nfc.nrm" "$(ICUBLD_PKG)\nfkc.nrm" "$(ICUBLD_PKG)\nfkc_cf.nrm" "$(ICUBLD_PKG)\uts46.nrm" "$(ICUBLD_PKG)\$(ICUCOL)\ucadata.icu" "$(ICUBLD_PKG)\$(ICUCOL)\invuca.icu" $(CURR_RES_FILES) $(LANG_RES_FILES) $(REGION_RES_FILES) $(ZONE_RES_FILES) $(BRK_FILES) $(BRK_CTD_FILES) $(BRK_RES_FILES) $(COL_COL_FILES) $(RBNF_RES_FILES) $(TRANSLIT_RES_FILES) $(ALL_RES) $(SPREP_FILES) "$(ICUBLD_PKG)\confusables.cfu"
|
||||
@echo Building icu data
|
||||
cd "$(ICUBLD_PKG)"
|
||||
"$(ICUPBIN)\pkgdata" $(COMMON_ICUDATA_ARGUMENTS) <<"$(ICUTMP)\icudata.lst"
|
||||
@ -599,6 +599,7 @@ cnvalias.icu
|
||||
nfc.nrm
|
||||
nfkc.nrm
|
||||
nfkc_cf.nrm
|
||||
uts46.nrm
|
||||
$(CNV_FILES:.cnv =.cnv
|
||||
)
|
||||
$(CNV_FILES_SPECIAL:.cnv =.cnv
|
||||
@ -945,6 +946,9 @@ res_index:table(nofallback) {
|
||||
"$(ICUBLD_PKG)\nfkc_cf.nrm": $(ICUSRCDATA_RELATIVE_PATH)\in\nfkc_cf.nrm
|
||||
"$(ICUPBIN)\icupkg" -tl $? $@
|
||||
|
||||
"$(ICUBLD_PKG)\uts46.nrm": $(ICUSRCDATA_RELATIVE_PATH)\in\uts46.nrm
|
||||
"$(ICUPBIN)\icupkg" -tl $? $@
|
||||
|
||||
"$(ICUBLD_PKG)\coll\invuca.icu": $(ICUSRCDATA_RELATIVE_PATH)\in\coll\invuca.icu
|
||||
"$(ICUPBIN)\icupkg" -tl $? $@
|
||||
|
||||
|
6618
icu4c/source/data/unidata/norm2/uts46.txt
Normal file
6618
icu4c/source/data/unidata/norm2/uts46.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2003-2009, International Business Machines
|
||||
* Copyright (C) 2003-2010, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
@ -37,6 +37,8 @@ static void TestJB4490(void);
|
||||
static void TestJB4475(void);
|
||||
static void TestLength(void);
|
||||
static void TestJB5273(void);
|
||||
static void TestUTS46(void);
|
||||
|
||||
void addIDNATest(TestNode** root);
|
||||
|
||||
|
||||
@ -64,6 +66,7 @@ addIDNATest(TestNode** root)
|
||||
addTest(root, &TestJB4475, "idna/TestJB4475");
|
||||
addTest(root, &TestLength, "idna/TestLength");
|
||||
addTest(root, &TestJB5273, "idna/TestJB5273");
|
||||
addTest(root, &TestUTS46, "idna/TestUTS46");
|
||||
}
|
||||
|
||||
static void
|
||||
@ -847,6 +850,177 @@ static void TestJB5273(){
|
||||
log_err_status(status, "uidna_toUnicode failed with error: %s\n", u_errorName(status));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test the new (ICU 4.6/2010) C API that was added for UTS #46.
|
||||
* Just an API test: Functionality is tested via C++ intltest.
|
||||
*/
|
||||
static void TestUTS46() {
|
||||
static const UChar fA_sharps16[] = { 0x66, 0x41, 0xdf, 0 };
|
||||
static const char fA_sharps8[] = { 0x66, 0x41, (char)0xc3, (char)0x9f, 0 };
|
||||
static const UChar fa_sharps16[] = { 0x66, 0x61, 0xdf, 0 };
|
||||
static const char fa_sharps8[] = { 0x66, 0x61, (char)0xc3, (char)0x9f, 0 };
|
||||
static const UChar fass16[] = { 0x66, 0x61, 0x73, 0x73, 0 };
|
||||
static const char fass8[] = { 0x66, 0x61, 0x73, 0x73, 0 };
|
||||
static const UChar fA_BEL[] = { 0x66, 0x41, 7, 0 };
|
||||
static const UChar fa_FFFD[] = { 0x66, 0x61, 0xfffd, 0 };
|
||||
|
||||
UChar dest16[10];
|
||||
char dest8[10];
|
||||
int32_t length;
|
||||
|
||||
UIDNAInfo info = UIDNA_INFO_INITIALIZER;
|
||||
UErrorCode errorCode = U_ZERO_ERROR;
|
||||
UIDNA *uts46 = uidna_openUTS46(UIDNA_USE_STD3_RULES|UIDNA_NONTRANSITIONAL_TO_UNICODE,
|
||||
&errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
log_err_status(errorCode, "uidna_openUTS46() failed: %s\n", u_errorName(errorCode));
|
||||
return;
|
||||
}
|
||||
|
||||
/* These calls should succeed. */
|
||||
length = uidna_labelToASCII(uts46, fA_sharps16, -1,
|
||||
dest16, LENGTHOF(dest16), &info, &errorCode);
|
||||
if( U_FAILURE(errorCode) || length != 4 || 0 != u_memcmp(dest16, fass16, 5) ||
|
||||
!info.isTransitionalDifferent || info.errors != 0
|
||||
) {
|
||||
log_err("uidna_labelToASCII() failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_labelToUnicode(uts46, fA_sharps16, u_strlen(fA_sharps16),
|
||||
dest16, LENGTHOF(dest16), &info, &errorCode);
|
||||
if( U_FAILURE(errorCode) || length != 3 || 0 != u_memcmp(dest16, fa_sharps16, 4) ||
|
||||
!info.isTransitionalDifferent || info.errors != 0
|
||||
) {
|
||||
log_err("uidna_labelToUnicode() failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_nameToASCII(uts46, fA_sharps16, u_strlen(fA_sharps16),
|
||||
dest16, 4, &info, &errorCode);
|
||||
if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
|
||||
length != 4 || 0 != u_memcmp(dest16, fass16, 4) ||
|
||||
!info.isTransitionalDifferent || info.errors != 0
|
||||
) {
|
||||
log_err("uidna_nameToASCII() failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_nameToUnicode(uts46, fA_sharps16, -1,
|
||||
dest16, 3, &info, &errorCode);
|
||||
if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
|
||||
length != 3 || 0 != u_memcmp(dest16, fa_sharps16, 3) ||
|
||||
!info.isTransitionalDifferent || info.errors != 0
|
||||
) {
|
||||
log_err("uidna_nameToUnicode() failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_labelToASCII_UTF8(uts46, fA_sharps8, -1,
|
||||
dest8, LENGTHOF(dest8), &info, &errorCode);
|
||||
if( U_FAILURE(errorCode) || length != 4 || 0 != memcmp(dest8, fass8, 5) ||
|
||||
!info.isTransitionalDifferent || info.errors != 0
|
||||
) {
|
||||
log_err("uidna_labelToASCII_UTF8() failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_labelToUnicodeUTF8(uts46, fA_sharps8, strlen(fA_sharps8),
|
||||
dest8, LENGTHOF(dest8), &info, &errorCode);
|
||||
if( U_FAILURE(errorCode) || length != 4 || 0 != memcmp(dest8, fa_sharps8, 5) ||
|
||||
!info.isTransitionalDifferent || info.errors != 0
|
||||
) {
|
||||
log_err("uidna_labelToUnicodeUTF8() failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_nameToASCII_UTF8(uts46, fA_sharps8, strlen(fA_sharps8),
|
||||
dest8, 4, &info, &errorCode);
|
||||
if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
|
||||
length != 4 || 0 != memcmp(dest8, fass8, 4) ||
|
||||
!info.isTransitionalDifferent || info.errors != 0
|
||||
) {
|
||||
log_err("uidna_nameToASCII_UTF8() failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_nameToUnicodeUTF8(uts46, fA_sharps8, -1,
|
||||
dest8, 4, &info, &errorCode);
|
||||
if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
|
||||
length != 4 || 0 != memcmp(dest8, fa_sharps8, 4) ||
|
||||
!info.isTransitionalDifferent || info.errors != 0
|
||||
) {
|
||||
log_err("uidna_nameToUnicodeUTF8() failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_nameToASCII(uts46, NULL, 0,
|
||||
dest16, 0, &info, &errorCode);
|
||||
if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
|
||||
length != 0 ||
|
||||
info.isTransitionalDifferent || info.errors != UIDNA_ERROR_EMPTY_LABEL
|
||||
) {
|
||||
log_err("uidna_nameToASCII(empty) failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_nameToUnicode(uts46, fA_BEL, -1,
|
||||
dest16, 3, &info, &errorCode);
|
||||
if( errorCode != U_STRING_NOT_TERMINATED_WARNING ||
|
||||
length != 3 || 0 != u_memcmp(dest16, fa_FFFD, 3) ||
|
||||
info.isTransitionalDifferent || info.errors == 0
|
||||
) {
|
||||
log_err("uidna_nameToUnicode(fa<BEL>) failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
|
||||
/* These calls should fail. */
|
||||
errorCode = U_USELESS_COLLATOR_ERROR;
|
||||
length = uidna_labelToASCII(uts46, fA_sharps16, -1,
|
||||
dest16, LENGTHOF(dest16), &info, &errorCode);
|
||||
if(errorCode != U_USELESS_COLLATOR_ERROR) {
|
||||
log_err("uidna_labelToASCII(failure) failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_labelToUnicode(uts46, fA_sharps16, u_strlen(fA_sharps16),
|
||||
dest16, LENGTHOF(dest16), NULL, &errorCode);
|
||||
if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
|
||||
log_err("uidna_labelToUnicode(UIDNAInfo=NULL) failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_nameToASCII(uts46, NULL, u_strlen(fA_sharps16),
|
||||
dest16, 4, &info, &errorCode);
|
||||
if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
|
||||
log_err("uidna_nameToASCII(src=NULL) failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_nameToUnicode(uts46, fA_sharps16, -2,
|
||||
dest16, 3, &info, &errorCode);
|
||||
if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
|
||||
log_err("uidna_nameToUnicode(length<-1) failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_labelToASCII_UTF8(uts46, fA_sharps8, -1,
|
||||
NULL, LENGTHOF(dest8), &info, &errorCode);
|
||||
if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
|
||||
log_err("uidna_labelToASCII_UTF8(dest=NULL) failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_labelToUnicodeUTF8(uts46, fA_sharps8, strlen(fA_sharps8),
|
||||
dest8, -1, &info, &errorCode);
|
||||
if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
|
||||
log_err("uidna_labelToUnicodeUTF8(capacity<0) failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_nameToASCII_UTF8(uts46, dest8, strlen(fA_sharps8),
|
||||
dest8, 4, &info, &errorCode);
|
||||
if(errorCode != U_ILLEGAL_ARGUMENT_ERROR) {
|
||||
log_err("uidna_nameToASCII_UTF8(src==dest!=NULL) failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
errorCode = U_ZERO_ERROR;
|
||||
length = uidna_nameToUnicodeUTF8(uts46, fA_sharps8, -1,
|
||||
dest8, 3, &info, &errorCode);
|
||||
if(errorCode != U_BUFFER_OVERFLOW_ERROR || length != 4) {
|
||||
log_err("uidna_nameToUnicodeUTF8() overflow failed: %s\n", u_errorName(errorCode));
|
||||
}
|
||||
|
||||
uidna_close(uts46);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -857,4 +1031,3 @@ static void TestJB5273(){
|
||||
* End:
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -54,8 +54,8 @@ itrbbi.o rbbiapts.o rbbitst.o ittrans.o transapi.o cpdtrtst.o \
|
||||
testutil.o transrt.o trnserr.o normconf.o sfwdchit.o \
|
||||
jamotest.o srchtest.o reptest.o regextst.o \
|
||||
itrbnf.o itrbnfrt.o itrbnfp.o ucaconf.o icusvtst.o \
|
||||
uobjtest.o idnaref.o idnaconf.o nptrans.o punyref.o testidn.o testidna.o incaltst.o \
|
||||
calcasts.o v32test.o uvectest.o textfile.o tokiter.o utxttest.o \
|
||||
uobjtest.o idnaref.o idnaconf.o nptrans.o punyref.o testidn.o testidna.o uts46test.o \
|
||||
incaltst.o calcasts.o v32test.o uvectest.o textfile.o tokiter.o utxttest.o \
|
||||
windttst.o winnmtst.o winutil.o csdetest.o tzrulets.o tzoffloc.o tzfmttst.o ssearch.o dtifmtts.o \
|
||||
tufmtts.o itspoof.o simplethread.o bidiconf.o locnmtst.o dcfmtest.o
|
||||
|
||||
|
@ -258,6 +258,10 @@ IntlTest::appendHex(uint32_t number,
|
||||
return target;
|
||||
}
|
||||
|
||||
static inline UBool isPrintable(UChar32 c) {
|
||||
return c <= 0x7E && (c >= 0x20 || c == 9 || c == 0xA || c == 0xD);
|
||||
}
|
||||
|
||||
// Replace nonprintable characters with unicode escapes
|
||||
UnicodeString&
|
||||
IntlTest::prettify(const UnicodeString &source,
|
||||
@ -271,9 +275,9 @@ IntlTest::prettify(const UnicodeString &source,
|
||||
for (i = 0; i < source.length(); )
|
||||
{
|
||||
UChar32 ch = source.char32At(i);
|
||||
i += UTF_CHAR_LENGTH(ch);
|
||||
i += U16_LENGTH(ch);
|
||||
|
||||
if (ch < 0x09 || (ch > 0x0A && ch < 0x20)|| ch > 0x7E)
|
||||
if (!isPrintable(ch))
|
||||
{
|
||||
if (ch <= 0xFFFF) {
|
||||
target += "\\u";
|
||||
@ -306,9 +310,9 @@ IntlTest::prettify(const UnicodeString &source, UBool parseBackslash)
|
||||
for (i = 0; i < source.length();)
|
||||
{
|
||||
UChar32 ch = source.char32At(i);
|
||||
i += UTF_CHAR_LENGTH(ch);
|
||||
i += U16_LENGTH(ch);
|
||||
|
||||
if (ch < 0x09 || (ch > 0x0A && ch < 0x20)|| ch > 0x7E)
|
||||
if (!isPrintable(ch))
|
||||
{
|
||||
if (parseBackslash) {
|
||||
// If we are preceded by an odd number of backslashes,
|
||||
@ -1466,12 +1470,11 @@ const char * IntlTest::pathToDataDirectory()
|
||||
|
||||
/*
|
||||
* This is a variant of cintltst/ccolltst.c:CharsToUChars().
|
||||
* It converts a character string into a UnicodeString, with
|
||||
* It converts an invariant-character string into a UnicodeString, with
|
||||
* unescaping \u sequences.
|
||||
*/
|
||||
UnicodeString CharsToUnicodeString(const char* chars){
|
||||
UnicodeString str(chars, ""); // Invariant conversion
|
||||
return str.unescape();
|
||||
return UnicodeString(chars, -1, US_INV).unescape();
|
||||
}
|
||||
|
||||
UnicodeString ctou(const char* chars) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2009, International Business Machines Corporation and
|
||||
* Copyright (c) 1997-2010, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
|
||||
@ -67,6 +67,36 @@ UnicodeString toString(int32_t n);
|
||||
} \
|
||||
break
|
||||
|
||||
// More convenient macros. These allow easy reordering of the test cases.
|
||||
//
|
||||
//| void MyTest::runIndexedTest(int32_t index, UBool exec,
|
||||
//| const char* &name, char* /*par*/) {
|
||||
//| TESTCASE_AUTO_BEGIN;
|
||||
//| TESTCASE_AUTO(TestSomething);
|
||||
//| TESTCASE_AUTO(TestSomethingElse);
|
||||
//| TESTCASE_AUTO(TestAnotherThing);
|
||||
//| TESTCASE_AUTO_END;
|
||||
//| }
|
||||
#define TESTCASE_AUTO_BEGIN \
|
||||
for(;;) { \
|
||||
int32_t testCaseAutoNumber = 0
|
||||
|
||||
#define TESTCASE_AUTO(test) \
|
||||
if (index == testCaseAutoNumber++) { \
|
||||
name = #test; \
|
||||
if (exec) { \
|
||||
logln(#test "---"); \
|
||||
logln(); \
|
||||
test(); \
|
||||
} \
|
||||
break; \
|
||||
}
|
||||
|
||||
#define TESTCASE_AUTO_END \
|
||||
name = ""; \
|
||||
break; \
|
||||
}
|
||||
|
||||
class IntlTest : public TestLog {
|
||||
public:
|
||||
|
||||
|
@ -1286,6 +1286,10 @@
|
||||
RelativePath=".\testidna.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\uts46test.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="locales & resources"
|
||||
|
@ -271,6 +271,7 @@ void LocalPointerTest::TestLocalArray() {
|
||||
#include "unicode/ucnvsel.h"
|
||||
#include "unicode/ucal.h"
|
||||
#include "unicode/udatpg.h"
|
||||
#include "unicode/uidna.h"
|
||||
#include "unicode/uldnames.h"
|
||||
#include "unicode/umsg.h"
|
||||
#include "unicode/unorm2.h"
|
||||
@ -345,6 +346,17 @@ void LocalPointerTest::TestLocalXyzPointer() {
|
||||
}
|
||||
#endif /* !UCONFIG_NO_NORMALIZATION */
|
||||
|
||||
#if !UCONFIG_NO_IDNA
|
||||
LocalUIDNAPointer idna(uidna_openUTS46(0, errorCode));
|
||||
if(errorCode.logIfFailureAndReset("uidna_openUTS46()")) {
|
||||
return;
|
||||
}
|
||||
if(idna.isNull()) {
|
||||
errln("LocalUIDNAPointer failure");
|
||||
return;
|
||||
}
|
||||
#endif /* !UCONFIG_NO_IDNA */
|
||||
|
||||
#if !UCONFIG_NO_REGULAR_EXPRESSIONS
|
||||
UnicodeString pattern=UNICODE_STRING_SIMPLE("abc|xy+z");
|
||||
LocalURegularExpressionPointer regex(
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2003-2009, International Business Machines
|
||||
* Copyright (C) 2003-2010, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
@ -22,6 +22,7 @@
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "unicode/localpointer.h"
|
||||
#include "unicode/ustring.h"
|
||||
#include "unicode/usprep.h"
|
||||
#include "unicode/uniset.h"
|
||||
@ -1235,6 +1236,8 @@ void TestIDNA::testRootLabelSeparator(const char* testName, CompareFunc func,
|
||||
// runIndexedTest
|
||||
//---------------------------------------------
|
||||
|
||||
extern IntlTest *createUTS46Test();
|
||||
|
||||
void TestIDNA::runIndexedTest( int32_t index, UBool exec, const char* &name, char* par)
|
||||
{
|
||||
if (exec) logln((UnicodeString)"TestSuite IDNA API ");
|
||||
@ -1266,6 +1269,14 @@ void TestIDNA::runIndexedTest( int32_t index, UBool exec, const char* &name, cha
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 13:
|
||||
name = "UTS46Test";
|
||||
if (exec) {
|
||||
logln("TestSuite UTS46Test---"); logln();
|
||||
LocalPointer<IntlTest> test(createUTS46Test());
|
||||
callTest(*test, par);
|
||||
}
|
||||
break;
|
||||
default: name = ""; break; /*needed to end loop*/
|
||||
}
|
||||
}
|
||||
|
@ -263,6 +263,7 @@ UObject *UObjectTest::testClassNoClassID(UObject *obj, const char *className, co
|
||||
#include "unicode/fmtable.h"
|
||||
#include "unicode/format.h"
|
||||
#include "unicode/gregocal.h"
|
||||
#include "unicode/idna.h"
|
||||
#include "unicode/locdspnm.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/msgfmt.h"
|
||||
@ -325,6 +326,9 @@ void UObjectTest::testIDs()
|
||||
UnicodeSet emptySet;
|
||||
TESTCLASSID_NONE_CTOR(FilteredNormalizer2, (*noNormalizer2, emptySet));
|
||||
TESTCLASSID_FACTORY(CanonicalIterator, new CanonicalIterator(UnicodeString("abc"), status));
|
||||
#endif
|
||||
#if !UCONFIG_NO_IDNA
|
||||
TESTCLASSID_NONE_FACTORY(IDNA, IDNA::createUTS46Instance(0, status));
|
||||
#endif
|
||||
//TESTCLASSID_DEFAULT(CollationElementIterator);
|
||||
#if !UCONFIG_NO_COLLATION
|
||||
|
@ -1820,6 +1820,14 @@ UnicodeStringTest::TestUTF32() {
|
||||
}
|
||||
}
|
||||
|
||||
class TestCheckedArrayByteSink : public CheckedArrayByteSink {
|
||||
public:
|
||||
TestCheckedArrayByteSink(char* outbuf, int32_t capacity)
|
||||
: CheckedArrayByteSink(outbuf, capacity), calledFlush(FALSE) {}
|
||||
virtual void Flush() { calledFlush = TRUE; }
|
||||
UBool calledFlush;
|
||||
};
|
||||
|
||||
void
|
||||
UnicodeStringTest::TestUTF8() {
|
||||
static const uint8_t utf8[] = {
|
||||
@ -1869,13 +1877,16 @@ UnicodeStringTest::TestUTF8() {
|
||||
UnicodeString us(FALSE, utf16, LENGTHOF(utf16));
|
||||
|
||||
char buffer[64];
|
||||
CheckedArrayByteSink sink(buffer, (int32_t)sizeof(buffer));
|
||||
TestCheckedArrayByteSink sink(buffer, (int32_t)sizeof(buffer));
|
||||
us.toUTF8(sink);
|
||||
if( sink.NumberOfBytesWritten() != (int32_t)sizeof(expected_utf8) ||
|
||||
0 != uprv_memcmp(buffer, expected_utf8, sizeof(expected_utf8))
|
||||
) {
|
||||
errln("UnicodeString::toUTF8() did not create the expected string.");
|
||||
}
|
||||
if(!sink.calledFlush) {
|
||||
errln("UnicodeString::toUTF8(sink) did not sink.Flush().");
|
||||
}
|
||||
#if U_HAVE_STD_STRING
|
||||
// Initial contents for testing that toUTF8String() appends.
|
||||
U_STD_NSQ string result8 = "-->";
|
||||
|
830
icu4c/source/test/intltest/uts46test.cpp
Normal file
830
icu4c/source/test/intltest/uts46test.cpp
Normal file
@ -0,0 +1,830 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2010, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
* file name: uts46test.cpp
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2010may05
|
||||
* created by: Markus W. Scherer
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_IDNA
|
||||
|
||||
#include <string.h>
|
||||
#include "unicode/bytestream.h"
|
||||
#include "unicode/idna.h"
|
||||
#include "unicode/localpointer.h"
|
||||
#include "unicode/std_string.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include "unicode/uidna.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "intltest.h"
|
||||
|
||||
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
||||
|
||||
class UTS46Test : public IntlTest {
|
||||
public:
|
||||
UTS46Test() : trans(NULL), nontrans(NULL) {}
|
||||
virtual ~UTS46Test();
|
||||
|
||||
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par=NULL);
|
||||
void TestAPI();
|
||||
void TestNotSTD3();
|
||||
void TestSomeCases();
|
||||
private:
|
||||
IDNA *trans, *nontrans;
|
||||
};
|
||||
|
||||
extern IntlTest *createUTS46Test() {
|
||||
return new UTS46Test();
|
||||
}
|
||||
|
||||
UTS46Test::~UTS46Test() {
|
||||
delete trans;
|
||||
delete nontrans;
|
||||
}
|
||||
|
||||
void UTS46Test::runIndexedTest(int32_t index, UBool exec, const char *&name, char * /*par*/) {
|
||||
if(exec) {
|
||||
logln("TestSuite UTS46Test: ");
|
||||
if(trans==NULL) {
|
||||
IcuTestErrorCode errorCode(*this, "init/createUTS46Instance()");
|
||||
trans=IDNA::createUTS46Instance(
|
||||
UIDNA_USE_STD3_RULES|UIDNA_CHECK_BIDI|UIDNA_CHECK_CONTEXTJ,
|
||||
errorCode);
|
||||
nontrans=IDNA::createUTS46Instance(
|
||||
UIDNA_USE_STD3_RULES|UIDNA_CHECK_BIDI|UIDNA_CHECK_CONTEXTJ|
|
||||
UIDNA_NONTRANSITIONAL_TO_ASCII|UIDNA_NONTRANSITIONAL_TO_UNICODE,
|
||||
errorCode);
|
||||
if(errorCode.logDataIfFailureAndReset("createUTS46Instance()")) {
|
||||
name="";
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
TESTCASE_AUTO_BEGIN;
|
||||
TESTCASE_AUTO(TestAPI);
|
||||
TESTCASE_AUTO(TestNotSTD3);
|
||||
TESTCASE_AUTO(TestSomeCases);
|
||||
TESTCASE_AUTO_END;
|
||||
}
|
||||
|
||||
const uint32_t severeErrors=
|
||||
UIDNA_ERROR_LEADING_COMBINING_MARK|
|
||||
UIDNA_ERROR_DISALLOWED|
|
||||
UIDNA_ERROR_PUNYCODE|
|
||||
UIDNA_ERROR_LABEL_HAS_DOT|
|
||||
UIDNA_ERROR_INVALID_ACE_LABEL;
|
||||
|
||||
static UBool isASCII(const UnicodeString &str) {
|
||||
const UChar *s=str.getBuffer();
|
||||
int32_t length=str.length();
|
||||
for(int32_t i=0; i<length; ++i) {
|
||||
if(s[i]>=0x80) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
class TestCheckedArrayByteSink : public CheckedArrayByteSink {
|
||||
public:
|
||||
TestCheckedArrayByteSink(char* outbuf, int32_t capacity)
|
||||
: CheckedArrayByteSink(outbuf, capacity), calledFlush(FALSE) {}
|
||||
virtual CheckedArrayByteSink& Reset() {
|
||||
CheckedArrayByteSink::Reset();
|
||||
calledFlush = FALSE;
|
||||
return *this;
|
||||
}
|
||||
virtual void Flush() { calledFlush = TRUE; }
|
||||
UBool calledFlush;
|
||||
};
|
||||
|
||||
void UTS46Test::TestAPI() {
|
||||
UErrorCode errorCode=U_ZERO_ERROR;
|
||||
UnicodeString result;
|
||||
IDNAInfo info;
|
||||
UnicodeString input=UNICODE_STRING_SIMPLE("www.eXample.cOm");
|
||||
UnicodeString expected=UNICODE_STRING_SIMPLE("www.example.com");
|
||||
trans->nameToASCII(input, result, info, errorCode);
|
||||
if(U_FAILURE(errorCode) || info.hasErrors() || result!=expected) {
|
||||
errln("T.nameToASCII(www.example.com) info.errors=%04lx result matches=%d %s",
|
||||
(long)info.getErrors(), result==expected, u_errorName(errorCode));
|
||||
}
|
||||
errorCode=U_USELESS_COLLATOR_ERROR;
|
||||
trans->nameToUnicode(input, result, info, errorCode);
|
||||
if(errorCode!=U_USELESS_COLLATOR_ERROR || !result.isBogus()) {
|
||||
errln("T.nameToUnicode(U_FAILURE) did not preserve the errorCode "
|
||||
"or not result.setToBogus() - %s",
|
||||
u_errorName(errorCode));
|
||||
}
|
||||
errorCode=U_ZERO_ERROR;
|
||||
input.setToBogus();
|
||||
result=UNICODE_STRING_SIMPLE("quatsch");
|
||||
nontrans->labelToASCII(input, result, info, errorCode);
|
||||
if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || !result.isBogus()) {
|
||||
errln("N.labelToASCII(bogus) did not set illegal-argument-error "
|
||||
"or not result.setToBogus() - %s",
|
||||
u_errorName(errorCode));
|
||||
}
|
||||
errorCode=U_ZERO_ERROR;
|
||||
input=UNICODE_STRING_SIMPLE("xn--bcher.de-65a");
|
||||
expected=UNICODE_STRING_SIMPLE("xn--bcher\\uFFFDde-65a").unescape();
|
||||
nontrans->labelToASCII(input, result, info, errorCode);
|
||||
if( U_FAILURE(errorCode) ||
|
||||
info.getErrors()!=(UIDNA_ERROR_LABEL_HAS_DOT|UIDNA_ERROR_INVALID_ACE_LABEL) ||
|
||||
result!=expected
|
||||
) {
|
||||
errln("N.labelToASCII(label-with-dot) failed with errors %04lx - %s",
|
||||
info.getErrors(), u_errorName(errorCode));
|
||||
}
|
||||
// UTF-8
|
||||
char buffer[100];
|
||||
TestCheckedArrayByteSink sink(buffer, LENGTHOF(buffer));
|
||||
errorCode=U_ZERO_ERROR;
|
||||
nontrans->labelToUnicodeUTF8(StringPiece(NULL, 5), sink, info, errorCode);
|
||||
if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || sink.NumberOfBytesWritten()!=0) {
|
||||
errln("N.labelToUnicodeUTF8(StringPiece(NULL, 5)) did not set illegal-argument-error ",
|
||||
"or did output something - %s",
|
||||
u_errorName(errorCode));
|
||||
}
|
||||
|
||||
sink.Reset();
|
||||
errorCode=U_ZERO_ERROR;
|
||||
nontrans->nameToASCII_UTF8(StringPiece(), sink, info, errorCode);
|
||||
if(U_FAILURE(errorCode) || sink.NumberOfBytesWritten()!=0 || !sink.calledFlush) {
|
||||
errln("N.nameToASCII_UTF8(empty) failed - %s",
|
||||
u_errorName(errorCode));
|
||||
}
|
||||
|
||||
static const char s[]={ 0x61, (char)0xc3, (char)0x9f };
|
||||
sink.Reset();
|
||||
errorCode=U_USELESS_COLLATOR_ERROR;
|
||||
nontrans->nameToUnicodeUTF8(StringPiece(s, 3), sink, info, errorCode);
|
||||
if(errorCode!=U_USELESS_COLLATOR_ERROR || sink.NumberOfBytesWritten()!=0) {
|
||||
errln("N.nameToUnicode_UTF8(U_FAILURE) did not preserve the errorCode "
|
||||
"or did output something - %s",
|
||||
u_errorName(errorCode));
|
||||
}
|
||||
|
||||
sink.Reset();
|
||||
errorCode=U_ZERO_ERROR;
|
||||
trans->labelToUnicodeUTF8(StringPiece(s, 3), sink, info, errorCode);
|
||||
if( U_FAILURE(errorCode) || sink.NumberOfBytesWritten()!=3 ||
|
||||
buffer[0]!=0x61 || buffer[1]!=0x73 || buffer[2]!=0x73 ||
|
||||
!sink.calledFlush
|
||||
) {
|
||||
errln("T.labelToUnicodeUTF8(a sharp-s) failed - %s",
|
||||
u_errorName(errorCode));
|
||||
}
|
||||
|
||||
sink.Reset();
|
||||
errorCode=U_ZERO_ERROR;
|
||||
// "eXampLe.cOm"
|
||||
static const char eX[]={ 0x65, 0x58, 0x61, 0x6d, 0x70, 0x4c, 0x65, 0x2e, 0x63, 0x4f, 0x6d, 0 };
|
||||
// "example.com"
|
||||
static const char ex[]={ 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d };
|
||||
trans->nameToUnicodeUTF8(eX, sink, info, errorCode);
|
||||
if( U_FAILURE(errorCode) || sink.NumberOfBytesWritten()!=11 ||
|
||||
0!=memcmp(ex, buffer, 11) || !sink.calledFlush
|
||||
) {
|
||||
errln("T.nameToUnicodeUTF8(eXampLe.cOm) failed - %s",
|
||||
u_errorName(errorCode));
|
||||
}
|
||||
}
|
||||
|
||||
void UTS46Test::TestNotSTD3() {
|
||||
IcuTestErrorCode errorCode(*this, "TestNotSTD3()");
|
||||
char buffer[400];
|
||||
LocalPointer<IDNA> not3(IDNA::createUTS46Instance(UIDNA_CHECK_BIDI, errorCode));
|
||||
if(errorCode.isFailure()) {
|
||||
return;
|
||||
}
|
||||
UnicodeString input=UNICODE_STRING_SIMPLE("\\u0000A_2+2=4\\u000A.e\\u00DFen.net").unescape();
|
||||
UnicodeString result;
|
||||
IDNAInfo info;
|
||||
if( not3->nameToUnicode(input, result, info, errorCode)!=
|
||||
UNICODE_STRING_SIMPLE("\\u0000a_2+2=4\\u000A.essen.net").unescape() ||
|
||||
info.hasErrors()
|
||||
) {
|
||||
prettify(result).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
errln("notSTD3.nameToUnicode(non-LDH ASCII) unexpected errors %04lx string %s",
|
||||
(long)info.getErrors(), buffer);
|
||||
}
|
||||
// A space (BiDi class WS) is not allowed in a BiDi domain name.
|
||||
input=UNICODE_STRING_SIMPLE("a z.xn--4db.edu");
|
||||
not3->nameToASCII(input, result, info, errorCode);
|
||||
if(result!=input || info.getErrors()!=UIDNA_ERROR_BIDI) {
|
||||
errln("notSTD3.nameToASCII(ASCII-with-space.alef.edu) failed");
|
||||
}
|
||||
}
|
||||
|
||||
struct TestCase {
|
||||
// Input string and options string (Nontransitional/Transitional/Both).
|
||||
const char *s, *o;
|
||||
// Expected Unicode result string.
|
||||
const char *u;
|
||||
uint32_t errors;
|
||||
};
|
||||
|
||||
static const TestCase testCases[]={
|
||||
{ "www.eXample.cOm", "B", // all ASCII
|
||||
"www.example.com", 0 },
|
||||
{ "B\\u00FCcher.de", "B", // u-umlaut
|
||||
"b\\u00FCcher.de", 0 },
|
||||
{ "\\u00D6BB", "B", // O-umlaut
|
||||
"\\u00F6bb", 0 },
|
||||
{ "fa\\u00DF.de", "N", // sharp s
|
||||
"fa\\u00DF.de", 0 },
|
||||
{ "fa\\u00DF.de", "T", // sharp s
|
||||
"fass.de", 0 },
|
||||
{ "XN--fA-hia.dE", "B", // sharp s in Punycode
|
||||
"fa\\u00DF.de", 0 },
|
||||
{ "\\u03B2\\u03CC\\u03BB\\u03BF\\u03C2.com", "N", // Greek with final sigma
|
||||
"\\u03B2\\u03CC\\u03BB\\u03BF\\u03C2.com", 0 },
|
||||
{ "\\u03B2\\u03CC\\u03BB\\u03BF\\u03C2.com", "T", // Greek with final sigma
|
||||
"\\u03B2\\u03CC\\u03BB\\u03BF\\u03C3.com", 0 },
|
||||
{ "xn--nxasmm1c", "B", // Greek with final sigma in Punycode
|
||||
"\\u03B2\\u03CC\\u03BB\\u03BF\\u03C2", 0 },
|
||||
{ "www.\\u0DC1\\u0DCA\\u200D\\u0DBB\\u0DD3.com", "N", // "Sri" in "Sri Lanka" has a ZWJ
|
||||
"www.\\u0DC1\\u0DCA\\u200D\\u0DBB\\u0DD3.com", 0 },
|
||||
{ "www.\\u0DC1\\u0DCA\\u200D\\u0DBB\\u0DD3.com", "T", // "Sri" in "Sri Lanka" has a ZWJ
|
||||
"www.\\u0DC1\\u0DCA\\u0DBB\\u0DD3.com", 0 },
|
||||
{ "www.xn--10cl1a0b660p.com", "B", // "Sri" in Punycode
|
||||
"www.\\u0DC1\\u0DCA\\u200D\\u0DBB\\u0DD3.com", 0 },
|
||||
{ "\\u0646\\u0627\\u0645\\u0647\\u200C\\u0627\\u06CC", "N", // ZWNJ
|
||||
"\\u0646\\u0627\\u0645\\u0647\\u200C\\u0627\\u06CC", 0 },
|
||||
{ "\\u0646\\u0627\\u0645\\u0647\\u200C\\u0627\\u06CC", "T", // ZWNJ
|
||||
"\\u0646\\u0627\\u0645\\u0647\\u0627\\u06CC", 0 },
|
||||
{ "xn--mgba3gch31f060k.com", "B", // ZWNJ in Punycode
|
||||
"\\u0646\\u0627\\u0645\\u0647\\u200C\\u0627\\u06CC.com", 0 },
|
||||
{ "a.b\\uFF0Ec\\u3002d\\uFF61", "B",
|
||||
"a.b.c.d.", 0 },
|
||||
{ "U\\u0308.xn--tda", "B", // U+umlaut.u-umlaut
|
||||
"\\u00FC.\\u00FC", 0 },
|
||||
{ "xn--u-ccb", "B", // u+umlaut in Punycode
|
||||
"xn--u-ccb\\uFFFD", UIDNA_ERROR_INVALID_ACE_LABEL },
|
||||
{ "a\\u2488com", "B", // contains 1-dot
|
||||
"a\\uFFFDcom", UIDNA_ERROR_DISALLOWED },
|
||||
{ "xn--a-ecp.ru", "B", // contains 1-dot in Punycode
|
||||
"xn--a-ecp\\uFFFD.ru", UIDNA_ERROR_INVALID_ACE_LABEL },
|
||||
{ "xn--0.pt", "B", // invalid Punycode
|
||||
"xn--0\\uFFFD.pt", UIDNA_ERROR_PUNYCODE },
|
||||
{ "xn--a.pt", "B", // U+0080
|
||||
"xn--a\\uFFFD.pt", UIDNA_ERROR_INVALID_ACE_LABEL },
|
||||
{ "xn--a-\\u00C4.pt", "B", // invalid Punycode
|
||||
"xn--a-\\u00E4.pt", UIDNA_ERROR_PUNYCODE },
|
||||
{ "\\u65E5\\u672C\\u8A9E\\u3002\\uFF2A\\uFF30", "B", // Japanese with fullwidth ".jp"
|
||||
"\\u65E5\\u672C\\u8A9E.jp", 0 },
|
||||
{ "\\u2615", "B", "\\u2615", 0 }, // Unicode 4.0 HOT BEVERAGE
|
||||
// many deviation characters, test the special mapping code
|
||||
{ "1.a\\u00DF\\u200C\\u200Db\\u200C\\u200Dc\\u00DF\\u00DF\\u00DF\\u00DFd"
|
||||
"\\u03C2\\u03C3\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFe"
|
||||
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFx"
|
||||
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFy"
|
||||
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u0302\\u00DFz", "N",
|
||||
"1.a\\u00DF\\u200C\\u200Db\\u200C\\u200Dc\\u00DF\\u00DF\\u00DF\\u00DFd"
|
||||
"\\u03C2\\u03C3\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFe"
|
||||
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFx"
|
||||
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFy"
|
||||
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u0302\\u00DFz",
|
||||
UIDNA_ERROR_LABEL_TOO_LONG|UIDNA_ERROR_CONTEXTJ },
|
||||
{ "1.a\\u00DF\\u200C\\u200Db\\u200C\\u200Dc\\u00DF\\u00DF\\u00DF\\u00DFd"
|
||||
"\\u03C2\\u03C3\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFe"
|
||||
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFx"
|
||||
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DFy"
|
||||
"\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u00DF\\u0302\\u00DFz", "T",
|
||||
"1.assbcssssssssd"
|
||||
"\\u03C3\\u03C3sssssssssssssssse"
|
||||
"ssssssssssssssssssssx"
|
||||
"ssssssssssssssssssssy"
|
||||
"sssssssssssssss\\u015Dssz", UIDNA_ERROR_LABEL_TOO_LONG },
|
||||
// "xn--bss" with deviation characters
|
||||
{ "\\u200Cx\\u200Dn\\u200C-\\u200D-b\\u00DF", "N",
|
||||
"\\u200Cx\\u200Dn\\u200C-\\u200D-b\\u00DF", UIDNA_ERROR_CONTEXTJ },
|
||||
{ "\\u200Cx\\u200Dn\\u200C-\\u200D-b\\u00DF", "T",
|
||||
"\\u5919", 0 },
|
||||
// "xn--bssffl" written as:
|
||||
// 02E3 MODIFIER LETTER SMALL X
|
||||
// 034F COMBINING GRAPHEME JOINER (ignored)
|
||||
// 2115 DOUBLE-STRUCK CAPITAL N
|
||||
// 200B ZERO WIDTH SPACE (ignored)
|
||||
// FE63 SMALL HYPHEN-MINUS
|
||||
// 00AD SOFT HYPHEN (ignored)
|
||||
// FF0D FULLWIDTH HYPHEN-MINUS
|
||||
// 180C MONGOLIAN FREE VARIATION SELECTOR TWO (ignored)
|
||||
// 212C SCRIPT CAPITAL B
|
||||
// FE00 VARIATION SELECTOR-1 (ignored)
|
||||
// 017F LATIN SMALL LETTER LONG S
|
||||
// 2064 INVISIBLE PLUS (ignored)
|
||||
// 1D530 MATHEMATICAL FRAKTUR SMALL S
|
||||
// E01EF VARIATION SELECTOR-256 (ignored)
|
||||
// FB04 LATIN SMALL LIGATURE FFL
|
||||
{ "\\u02E3\\u034F\\u2115\\u200B\\uFE63\\u00AD\\uFF0D\\u180C"
|
||||
"\\u212C\\uFE00\\u017F\\u2064\\U0001D530\\U000E01EF\\uFB04", "B",
|
||||
"\\u5921\\u591E\\u591C\\u5919", 0 },
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901", 0 },
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901.", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901.", 0 },
|
||||
// Domain name >256 characters, forces slow path in UTF-8 processing.
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"12345678901234567890123456789012345678901234567890123456789012", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"12345678901234567890123456789012345678901234567890123456789012",
|
||||
UIDNA_ERROR_DOMAIN_NAME_TOO_LONG },
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789\\u05D0", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789\\u05D0",
|
||||
UIDNA_ERROR_DOMAIN_NAME_TOO_LONG|UIDNA_ERROR_BIDI },
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901234."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901234."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890",
|
||||
UIDNA_ERROR_LABEL_TOO_LONG },
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901234."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890.", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901234."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890.",
|
||||
UIDNA_ERROR_LABEL_TOO_LONG },
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901234."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901234."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901",
|
||||
UIDNA_ERROR_LABEL_TOO_LONG|UIDNA_ERROR_DOMAIN_NAME_TOO_LONG },
|
||||
// label length 63: xn--1234567890123456789012345678901234567890123456789012345-9te
|
||||
{ "\\u00E41234567890123456789012345678901234567890123456789012345", "B",
|
||||
"\\u00E41234567890123456789012345678901234567890123456789012345", 0 },
|
||||
{ "1234567890\\u00E41234567890123456789012345678901234567890123456", "B",
|
||||
"1234567890\\u00E41234567890123456789012345678901234567890123456", UIDNA_ERROR_LABEL_TOO_LONG },
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890\\u00E4123456789012345678901234567890123456789012345."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890\\u00E4123456789012345678901234567890123456789012345."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901", 0 },
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890\\u00E4123456789012345678901234567890123456789012345."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901.", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890\\u00E4123456789012345678901234567890123456789012345."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901.", 0 },
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890\\u00E4123456789012345678901234567890123456789012345."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"12345678901234567890123456789012345678901234567890123456789012", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890\\u00E4123456789012345678901234567890123456789012345."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"12345678901234567890123456789012345678901234567890123456789012",
|
||||
UIDNA_ERROR_DOMAIN_NAME_TOO_LONG },
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890\\u00E41234567890123456789012345678901234567890123456."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890\\u00E41234567890123456789012345678901234567890123456."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890",
|
||||
UIDNA_ERROR_LABEL_TOO_LONG },
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890\\u00E41234567890123456789012345678901234567890123456."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890.", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890\\u00E41234567890123456789012345678901234567890123456."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"123456789012345678901234567890123456789012345678901234567890.",
|
||||
UIDNA_ERROR_LABEL_TOO_LONG },
|
||||
{ "123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890\\u00E41234567890123456789012345678901234567890123456."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901", "B",
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890\\u00E41234567890123456789012345678901234567890123456."
|
||||
"123456789012345678901234567890123456789012345678901234567890123."
|
||||
"1234567890123456789012345678901234567890123456789012345678901",
|
||||
UIDNA_ERROR_LABEL_TOO_LONG|UIDNA_ERROR_DOMAIN_NAME_TOO_LONG },
|
||||
// hyphen errors and empty-label errors
|
||||
// "xn---q----jra"=="-q--a-umlaut-"
|
||||
{ "a.b..-q--a-.e", "B", "a.b..-q--a-.e",
|
||||
UIDNA_ERROR_EMPTY_LABEL|UIDNA_ERROR_LEADING_HYPHEN|UIDNA_ERROR_TRAILING_HYPHEN|
|
||||
UIDNA_ERROR_HYPHEN_3_4 },
|
||||
{ "a.b..-q--\\u00E4-.e", "B", "a.b..-q--\\u00E4-.e",
|
||||
UIDNA_ERROR_EMPTY_LABEL|UIDNA_ERROR_LEADING_HYPHEN|UIDNA_ERROR_TRAILING_HYPHEN|
|
||||
UIDNA_ERROR_HYPHEN_3_4 },
|
||||
{ "a.b..xn---q----jra.e", "B", "a.b..-q--\\u00E4-.e",
|
||||
UIDNA_ERROR_EMPTY_LABEL|UIDNA_ERROR_LEADING_HYPHEN|UIDNA_ERROR_TRAILING_HYPHEN|
|
||||
UIDNA_ERROR_HYPHEN_3_4 },
|
||||
{ "a..c", "B", "a..c", UIDNA_ERROR_EMPTY_LABEL },
|
||||
{ "a.-b.", "B", "a.-b.", UIDNA_ERROR_LEADING_HYPHEN },
|
||||
{ "a.b-.c", "B", "a.b-.c", UIDNA_ERROR_TRAILING_HYPHEN },
|
||||
{ "a.-.c", "B", "a.-.c", UIDNA_ERROR_LEADING_HYPHEN|UIDNA_ERROR_TRAILING_HYPHEN },
|
||||
{ "a.bc--de.f", "B", "a.bc--de.f", UIDNA_ERROR_HYPHEN_3_4 },
|
||||
{ "\\u00E4.\\u00AD.c", "B", "\\u00E4..c", UIDNA_ERROR_EMPTY_LABEL },
|
||||
{ "\\u00E4.-b.", "B", "\\u00E4.-b.", UIDNA_ERROR_LEADING_HYPHEN },
|
||||
{ "\\u00E4.b-.c", "B", "\\u00E4.b-.c", UIDNA_ERROR_TRAILING_HYPHEN },
|
||||
{ "\\u00E4.-.c", "B", "\\u00E4.-.c", UIDNA_ERROR_LEADING_HYPHEN|UIDNA_ERROR_TRAILING_HYPHEN },
|
||||
{ "\\u00E4.bc--de.f", "B", "\\u00E4.bc--de.f", UIDNA_ERROR_HYPHEN_3_4 },
|
||||
{ "a.b.\\u0308c.d", "B", "a.b.\\uFFFDc.d", UIDNA_ERROR_LEADING_COMBINING_MARK },
|
||||
{ "a.b.xn--c-bcb.d", "B",
|
||||
"a.b.xn--c-bcb\\uFFFD.d", UIDNA_ERROR_LEADING_COMBINING_MARK|UIDNA_ERROR_INVALID_ACE_LABEL },
|
||||
// BiDi
|
||||
{ "A0", "B", "a0", 0 },
|
||||
{ "0A", "B", "0a", 0 }, // all-LTR is ok to start with a digit (EN)
|
||||
{ "0A.\\u05D0", "B", // ASCII label does not start with L/R/AL
|
||||
"0a.\\u05D0", UIDNA_ERROR_BIDI },
|
||||
{ "c.xn--0-eha.xn--4db", "B", // 2nd label does not start with L/R/AL
|
||||
"c.0\\u00FC.\\u05D0", UIDNA_ERROR_BIDI },
|
||||
{ "b-.\\u05D0", "B", // label does not end with L/EN
|
||||
"b-.\\u05D0", UIDNA_ERROR_TRAILING_HYPHEN|UIDNA_ERROR_BIDI },
|
||||
{ "d.xn----dha.xn--4db", "B", // 2nd label does not end with L/EN
|
||||
"d.\\u00FC-.\\u05D0", UIDNA_ERROR_TRAILING_HYPHEN|UIDNA_ERROR_BIDI },
|
||||
{ "a\\u05D0", "B", "a\\u05D0", UIDNA_ERROR_BIDI }, // first dir != last dir
|
||||
{ "\\u05D0\\u05C7", "B", "\\u05D0\\u05C7", 0 },
|
||||
{ "\\u05D09\\u05C7", "B", "\\u05D09\\u05C7", 0 },
|
||||
{ "\\u05D0a\\u05C7", "B", "\\u05D0a\\u05C7", UIDNA_ERROR_BIDI }, // first dir != last dir
|
||||
{ "\\u05D0\\u05EA", "B", "\\u05D0\\u05EA", 0 },
|
||||
{ "\\u05D0\\u05F3\\u05EA", "B", "\\u05D0\\u05F3\\u05EA", 0 },
|
||||
{ "a\\u05D0Tz", "B", "a\\u05D0tz", UIDNA_ERROR_BIDI }, // mixed dir
|
||||
{ "\\u05D0T\\u05EA", "B", "\\u05D0t\\u05EA", UIDNA_ERROR_BIDI }, // mixed dir
|
||||
{ "\\u05D07\\u05EA", "B", "\\u05D07\\u05EA", 0 },
|
||||
{ "\\u05D0\\u0667\\u05EA", "B", "\\u05D0\\u0667\\u05EA", 0 }, // Arabic 7 in the middle
|
||||
{ "a7\\u0667z", "B", "a7\\u0667z", UIDNA_ERROR_BIDI }, // AN digit in LTR
|
||||
{ "\\u05D07\\u0667\\u05EA", "B", // mixed EN/AN digits in RTL
|
||||
"\\u05D07\\u0667\\u05EA", UIDNA_ERROR_BIDI },
|
||||
// ZWJ
|
||||
{ "\\u0BB9\\u0BCD\\u200D", "N", "\\u0BB9\\u0BCD\\u200D", 0 }, // Virama+ZWJ
|
||||
{ "\\u0BB9\\u200D", "N", "\\u0BB9\\u200D", UIDNA_ERROR_CONTEXTJ }, // no Virama
|
||||
{ "\\u200D", "N", "\\u200D", UIDNA_ERROR_CONTEXTJ }, // no Virama
|
||||
// ZWNJ
|
||||
{ "\\u0BB9\\u0BCD\\u200C", "N", "\\u0BB9\\u0BCD\\u200C", 0 }, // Virama+ZWNJ
|
||||
{ "\\u0BB9\\u200C", "N", "\\u0BB9\\u200C", UIDNA_ERROR_CONTEXTJ }, // no Virama
|
||||
{ "\\u200C", "N", "\\u200C", UIDNA_ERROR_CONTEXTJ }, // no Virama
|
||||
{ "\\u0644\\u0670\\u200C\\u06ED\\u06EF", "N", // Joining types D T ZWNJ T R
|
||||
"\\u0644\\u0670\\u200C\\u06ED\\u06EF", 0 },
|
||||
{ "\\u0644\\u0670\\u200C\\u06EF", "N", // D T ZWNJ R
|
||||
"\\u0644\\u0670\\u200C\\u06EF", 0 },
|
||||
{ "\\u0644\\u200C\\u06ED\\u06EF", "N", // D ZWNJ T R
|
||||
"\\u0644\\u200C\\u06ED\\u06EF", 0 },
|
||||
{ "\\u0644\\u200C\\u06EF", "N", // D ZWNJ R
|
||||
"\\u0644\\u200C\\u06EF", 0 },
|
||||
{ "\\u0644\\u0670\\u200C\\u06ED", "N", // D T ZWNJ T
|
||||
"\\u0644\\u0670\\u200C\\u06ED", UIDNA_ERROR_BIDI|UIDNA_ERROR_CONTEXTJ },
|
||||
{ "\\u06EF\\u200C\\u06EF", "N", // R ZWNJ R
|
||||
"\\u06EF\\u200C\\u06EF", UIDNA_ERROR_CONTEXTJ },
|
||||
{ "\\u0644\\u200C", "N", // D ZWNJ
|
||||
"\\u0644\\u200C", UIDNA_ERROR_BIDI|UIDNA_ERROR_CONTEXTJ },
|
||||
// { "", "B",
|
||||
// "", 0 },
|
||||
};
|
||||
|
||||
void UTS46Test::TestSomeCases() {
|
||||
IcuTestErrorCode errorCode(*this, "TestSomeCases");
|
||||
char buffer[400], buffer2[400];
|
||||
int32_t i;
|
||||
for(i=0; i<LENGTHOF(testCases); ++i) {
|
||||
const TestCase &testCase=testCases[i];
|
||||
UnicodeString input(ctou(testCase.s));
|
||||
UnicodeString expected(ctou(testCase.u));
|
||||
// ToASCII/ToUnicode, transitional/nontransitional
|
||||
UnicodeString aT, uT, aN, uN;
|
||||
IDNAInfo aTInfo, uTInfo, aNInfo, uNInfo;
|
||||
trans->nameToASCII(input, aT, aTInfo, errorCode);
|
||||
trans->nameToUnicode(input, uT, uTInfo, errorCode);
|
||||
nontrans->nameToASCII(input, aN, aNInfo, errorCode);
|
||||
nontrans->nameToUnicode(input, uN, uNInfo, errorCode);
|
||||
if(errorCode.logIfFailureAndReset("first-level processing [%d/%s] %s",
|
||||
(int)i, testCase.o, testCase.s)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
// ToUnicode does not set length errors.
|
||||
uint32_t uniErrors=testCase.errors&~
|
||||
(UIDNA_ERROR_EMPTY_LABEL|
|
||||
UIDNA_ERROR_LABEL_TOO_LONG|
|
||||
UIDNA_ERROR_DOMAIN_NAME_TOO_LONG);
|
||||
char mode=testCase.o[0];
|
||||
if(mode=='B' || mode=='N') {
|
||||
if(uNInfo.getErrors()!=uniErrors) {
|
||||
errln("N.nameToUnicode([%d] %s) unexpected errors %04lx",
|
||||
(int)i, testCase.s, (long)uNInfo.getErrors());
|
||||
continue;
|
||||
}
|
||||
if(uN!=expected) {
|
||||
prettify(uN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
errln("N.nameToUnicode([%d] %s) unexpected string %s",
|
||||
(int)i, testCase.s, buffer);
|
||||
continue;
|
||||
}
|
||||
if(aNInfo.getErrors()!=testCase.errors) {
|
||||
errln("N.nameToASCII([%d] %s) unexpected errors %04lx",
|
||||
(int)i, testCase.s, (long)aNInfo.getErrors());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(mode=='B' || mode=='T') {
|
||||
if(uTInfo.getErrors()!=uniErrors) {
|
||||
errln("T.nameToUnicode([%d] %s) unexpected errors %04lx",
|
||||
(int)i, testCase.s, (long)uTInfo.getErrors());
|
||||
continue;
|
||||
}
|
||||
if(uT!=expected) {
|
||||
prettify(uT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
errln("T.nameToUnicode([%d] %s) unexpected string %s",
|
||||
(int)i, testCase.s, buffer);
|
||||
continue;
|
||||
}
|
||||
if(aTInfo.getErrors()!=testCase.errors) {
|
||||
errln("T.nameToASCII([%d] %s) unexpected errors %04lx",
|
||||
(int)i, testCase.s, (long)aTInfo.getErrors());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// ToASCII is all-ASCII if no severe errors
|
||||
if((aNInfo.getErrors()&severeErrors)==0 && !isASCII(aN)) {
|
||||
prettify(aN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
errln("N.nameToASCII([%d] %s) (errors %04lx) result is not ASCII %s",
|
||||
(int)i, testCase.s, aNInfo.getErrors(), buffer);
|
||||
continue;
|
||||
}
|
||||
if((aTInfo.getErrors()&severeErrors)==0 && !isASCII(aT)) {
|
||||
prettify(aT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
errln("T.nameToASCII([%d] %s) (errors %04lx) result is not ASCII %s",
|
||||
(int)i, testCase.s, aTInfo.getErrors(), buffer);
|
||||
continue;
|
||||
}
|
||||
if(verbose) {
|
||||
char m= mode=='B' ? mode : 'N';
|
||||
prettify(aN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
logln("%c.nameToASCII([%d] %s) (errors %04lx) result string: %s",
|
||||
m, (int)i, testCase.s, aNInfo.getErrors(), buffer);
|
||||
if(mode!='B') {
|
||||
prettify(aT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
logln("T.nameToASCII([%d] %s) (errors %04lx) result string: %s",
|
||||
(int)i, testCase.s, aTInfo.getErrors(), buffer);
|
||||
}
|
||||
}
|
||||
// second-level processing
|
||||
UnicodeString aTuN, uTaN, aNuN, uNaN;
|
||||
IDNAInfo aTuNInfo, uTaNInfo, aNuNInfo, uNaNInfo;
|
||||
nontrans->nameToUnicode(aT, aTuN, aTuNInfo, errorCode);
|
||||
nontrans->nameToASCII(uT, uTaN, uTaNInfo, errorCode);
|
||||
nontrans->nameToUnicode(aN, aNuN, aNuNInfo, errorCode);
|
||||
nontrans->nameToASCII(uN, uNaN, uNaNInfo, errorCode);
|
||||
if(errorCode.logIfFailureAndReset("second-level processing [%d/%s] %s",
|
||||
(int)i, testCase.o, testCase.s)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if(aN!=uNaN) {
|
||||
prettify(aN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
prettify(uNaN).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
|
||||
errln("N.nameToASCII([%d] %s)!=N.nameToUnicode().N.nameToASCII() "
|
||||
"(errors %04lx) %s vs. %s",
|
||||
(int)i, testCase.s, aNInfo.getErrors(), buffer, buffer2);
|
||||
continue;
|
||||
}
|
||||
if(aT!=uTaN) {
|
||||
prettify(aT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
prettify(uTaN).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
|
||||
errln("T.nameToASCII([%d] %s)!=T.nameToUnicode().N.nameToASCII() "
|
||||
"(errors %04lx) %s vs. %s",
|
||||
(int)i, testCase.s, aNInfo.getErrors(), buffer, buffer2);
|
||||
continue;
|
||||
}
|
||||
if(uN!=aNuN) {
|
||||
prettify(uN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
prettify(aNuN).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
|
||||
errln("N.nameToUnicode([%d] %s)!=N.nameToASCII().N.nameToUnicode() "
|
||||
"(errors %04lx) %s vs. %s",
|
||||
(int)i, testCase.s, uNInfo.getErrors(), buffer, buffer2);
|
||||
continue;
|
||||
}
|
||||
if(uT!=aTuN) {
|
||||
prettify(uT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
prettify(aTuN).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
|
||||
errln("T.nameToUnicode([%d] %s)!=T.nameToASCII().N.nameToUnicode() "
|
||||
"(errors %04lx) %s vs. %s",
|
||||
(int)i, testCase.s, uNInfo.getErrors(), buffer, buffer2);
|
||||
continue;
|
||||
}
|
||||
// labelToUnicode
|
||||
UnicodeString aTL, uTL, aNL, uNL;
|
||||
IDNAInfo aTLInfo, uTLInfo, aNLInfo, uNLInfo;
|
||||
trans->labelToASCII(input, aTL, aTLInfo, errorCode);
|
||||
trans->labelToUnicode(input, uTL, uTLInfo, errorCode);
|
||||
nontrans->labelToASCII(input, aNL, aNLInfo, errorCode);
|
||||
nontrans->labelToUnicode(input, uNL, uNLInfo, errorCode);
|
||||
if(errorCode.logIfFailureAndReset("labelToXYZ processing [%d/%s] %s",
|
||||
(int)i, testCase.o, testCase.s)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if(aN.indexOf((UChar)0x2e)<0) {
|
||||
if(aN!=aNL || aNInfo.getErrors()!=aNLInfo.getErrors()) {
|
||||
prettify(aN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
prettify(aNL).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
|
||||
errln("N.nameToASCII([%d] %s)!=N.labelToASCII() "
|
||||
"(errors %04lx vs %04lx) %s vs. %s",
|
||||
(int)i, testCase.s, aNInfo.getErrors(), aNLInfo.getErrors(), buffer, buffer2);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if((aNLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) {
|
||||
errln("N.labelToASCII([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
|
||||
(int)i, testCase.s, (long)aNLInfo.getErrors());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(aT.indexOf((UChar)0x2e)<0) {
|
||||
if(aT!=aTL || aTInfo.getErrors()!=aTLInfo.getErrors()) {
|
||||
prettify(aT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
prettify(aTL).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
|
||||
errln("T.nameToASCII([%d] %s)!=T.labelToASCII() "
|
||||
"(errors %04lx vs %04lx) %s vs. %s",
|
||||
(int)i, testCase.s, aTInfo.getErrors(), aTLInfo.getErrors(), buffer, buffer2);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if((aTLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) {
|
||||
errln("T.labelToASCII([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
|
||||
(int)i, testCase.s, (long)aTLInfo.getErrors());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(uN.indexOf((UChar)0x2e)<0) {
|
||||
if(uN!=uNL || uNInfo.getErrors()!=uNLInfo.getErrors()) {
|
||||
prettify(uN).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
prettify(uNL).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
|
||||
errln("N.nameToUnicode([%d] %s)!=N.labelToUnicode() "
|
||||
"(errors %04lx vs %04lx) %s vs. %s",
|
||||
(int)i, testCase.s, uNInfo.getErrors(), uNLInfo.getErrors(), buffer, buffer2);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if((uNLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) {
|
||||
errln("N.labelToUnicode([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
|
||||
(int)i, testCase.s, (long)uNLInfo.getErrors());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(uT.indexOf((UChar)0x2e)<0) {
|
||||
if(uT!=uTL || uTInfo.getErrors()!=uTLInfo.getErrors()) {
|
||||
prettify(uT).extract(0, 0x7fffffff, buffer, LENGTHOF(buffer));
|
||||
prettify(uTL).extract(0, 0x7fffffff, buffer2, LENGTHOF(buffer2));
|
||||
errln("T.nameToUnicode([%d] %s)!=T.labelToUnicode() "
|
||||
"(errors %04lx vs %04lx) %s vs. %s",
|
||||
(int)i, testCase.s, uTInfo.getErrors(), uTLInfo.getErrors(), buffer, buffer2);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if((uTLInfo.getErrors()&UIDNA_ERROR_LABEL_HAS_DOT)==0) {
|
||||
errln("T.labelToUnicode([%d] %s) errors %04lx missing UIDNA_ERROR_LABEL_HAS_DOT",
|
||||
(int)i, testCase.s, (long)uTLInfo.getErrors());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Differences between transitional and nontransitional processing
|
||||
if(mode=='B') {
|
||||
if( aNInfo.isTransitionalDifferent() ||
|
||||
aTInfo.isTransitionalDifferent() ||
|
||||
uNInfo.isTransitionalDifferent() ||
|
||||
uTInfo.isTransitionalDifferent() ||
|
||||
aNLInfo.isTransitionalDifferent() ||
|
||||
aTLInfo.isTransitionalDifferent() ||
|
||||
uNLInfo.isTransitionalDifferent() ||
|
||||
uTLInfo.isTransitionalDifferent()
|
||||
) {
|
||||
errln("B.process([%d] %s) isTransitionalDifferent()", (int)i, testCase.s);
|
||||
continue;
|
||||
}
|
||||
if( aN!=aT || uN!=uT || aNL!=aTL || uNL!=uTL ||
|
||||
aNInfo.getErrors()!=aTInfo.getErrors() || uNInfo.getErrors()!=uTInfo.getErrors() ||
|
||||
aNLInfo.getErrors()!=aTLInfo.getErrors() || uNLInfo.getErrors()!=uTLInfo.getErrors()
|
||||
) {
|
||||
errln("N.process([%d] %s) vs. T.process() different errors or result strings",
|
||||
(int)i, testCase.s);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if( !aNInfo.isTransitionalDifferent() ||
|
||||
!aTInfo.isTransitionalDifferent() ||
|
||||
!uNInfo.isTransitionalDifferent() ||
|
||||
!uTInfo.isTransitionalDifferent() ||
|
||||
!aNLInfo.isTransitionalDifferent() ||
|
||||
!aTLInfo.isTransitionalDifferent() ||
|
||||
!uNLInfo.isTransitionalDifferent() ||
|
||||
!uTLInfo.isTransitionalDifferent()
|
||||
) {
|
||||
errln("%s.process([%d] %s) !isTransitionalDifferent()",
|
||||
testCase.o, (int)i, testCase.s);
|
||||
continue;
|
||||
}
|
||||
if(aN==aT || uN==uT || aNL==aTL || uNL==uTL) {
|
||||
errln("N.process([%d] %s) vs. T.process() same result strings",
|
||||
(int)i, testCase.s);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// UTF-8 if we have std::string
|
||||
#if U_HAVE_STD_STRING
|
||||
U_STD_NSQ string input8, aT8, uT8, aN8, uN8;
|
||||
StringByteSink<U_STD_NSQ string> aT8Sink(&aT8), uT8Sink(&uT8), aN8Sink(&aN8), uN8Sink(&uN8);
|
||||
IDNAInfo aT8Info, uT8Info, aN8Info, uN8Info;
|
||||
input.toUTF8String(input8);
|
||||
trans->nameToASCII_UTF8(input8, aT8Sink, aT8Info, errorCode);
|
||||
trans->nameToUnicodeUTF8(input8, uT8Sink, uT8Info, errorCode);
|
||||
nontrans->nameToASCII_UTF8(input8, aN8Sink, aN8Info, errorCode);
|
||||
nontrans->nameToUnicodeUTF8(input8, uN8Sink, uN8Info, errorCode);
|
||||
if(errorCode.logIfFailureAndReset("UTF-8 processing [%d/%s] %s",
|
||||
(int)i, testCase.o, testCase.s)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
UnicodeString aT16(UnicodeString::fromUTF8(aT8));
|
||||
UnicodeString uT16(UnicodeString::fromUTF8(uT8));
|
||||
UnicodeString aN16(UnicodeString::fromUTF8(aN8));
|
||||
UnicodeString uN16(UnicodeString::fromUTF8(uN8));
|
||||
if( aN8Info.getErrors()!=aNInfo.getErrors() ||
|
||||
uN8Info.getErrors()!=uNInfo.getErrors()
|
||||
) {
|
||||
errln("N.xyzUTF8([%d] %s) vs. UTF-16 processing different errors %04lx vs. %04lx",
|
||||
(int)i, testCase.s,
|
||||
(long)aN8Info.getErrors(), (long)aNInfo.getErrors());
|
||||
continue;
|
||||
}
|
||||
if( aT8Info.getErrors()!=aTInfo.getErrors() ||
|
||||
uT8Info.getErrors()!=uTInfo.getErrors()
|
||||
) {
|
||||
errln("T.xyzUTF8([%d] %s) vs. UTF-16 processing different errors %04lx vs. %04lx",
|
||||
(int)i, testCase.s,
|
||||
(long)aT8Info.getErrors(), (long)aTInfo.getErrors());
|
||||
continue;
|
||||
}
|
||||
if(aT16!=aT || uT16!=uT || aN16!=aN || uN16!=uN) {
|
||||
errln("%s.xyzUTF8([%d] %s) vs. UTF-16 processing different string results",
|
||||
testCase.o, (int)i, testCase.s, (long)aTInfo.getErrors());
|
||||
continue;
|
||||
}
|
||||
if( aT8Info.isTransitionalDifferent()!=aTInfo.isTransitionalDifferent() ||
|
||||
uT8Info.isTransitionalDifferent()!=uTInfo.isTransitionalDifferent() ||
|
||||
aN8Info.isTransitionalDifferent()!=aNInfo.isTransitionalDifferent() ||
|
||||
uN8Info.isTransitionalDifferent()!=uNInfo.isTransitionalDifferent()
|
||||
) {
|
||||
errln("%s.xyzUTF8([%d] %s) vs. UTF-16 processing different isTransitionalDifferent()",
|
||||
testCase.o, (int)i, testCase.s);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif // UCONFIG_NO_IDNA
|
Loading…
Reference in New Issue
Block a user