Commit 87b50325 authored by Joost Rijneveld's avatar Joost Rijneveld

Added static to convert code points to Strings

parent 1c532f9f
......@@ -10,7 +10,6 @@ package nl.uu.cs.ssm ;
import java.awt.Color;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
public class Machine
{
......@@ -482,11 +481,9 @@ public class Machine
messenger.println( "" + pop() ) ;
break ;
case Instruction.TR_PR_CHAR :
ByteBuffer b = ByteBuffer.allocate(4);
b.putInt(pop());
try
{
messenger.print( "" + new String(b.array(), "UTF-32BE") ) ;
messenger.print( "" + Utils.codePointToString(pop()) ) ;
}
catch (UnsupportedEncodingException e)
{
......
......@@ -10,6 +10,8 @@ package nl.uu.cs.ssm ;
import java.awt.Rectangle;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
......@@ -282,4 +284,12 @@ public class Utils
scrollComponentTo( c, new Rectangle( 0, r.height-2, r.width, 2 ) ) ;
}
/**
* Convert unicode code point to String
*/
public static String codePointToString(int n) throws UnsupportedEncodingException {
ByteBuffer b = ByteBuffer.allocate(4);
b.putInt(n);
return new String(b.array(), "UTF-32BE");
}
}
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