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

Commit

Permalink
Merge pull request #6 from menduz/feature/scalar-raw-value
Browse files Browse the repository at this point in the history
Feature/scalar raw value
  • Loading branch information
KonstantinSviridov authored Oct 4, 2016
2 parents 78fae94 + d690e05 commit 84445e2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
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

0 comments on commit 84445e2

Please sign in to comment.