0N/A/*
2362N/A * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.io;
0N/A
0N/Aimport sun.nio.cs.ext.ISCII91;
0N/A
0N/A/*
0N/A * Copyright (c) 1998 International Business Machines.
0N/A * All Rights Reserved.
0N/A *
0N/A * Author : Sunanda Bera, C. Thirumalesh
0N/A * Last Modified : 23,November,1998
0N/A *
0N/A * Purpose : Defines class ByteToCharISCII91.
0N/A *
0N/A *
0N/A * Revision History
0N/A * ======== =======
0N/A *
0N/A * Date By Description
0N/A * ---- -- -----------
0N/A *
0N/A *
0N/A */
0N/A
0N/A/**
0N/A * Converter class. Converts between Unicode encoding and ISCII91 encoding.
0N/A * ISCII91 is the character encoding as defined in Indian Standard document
0N/A * IS 13194:1991 ( Indian Script Code for Information Interchange ).
0N/A *
0N/A * @see sun.io.ByteToCharConverter
0N/A */
0N/Apublic class ByteToCharISCII91 extends ByteToCharConverter {
0N/A
0N/A private static final char[] directMapTable = ISCII91.getDirectMapTable();
0N/A
0N/A private static final char NUKTA_CHAR = '\u093c';
0N/A private static final char HALANT_CHAR = '\u094d';
0N/A private static final char ZWNJ_CHAR = '\u200c';
0N/A private static final char ZWJ_CHAR = '\u200d';
0N/A private static final char INVALID_CHAR = '\uffff';
0N/A
0N/A private char contextChar = INVALID_CHAR;
0N/A private boolean needFlushing = false;
0N/A
0N/A/**
0N/A * Converts ISCII91 characters to Unicode.
0N/A * @see sun.io.ByteToCharConverter#convert
0N/A */
0N/A public int convert(byte input[], int inStart, int inEnd,
0N/A char output[], int outStart, int outEnd)
0N/A throws ConversionBufferFullException, UnknownCharacterException {
0N/A /*Rules:
0N/A * 1)ATR,EXT,following character to be replaced with '\ufffd'
0N/A * 2)Halant + Halant => '\u094d' (Virama) + '\u200c'(ZWNJ)
0N/A * 3)Halant + Nukta => '\u094d' (Virama) + '\u200d'(ZWJ)
0N/A */
0N/A charOff = outStart;
0N/A byteOff = inStart;
0N/A while (byteOff < inEnd) {
0N/A if (charOff >= outEnd) {
0N/A throw new ConversionBufferFullException();
0N/A }
0N/A int index = input[byteOff++];
0N/A index = ( index < 0 )? ( index + 255 ):index;
0N/A char currentChar = directMapTable[index];
0N/A
0N/A // if the contextChar is either ATR || EXT set the output to '\ufffd'
0N/A if(contextChar == '\ufffd') {
0N/A output[charOff++] = '\ufffd';
0N/A contextChar = INVALID_CHAR;
0N/A needFlushing = false;
0N/A continue;
0N/A }
0N/A
0N/A switch(currentChar) {
0N/A case '\u0901':
0N/A case '\u0907':
0N/A case '\u0908':
0N/A case '\u090b':
0N/A case '\u093f':
0N/A case '\u0940':
0N/A case '\u0943':
0N/A case '\u0964':
0N/A if(needFlushing) {
0N/A output[charOff++] = contextChar;
0N/A contextChar = currentChar;
0N/A continue;
0N/A }
0N/A contextChar = currentChar;
0N/A needFlushing = true;
0N/A continue;
0N/A case NUKTA_CHAR:
0N/A switch(contextChar) {
0N/A case '\u0901':
0N/A output[charOff] = '\u0950';
0N/A break;
0N/A case '\u0907':
0N/A output[charOff] = '\u090c';
0N/A break;
0N/A case '\u0908':
0N/A output[charOff] = '\u0961';
0N/A break;
0N/A case '\u090b':
0N/A output[charOff] = '\u0960';
0N/A break;
0N/A case '\u093f':
0N/A output[charOff] = '\u0962';
0N/A break;
0N/A case '\u0940':
0N/A output[charOff] = '\u0963';
0N/A break;
0N/A case '\u0943':
0N/A output[charOff] = '\u0944';
0N/A break;
0N/A case '\u0964':
0N/A output[charOff] = '\u093d';
0N/A break;
0N/A case HALANT_CHAR:
0N/A if(needFlushing) {
0N/A output[charOff++] = contextChar;
0N/A contextChar = currentChar;
0N/A continue;
0N/A }
0N/A output[charOff] = ZWJ_CHAR;
0N/A break;
0N/A default:
0N/A if(needFlushing) {
0N/A output[charOff++] = contextChar;
0N/A contextChar = currentChar;
0N/A continue;
0N/A }
0N/A output[charOff] = NUKTA_CHAR;
0N/A }
0N/A break;
0N/A case HALANT_CHAR:
0N/A if(needFlushing) {
0N/A output[charOff++] = contextChar;
0N/A contextChar = currentChar;
0N/A continue;
0N/A }
0N/A if(contextChar == HALANT_CHAR) {
0N/A output[charOff] = ZWNJ_CHAR;
0N/A break;
0N/A }
0N/A output[charOff] = HALANT_CHAR;
0N/A break;
0N/A case INVALID_CHAR:
0N/A if(needFlushing) {
0N/A output[charOff++] = contextChar;
0N/A contextChar = currentChar;
0N/A continue;
0N/A }
0N/A if(subMode) {
0N/A output[charOff] = subChars[0];
0N/A break;
0N/A } else {
0N/A contextChar = INVALID_CHAR;
0N/A throw new UnknownCharacterException();
0N/A }
0N/A default:
0N/A if(needFlushing) {
0N/A output[charOff++] = contextChar;
0N/A contextChar = currentChar;
0N/A continue;
0N/A }
0N/A output[charOff] = currentChar;
0N/A break;
0N/A }//end switch
0N/A
0N/A contextChar = currentChar;
0N/A needFlushing = false;
0N/A charOff++;
0N/A }//end while
0N/A return charOff - outStart;
0N/A } //convert()
0N/A
0N/A/**
0N/A * @see sun.io.ByteToCharConverter#flush
0N/A */
0N/A public int flush( char[] output, int outStart, int outEnd )
0N/A throws MalformedInputException, ConversionBufferFullException
0N/A {
0N/A int charsWritten = 0;
0N/A //if the last char was not flushed, flush it!
0N/A if(needFlushing) {
0N/A output[outStart] = contextChar;
0N/A charsWritten = 1;
0N/A }
0N/A contextChar = INVALID_CHAR;
0N/A needFlushing = false;
0N/A byteOff = charOff = 0;
0N/A return charsWritten;
0N/A }//flush()
0N/A/**
0N/A * Returns the character set id for the conversion.
0N/A */
0N/A public String getCharacterEncoding()
0N/A {
0N/A return "ISCII91";
0N/A }//getCharacterEncoding()
0N/A/**
0N/A * @see sun.io.ByteToCharConverter#reset
0N/A */
0N/A public void reset()
0N/A {
0N/A byteOff = charOff = 0;
0N/A }//reset()
0N/A
0N/A}//end of class definition