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 ; ...@@ -10,7 +10,6 @@ package nl.uu.cs.ssm ;
import java.awt.Color; import java.awt.Color;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
public class Machine public class Machine
{ {
...@@ -482,11 +481,9 @@ public class Machine ...@@ -482,11 +481,9 @@ public class Machine
messenger.println( "" + pop() ) ; messenger.println( "" + pop() ) ;
break ; break ;
case Instruction.TR_PR_CHAR : case Instruction.TR_PR_CHAR :
ByteBuffer b = ByteBuffer.allocate(4);
b.putInt(pop());
try try
{ {
messenger.print( "" + new String(b.array(), "UTF-32BE") ) ; messenger.print( "" + Utils.codePointToString(pop()) ) ;
} }
catch (UnsupportedEncodingException e) catch (UnsupportedEncodingException e)
{ {
......
...@@ -10,6 +10,8 @@ package nl.uu.cs.ssm ; ...@@ -10,6 +10,8 @@ package nl.uu.cs.ssm ;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.io.File; import java.io.File;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
...@@ -281,5 +283,13 @@ public class Utils ...@@ -281,5 +283,13 @@ public class Utils
Rectangle r = c.getBounds() ; Rectangle r = c.getBounds() ;
scrollComponentTo( c, new Rectangle( 0, r.height-2, r.width, 2 ) ) ; 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