Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Feature/scalar raw value #6

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"devInstall": "dev-env-installer install"
},
"dependencies": {
"underscore": "^1.8.3"

},
"typings":"dist/index.d.ts",
"repository": {
Expand Down
22 changes: 17 additions & 5 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,16 @@ function charFromCodepoint(c) {

var simpleEscapeCheck = new Array(256); // integer, for fast access
var simpleEscapeMap = new Array(256);
var customEscapeCheck = new Array(256); // integer, for fast access
var customEscapeMap = new Array(256);
for (var i = 0; i < 256; i++) {
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
simpleEscapeMap[i] = simpleEscapeSequence(i);
customEscapeMap[i] = simpleEscapeMap[i] = simpleEscapeSequence(i);
simpleEscapeCheck[i] = simpleEscapeMap[i] ? 1 : 0;
customEscapeCheck[i] = 1;

if (!simpleEscapeCheck[i]) {
customEscapeMap[i] = '\\' + String.fromCharCode(i);
}
}


Expand Down Expand Up @@ -151,14 +158,16 @@ class State{
tagMap:any
version:string
checkLineBreaks:boolean
allowAnyEscape:boolean

constructor(input:string,options:any){
this.input = input;

this.filename = options['filename'] || null;
this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
this.onWarning = options['onWarning'] || null;
this.legacy = options['legacy'] || false;
this.legacy = options['legacy'] || false;
this.allowAnyEscape = options['allowAnyEscape'] || false;

this.implicitTypes = this.schema.compiledImplicit;
this.typeMap = this.schema.compiledTypeMap;
Expand Down Expand Up @@ -571,6 +580,7 @@ function readPlainScalar(state:State, nodeIndent, withinFlowCollection) {
captureSegment(state, captureStart, captureEnd, false);

if (state.result.startPosition!=-1) {
state_result.rawValue = state.input.substring(state_result.startPosition, state_result.endPosition);
return true;
}

Expand Down Expand Up @@ -655,6 +665,7 @@ function readDoubleQuotedScalar(state:State, nodeIndent:number) {
captureSegment(state, captureStart, state.position, true);
state.position++;
scalar.endPosition=state.position;
scalar.rawValue = state.input.substring(scalar.startPosition, scalar.endPosition);
return true;

} else if (0x5C/* \ */ === ch) {
Expand All @@ -665,8 +676,8 @@ function readDoubleQuotedScalar(state:State, nodeIndent:number) {
skipSeparationSpace(state, false, nodeIndent);

// TODO: rework to inline fn with no type cast?
} else if (ch < 256 && simpleEscapeCheck[ch]) {
scalar.value += simpleEscapeMap[ch];
} else if (ch < 256 && (state.allowAnyEscape ? customEscapeCheck[ch] : simpleEscapeCheck[ch])) {
scalar.value += (state.allowAnyEscape ? customEscapeMap[ch] : simpleEscapeMap[ch]);
state.position++;

} else if ((tmp = escapedHexLen(ch)) > 0) {
Expand Down Expand Up @@ -981,6 +992,7 @@ function readBlockScalar(state:State, nodeIndent) {

}
sc.endPosition=i;
sc.rawValue = state.input.substring(sc.startPosition, sc.endPosition);
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion src/yamlAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface YAMLScalar extends YAMLNode{
value:string
doubleQuoted?:boolean
plainScalar?:boolean
rawValue:string
}

export interface YAMLMapping extends YAMLNode{
Expand Down Expand Up @@ -83,7 +84,8 @@ export function newScalar(v:string=""):YAMLScalar{
value:v,
kind:Kind.SCALAR,
parent:null,
doubleQuoted:false
doubleQuoted:false,
rawValue:v
}
}
export function newItems():YAMLSequence{
Expand Down