--- a/src/Tools/VSCode/extension/src/isabelle_encoding.ts Mon Mar 07 21:16:12 2022 +0100
+++ b/src/Tools/VSCode/extension/src/isabelle_encoding.ts Tue Mar 08 15:51:18 2022 +0100
@@ -5,35 +5,35 @@
'use strict';
-import * as fs from 'fs'
-import { TextEncoder, TextDecoder } from 'util'
+import { TextEncoder, TextDecoder } from 'util' // VSCODE: REMOVE
+
+const fs = require('fs');
/* defined symbols */
-export interface Symbol_Entry
-{
- symbol: string,
- name: string,
- code: number,
- abbrevs: string[]
+export interface Symbol_Entry {
+ symbol: string;
+ name: string;
+ code: number;
+ abbrevs: string[];
}
-const symbols_file = process.env["ISABELLE_VSCODE_SYMBOLS"]
+const symbols_file = process.env['ISABELLE_VSCODE_SYMBOLS'];
export const symbols: [Symbol_Entry] =
- symbols_file ? JSON.parse(fs.readFileSync(symbols_file).toString()) : []
+ symbols_file ? JSON.parse(fs.readFileSync(symbols_file).toString()) : [];
export const symbols_decode: Map<string, string> =
- new Map(symbols.map((s: Symbol_Entry) => [s.symbol, String.fromCharCode(s.code)]))
+ new Map(symbols.map((s: Symbol_Entry) => [s.symbol, String.fromCharCode(s.code)]));
export const symbols_encode: Map<string, string> =
- new Map(symbols.map((s: Symbol_Entry) => [String.fromCharCode(s.code), s.symbol]))
+ new Map(symbols.map((s: Symbol_Entry) => [String.fromCharCode(s.code), s.symbol]));
/* encoding */
-export const UTF8_Isabelle = 'utf8-isabelle'
+export const UTF8_Isabelle = 'utf8-isabelle';
export interface Options {
stripBOM?: boolean;
@@ -41,24 +41,36 @@
defaultEncoding?: string;
}
-export interface EncoderStream {
- write(str: string): Uint8Array
- end(): Uint8Array | undefined
+export interface IEncoderStream {
+ write(input: string): Uint8Array;
+ end(): Uint8Array | undefined;
}
-export interface DecoderStream {
- write(buf: Uint8Array): string
- end(): string | undefined
+export interface IDecoderStream {
+ write(input: Uint8Array): string;
+ end(): string | undefined;
}
-export function getEncoder(encoding: string, options?: Options): EncoderStream
-{
- const utf8_encoder = new TextEncoder
- return null
+export async function getEncoder(encoding: string, options?: Options): Promise<IEncoderStream> {
+ const utf8_encoder = new TextEncoder();
+ return {
+ write(input: string): Uint8Array {
+ return utf8_encoder.encode(input);
+ },
+ end(): Uint8Array | undefined {
+ return utf8_encoder.encode();
+ }
+ };
}
-export function getDecoder(encoding: string, options?: Options): DecoderStream
-{
- const utf8_decoder = new TextDecoder
- return null
+export async function getDecoder(encoding: string, options?: Options): Promise<IDecoderStream> {
+ const utf8TextDecoder = new TextDecoder();
+ return {
+ write(input: Uint8Array): string {
+ return utf8TextDecoder.decode(input, { stream: true });
+ },
+ end(): string | undefined {
+ return utf8TextDecoder.decode();
+ }
+ };
}