Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
111 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,39 @@ | ||
define(function() { | ||
"use strict"; | ||
|
||
var mappings, locked, offset = 0; | ||
|
||
var reset = function reset() { | ||
mappings = []; | ||
}; | ||
|
||
var addMapping = function addMapping(options) { | ||
if(locked || !mappings) return; | ||
var mapping = { | ||
name: options.name || '', | ||
start: offset, | ||
end: offset + options.length, | ||
type: options.type || '', | ||
description: options.description || '', | ||
value: options.value || false | ||
}; | ||
// offset += options.length; | ||
mappings.push(mapping); | ||
return mapping; | ||
}; | ||
|
||
var lock = function lock() { | ||
locked = true; | ||
var Mapper = function() { | ||
this.mappings = []; | ||
}; | ||
|
||
return { | ||
reset: reset, | ||
lock: lock, | ||
addMapping: addMapping, | ||
getMappings: function() { | ||
return mappings; | ||
Mapper.prototype = { | ||
reset: function reset() { | ||
this.mappings = []; | ||
}, | ||
addMapping: function addMapping(offset, options) { | ||
var mapping = { | ||
name: options.name || '', | ||
start: offset, | ||
end: offset + options.length, | ||
type: options.type || '', | ||
description: options.description || '', | ||
value: options.value !== undefined ? options.value instanceof Array ? "<structured>" : options.value : false | ||
}; | ||
this.mappings.push(mapping); | ||
return mapping; | ||
}, | ||
last: function() { | ||
return this.mappings[this.mappings.length-1]; | ||
}, | ||
sort: function() { | ||
this.mappings.sort(function(a,b) { | ||
// order by start offsets | ||
var diff = a.start - b.start; | ||
// but, if they're the same: the longest mapping comes first | ||
if(diff === 0) { return b.end - a.end; } | ||
return diff; | ||
}); | ||
} | ||
}; | ||
|
||
return Mapper; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters