mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-2155 FC_NFKC Api
X-SVN-Rev: 9890
This commit is contained in:
parent
58096f537a
commit
45040ba165
3 changed files with 102 additions and 13 deletions
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/normalizer/BasicTest.java,v $
|
||||
* $Date: 2002/08/12 16:14:35 $
|
||||
* $Revision: 1.15 $
|
||||
* $Date: 2002/09/19 18:12:31 $
|
||||
* $Revision: 1.16 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
@ -2052,12 +2052,12 @@ public class BasicTest extends TestFmwk {
|
|||
count=countFoldFCDExceptions(0);
|
||||
count+=countFoldFCDExceptions(Normalizer.FOLD_CASE_EXCLUDE_SPECIAL_I);
|
||||
if(count>0) {
|
||||
/*
|
||||
* If case-folding un-FCDs any strings, then unorm_compare() must be
|
||||
* re-implemented.
|
||||
* It currently assumes that one can check for FCD then case-fold
|
||||
* and then still have FCD strings for raw decomposition without reordering.
|
||||
*/
|
||||
//*
|
||||
//* If case-folding un-FCDs any strings, then unorm_compare() must be
|
||||
//* re-implemented.
|
||||
//* It currently assumes that one can check for FCD then case-fold
|
||||
//* and then still have FCD strings for raw decomposition without reordering.
|
||||
//*
|
||||
errln("error: There are "+count+" code points for which case-folding"+
|
||||
" may un-FCD a string for all folding options.\n See comment"+
|
||||
" in BasicNormalizerTest::FindFoldFCDExceptions()!");
|
||||
|
@ -2096,5 +2096,44 @@ public class BasicTest extends TestFmwk {
|
|||
}
|
||||
}
|
||||
*/
|
||||
public void TestFCNFKCClosure() {
|
||||
final class TestStruct{
|
||||
int c;
|
||||
String s;
|
||||
TestStruct(int cp, String src){
|
||||
c=cp;
|
||||
s=src;
|
||||
}
|
||||
};
|
||||
|
||||
TestStruct[] tests= new TestStruct[]{
|
||||
new TestStruct( 0x037A, new String( "\u0020\u03B9") ),
|
||||
new TestStruct( 0x03D2, new String( "\u03C5") ),
|
||||
new TestStruct( 0x20A8, new String( "\u0072\u0073") ) ,
|
||||
new TestStruct( 0x210B, new String( "\u0068") ),
|
||||
new TestStruct( 0x210C, new String( "\u0068") ),
|
||||
new TestStruct( 0x2121, new String( "\u0074\u0065\u006C") ),
|
||||
new TestStruct( 0x2122, new String( "\u0074\u006D") ),
|
||||
new TestStruct( 0x2128, new String( "\u007A") ),
|
||||
new TestStruct( 0x1D5DB, new String( "\u0068") ),
|
||||
new TestStruct( 0x1D5ED, new String( "\u007A") ),
|
||||
new TestStruct( 0x0061, new String() )
|
||||
};
|
||||
|
||||
|
||||
int i, length;
|
||||
|
||||
for(i=0; i<tests.length; ++i) {
|
||||
String result=Normalizer.getFC_NFKC_Closure(tests[i].c);
|
||||
if(!result.equals(new String(tests[i].s))) {
|
||||
errln("getFC_NFKC_Closure(U+"+Integer.toHexString(tests[i].c)+") is wrong");
|
||||
}
|
||||
}
|
||||
|
||||
/* error handling */
|
||||
|
||||
length=Normalizer.getFC_NFKC_Closure(0x5c, null);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/NormalizerImpl.java,v $
|
||||
* $Date: 2002/08/07 18:07:56 $
|
||||
* $Revision: 1.10 $
|
||||
* $Date: 2002/09/19 18:12:30 $
|
||||
* $Revision: 1.11 $
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
|
@ -2558,7 +2558,42 @@ public final class NormalizerImpl {
|
|||
|
||||
return false; /* not found */
|
||||
}
|
||||
|
||||
|
||||
public static int getFC_NFKC_Closure(int c, char[] dest) {
|
||||
|
||||
int destCapacity;
|
||||
|
||||
if(dest==null ) {
|
||||
destCapacity=0;
|
||||
}else{
|
||||
destCapacity = dest.length;
|
||||
}
|
||||
|
||||
int aux =auxTrieImpl.auxTrie.getCodePointValue(c);
|
||||
|
||||
aux&= AUX_FNC_MASK;
|
||||
if(aux!=0) {
|
||||
int s;
|
||||
int index=aux;
|
||||
int length;
|
||||
|
||||
s =extraData[index];
|
||||
if(s<0xff00) {
|
||||
/* s points to the single-unit string */
|
||||
length=1;
|
||||
} else {
|
||||
length=s&0xff;
|
||||
++index;
|
||||
}
|
||||
if(0<length && length<=destCapacity) {
|
||||
System.arraycopy(extraData,index,dest,0,length);
|
||||
}
|
||||
return length;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal API, used by collation code.
|
||||
* Get access to the internal FCD trie table to be able to perform
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Normalizer.java,v $
|
||||
* $Date: 2002/08/07 18:06:50 $
|
||||
* $Revision: 1.22 $
|
||||
* $Date: 2002/09/19 18:12:31 $
|
||||
* $Revision: 1.23 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -1462,6 +1462,21 @@ public final class Normalizer implements Cloneable{
|
|||
}
|
||||
}
|
||||
|
||||
public static int getFC_NFKC_Closure(int c,char[] dest){
|
||||
return NormalizerImpl.getFC_NFKC_Closure(c,dest);
|
||||
}
|
||||
|
||||
public static String getFC_NFKC_Closure(int c){
|
||||
char[] dest = new char[10];
|
||||
for(;;){
|
||||
int length = getFC_NFKC_Closure(c,dest);
|
||||
if(length<=dest.length){
|
||||
return new String(dest,0,length);
|
||||
}else{
|
||||
dest = new char[length];
|
||||
}
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
// Iteration API
|
||||
//-------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue