Skip to content

Commit 307a336

Browse files
committed
Added UTF-8 support to web interface
1 parent 35bb1d5 commit 307a336

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

pscweb.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="en-GB"><!-- https://github.com/cpp-tutor/pseudocode-compiler/ -->
33
<head>
4-
<meta charset="UTF-8">
4+
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
55
<title>Pseudocode to JavaScript Compiler</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1">
77
<link href="pscweb.css" type="text/css" rel="stylesheet" />
@@ -14,7 +14,7 @@
1414
<h2 align="center">Pseudocode to JavaScript Compiler</h2>
1515
</div>
1616
<div class="window">
17-
<form id="input">
17+
<form id="input" accept-charset="utf-8">
1818
<label for="program_source_id"><h3 align="center">Type your program in here</h3>
1919
<textarea name="program_source"></textarea>
2020
</label>

pscweb.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,17 @@ function clear_output() {
3636
document.getElementById('program_output').innerHTML = '';
3737
}
3838

39-
function base64enc(rawutf8) {
39+
function toutf8(str) {
40+
var urifmt = '' + encodeURIComponent(str), x = function(s) {
41+
return String.fromCharCode(parseInt(s.substring(1), 16));
42+
}
43+
return urifmt.replace(/%../g, x);
44+
}
45+
46+
function base64enc(input) {
4047
let encweb = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=';
41-
var enc = '', pos = 0, len = rawutf8.length;
48+
var rawutf8 = toutf8(input), enc = '', pos = 0;
49+
let len = rawutf8.length;
4250
while ((len - pos) > 2) {
4351
enc += encweb[(rawutf8.charCodeAt(pos) >> 2) & 0x3f];
4452
enc += encweb[((rawutf8.charCodeAt(pos) << 4) | (rawutf8.charCodeAt(pos + 1) >> 4)) & 0x3f];

0 commit comments

Comments
 (0)