mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-11 10:38:31 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
44
src/vs/base/common/marshalling.ts
Normal file
44
src/vs/base/common/marshalling.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import URI from 'vs/base/common/uri';
|
||||
|
||||
export function stringify(obj: any): string {
|
||||
return JSON.stringify(obj, replacer);
|
||||
}
|
||||
|
||||
export function parse(text: string): any {
|
||||
return JSON.parse(text, reviver);
|
||||
}
|
||||
|
||||
interface MarshalledObject {
|
||||
$mid: number;
|
||||
}
|
||||
|
||||
function replacer(key: string, value: any): any {
|
||||
// URI is done via toJSON-member
|
||||
if (value instanceof RegExp) {
|
||||
return {
|
||||
$mid: 2,
|
||||
source: (<RegExp>value).source,
|
||||
flags: ((<RegExp>value).global ? 'g' : '') + ((<RegExp>value).ignoreCase ? 'i' : '') + ((<RegExp>value).multiline ? 'm' : ''),
|
||||
};
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function reviver(key: string, value: any): any {
|
||||
let marshallingConst: number;
|
||||
if (value !== void 0 && value !== null) {
|
||||
marshallingConst = (<MarshalledObject>value).$mid;
|
||||
}
|
||||
|
||||
switch (marshallingConst) {
|
||||
case 1: return URI.revive(value);
|
||||
case 2: return new RegExp(value.source, value.flags);
|
||||
default: return value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user