mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-20 20:19:32 +00:00
ICU-8006 Add new API for CharsetDecoderICU and CharsetEncoderICU
X-SVN-Rev: 29474
This commit is contained in:
parent
f0fe89f14c
commit
d0670255e8
4 changed files with 84 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2006-2010, International Business Machines Corporation and *
|
||||
* Copyright (C) 2006-2011, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
|
@ -722,4 +722,23 @@ public abstract class CharsetDecoderICU extends CharsetDecoder{
|
|||
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Returns the maxBytesPerChar value for the Charset that created this decoder.
|
||||
* @return maxBytesPerChar
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
public final float maxBytesPerChar() {
|
||||
return ((CharsetICU)(this.charset())).maxBytesPerChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the converter has a fixed ratio of bytes per
|
||||
* 16-bit char/UChar (e.g. converters that are SBCS or DBCS).
|
||||
* @return true if the converter is fixed-width
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
public final boolean isFixedWidth() {
|
||||
return ((CharsetICU)this.charset()).isFixedWidth();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2006-2009, International Business Machines Corporation and *
|
||||
* Copyright (C) 2006-2011, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
|
@ -917,4 +917,23 @@ public abstract class CharsetEncoderICU extends CharsetEncoder {
|
|||
fromUChar32 = UCharacter.getCodePoint(lead, trail);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maxCharsPerByte value for the Charset that created this encoder.
|
||||
* @return maxCharsPerByte
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
public final float maxCharsPerByte() {
|
||||
return ((CharsetICU)(this.charset())).maxCharsPerByte;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the converter has a fixed ratio of bytes per
|
||||
* 16-bit char/UChar (e.g. converters that are SBCS or DBCS).
|
||||
* @return true if the converter is fixed-width
|
||||
* @draft ICU 4.8
|
||||
*/
|
||||
public final boolean isFixedWidth() {
|
||||
return ((CharsetICU)this.charset()).isFixedWidth();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2006-2010, International Business Machines Corporation and *
|
||||
* Copyright (C) 2006-2011, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
|
@ -378,5 +378,9 @@ public abstract class CharsetICU extends Charset{
|
|||
static void getCompleteUnicodeSet(UnicodeSet setFillIn){
|
||||
setFillIn.add(0, 0x10ffff);
|
||||
}
|
||||
|
||||
boolean isFixedWidth() {
|
||||
return (maxBytesPerChar == minBytesPerChar);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2006-2010, International Business Machines Corporation and *
|
||||
* Copyright (C) 2006-2011, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
|
@ -5592,4 +5592,42 @@ public class TestCharset extends TestFmwk {
|
|||
}
|
||||
}
|
||||
}
|
||||
public void TestIsFixedWidth(){
|
||||
String[] fixedWidth = {
|
||||
"US-ASCII",
|
||||
"UTF32",
|
||||
"ibm-5478_P100-1995",
|
||||
"UTF16"
|
||||
};
|
||||
|
||||
String[] notFixedWidth = {
|
||||
"GB18030",
|
||||
"UTF8",
|
||||
"windows-949-2000"
|
||||
};
|
||||
CharsetProvider provider = new CharsetProviderICU();
|
||||
Charset charset;
|
||||
CharsetEncoder encoder;
|
||||
CharsetDecoder decoder;
|
||||
|
||||
for (int i = 0; i < fixedWidth.length; i++) {
|
||||
charset = provider.charsetForName(fixedWidth[i]);
|
||||
encoder = charset.newEncoder();
|
||||
decoder = charset.newDecoder();
|
||||
|
||||
if (!((CharsetEncoderICU)encoder).isFixedWidth() || !((CharsetDecoderICU)decoder).isFixedWidth()) {
|
||||
errln(fixedWidth[i] + " is a fixedWidth charset but returned false.");
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < notFixedWidth.length; i++) {
|
||||
charset = provider.charsetForName(notFixedWidth[i]);
|
||||
encoder = charset.newEncoder();
|
||||
decoder = charset.newDecoder();
|
||||
|
||||
if (((CharsetEncoderICU)encoder).isFixedWidth() || ((CharsetDecoderICU)decoder).isFixedWidth()) {
|
||||
errln(notFixedWidth[i] + " is NOT a fixedWidth charset but returned true.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue