Commit 18fb9d46 authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Add support for ISO-8859-15.

parent 7094f28f
......@@ -32,6 +32,8 @@ More detailed changes:
* Programs and Libraries
* `cldc-compact`
* Added `java.util.Vector`, it was missing.
* Added support for ISO-8859-15, this is the newer encoding with the
Euro symbol.
* Implemented `java.io.InputStream`.
* Implemented `java.util.EventObject`.
* Implemented `java.util.LinkedList`.
......
......@@ -65,6 +65,10 @@ public final class CodecFactory
case "iso-8859-1":
return new ISO88591Decoder();
// ISO-8859-15
case "iso-8859-15":
return new ISO885915Decoder();
// UTF-8
case "utf-8":
return new UTF8Decoder();
......@@ -180,6 +184,10 @@ public final class CodecFactory
case "iso-8859-1":
return new ISO88591Encoder();
// ISO-8859-15
case "iso-8859-15":
return new ISO885915Encoder();
// UTF-8
case "utf-8":
return new UTF8Encoder();
......
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package cc.squirreljme.runtime.cldc.io;
/**
* Decoder for ISO-8859-15.
*
* @since 2019/04/29
*/
public class ISO885915Decoder
implements Decoder
{
/**
* {@inheritDoc}
* @since 2019/04/29
*/
@Override
public final double averageSequenceLength()
{
return 1.0;
}
/**
* {@inheritDoc}
* @since 2019/04/29
*/
@Override
public final int decode(byte[] __b, int __o, int __l)
throws IndexOutOfBoundsException, NullPointerException
{
if (__b == null)
throw new NullPointerException("NARG");
if (__o < 0 || __l < 0 || (__o + __l) > __b.length)
throw new IndexOutOfBoundsException("IOOB");
// Not enough to decode a character
if (__l <= 0)
return -1;
// Remap some characters?
int c = (__b[__o] & 0xFF);
switch (c)
{
case 0x00A4: c = 0x20AC; break;
case 0x00A6: c = 0x0160; break;
case 0x00A8: c = 0x0161; break;
case 0x00B4: c = 0x017D; break;
case 0x00B8: c = 0x017E; break;
case 0x00BC: c = 0x0152; break;
case 0x00BD: c = 0x0153; break;
case 0x00BE: c = 0x0178; break;
}
return 0x1_0000 | c;
}
/**
* {@inheritDc}
* @since 2019/04/29
*/
@Override
public final String encodingName()
{
return "iso-8859-15";
}
/**
* {@inheritDc}
* @since 2019/04/29
*/
@Override
public final int maximumSequenceLength()
{
return 1;
}
}
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package cc.squirreljme.runtime.cldc.io;
/**
* Encodes character data to ISO-8859-15.
*
* @since 2019/04/29
*/
public final class ISO885915Encoder
implements Encoder
{
/**
* {@inheritDoc}
* @since 2019/04/29
*/
@Override
public final double averageSequenceLength()
{
return 1.0;
}
/**
* {@inheritDoc}
* @since 2019/04/29
*/
@Override
public int encode(char __c, byte[] __b, int __o, int __l)
throws IndexOutOfBoundsException, NullPointerException
{
if (__b == null)
throw new NullPointerException("NARG");
if (__o < 0 || __l < 0 || (__o + __l) > __b.length)
throw new IndexOutOfBoundsException("IOOB");
// Always encodes to one character, so if one character cannot fit in
// the buffer then fail
if (__l < 1)
return -1;
// Remap some characters?
switch (__c)
{
// Convert
case 0x20AC: __c = (char)0x00A4; break;
case 0x0160: __c = (char)0x00A6; break;
case 0x0161: __c = (char)0x00A8; break;
case 0x017D: __c = (char)0x00B4; break;
case 0x017E: __c = (char)0x00B8; break;
case 0x0152: __c = (char)0x00BC; break;
case 0x0153: __c = (char)0x00BD; break;
case 0x0178: __c = (char)0x00BE; break;
// Cannot be encoded
case 0x00A4:
case 0x00A6:
case 0x00A8:
case 0x00B4:
case 0x00B8:
case 0x00BC:
case 0x00BD:
case 0x00BE: __c = (char)0xFFFD; break;
}
// These characters are invalid, so they all become the replacement
// character
if (__c >= 0x100)
__b[__o] = '?';
// Encode as is
else
__b[__o] = (byte)__c;
// Only single characters written
return 1;
}
/**
* {@inheritDc}
* @since 2019/04/29
*/
@Override
public final String encodingName()
{
return "iso-8859-15";
}
/**
* {@inheritDoc}
* @since 2019/04/29
*/
@Override
public final int maximumSequenceLength()
{
return 1;
}
}
......@@ -15,7 +15,7 @@ package cc.squirreljme.runtime.cldc.io;
*
* @since 2018/11/11
*/
public class ISO88591Decoder
public final class ISO88591Decoder
implements Decoder
{
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment