[m-rev.] for review: force text encoding on java grades

Peter Wang novalazy at gmail.com
Tue Oct 26 15:06:02 AEDT 2010


How should we handle charset encodings?  For Java and C# it is easy to
add extra open_input and open_output predicates that take an encoding
argument.  For C, we would need to make an assumption about the internal
string encoding (UTF-8) to support those predicates.
To begin with, we'd probably only support UTF-8 and iso-8859-1
as external encodings, which don't need any mapping tables.

---

Branches: main, 10.04

library/io.m:
        Force UTF-8 encoding on text streams in Java grades.

diff --git a/library/io.m b/library/io.m
index 46eed61..a313676 100644
--- a/library/io.m
+++ b/library/io.m
@@ -5789,7 +5789,12 @@ int             ML_fprintf(MercuryFilePtr mf, const char *format, ...);
         public  int                         line_number = 1;
 
         public MR_TextInputFile(java.io.InputStream stream) {
-            input = new java.io.InputStreamReader(stream);
+            try {
+                input = new java.io.InputStreamReader(stream, ""UTF-8"");
+            } catch (java.io.UnsupportedEncodingException e) {
+                // This will never happen.
+                throw new Error(e.toString());
+            }
         }
 
         /*
@@ -5948,8 +5953,14 @@ int             ML_fprintf(MercuryFilePtr mf, const char *format, ...);
         public  int                     line_number = 1;
 
         public MR_TextOutputFile(java.io.OutputStream stream) {
-            output = new java.io.BufferedWriter(
-                new java.io.OutputStreamWriter(stream));
+            try {
+                output = new java.io.BufferedWriter(
+                    new java.io.OutputStreamWriter(stream, ""UTF-8""));
+            }
+            catch (java.io.UnsupportedEncodingException e) {
+                // This will never happen.
+                throw new Error(e.toString());
+            }
         }
 
         public void put(char c)

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list