@@ -10,6 +10,8 @@ import * as properties from "properties";
10
10
import * as vscode from "vscode" ;
11
11
import * as WinReg from "winreg" ;
12
12
13
+ const encodingMapping : object = JSON . parse ( fs . readFileSync ( path . join ( __dirname , "../../../misc" , "codepageMapping.json" ) , "utf8" ) ) ;
14
+
13
15
/**
14
16
* This function will return the VSCode C/C++ extesnion compatible platform literals.
15
17
* @function getCppConfigPlatform
@@ -211,30 +213,10 @@ export function spawn(command: string, outputChannel: vscode.OutputChannel, args
211
213
212
214
if ( outputChannel ) {
213
215
child . stdout . on ( "data" , ( data : Buffer ) => {
214
- switch ( codepage ) {
215
- case "932" :
216
- outputChannel . append ( iconv . decode ( data , "Shift_JIS" ) ) ;
217
- break ;
218
- case "936" :
219
- outputChannel . append ( iconv . decode ( data , "GBK" ) ) ;
220
- break ;
221
- default :
222
- outputChannel . append ( data . toString ( ) ) ;
223
- break ;
224
- }
216
+ outputChannel . append ( decodeData ( data , codepage ) ) ;
225
217
} ) ;
226
218
child . stderr . on ( "data" , ( data : Buffer ) => {
227
- switch ( codepage ) {
228
- case "932" :
229
- outputChannel . append ( iconv . decode ( data , "Shift_JIS" ) ) ;
230
- break ;
231
- case "936" :
232
- outputChannel . append ( iconv . decode ( data , "GBK" ) ) ;
233
- break ;
234
- default :
235
- outputChannel . append ( data . toString ( ) ) ;
236
- break ;
237
- }
219
+ outputChannel . append ( decodeData ( data , codepage ) ) ;
238
220
} ) ;
239
221
}
240
222
@@ -250,6 +232,13 @@ export function spawn(command: string, outputChannel: vscode.OutputChannel, args
250
232
} ) ;
251
233
}
252
234
235
+ export function decodeData ( data : Buffer , codepage : string ) : string {
236
+ if ( encodingMapping . hasOwnProperty ( codepage ) ) {
237
+ return iconv . decode ( data , encodingMapping [ codepage ] ) ;
238
+ }
239
+ return data . toString ( ) ;
240
+ }
241
+
253
242
export function tryParseJSON ( jsonString : string ) {
254
243
try {
255
244
const jsonObj = JSON . parse ( jsonString ) ;
@@ -397,5 +386,5 @@ export function getRegistryValues(hive: string, key: string, name: string): Prom
397
386
}
398
387
399
388
export function convertToHex ( number , width = 0 ) {
400
- return padStart ( number . toString ( 16 ) , width , "0" ) ;
389
+ return padStart ( number . toString ( 16 ) , width , "0" ) ;
401
390
}
0 commit comments