cdocparser
Advanced tools
Comparing version 0.3.0-pre3 to 0.3.0-pre4
34
index.js
@@ -16,2 +16,24 @@ 'use strict'; | ||
/** | ||
* Generate a function that will index a buffer of text | ||
* and return a line for a specify char index | ||
* | ||
* @param {String} buffer buffer that is indexed | ||
* @return {Function} Function that translates an char index to line number | ||
*/ | ||
function index(buffer) { | ||
var indexData = {0: 0}; | ||
for (var i = 0, length = buffer.length, line = 1; i < length; i++) { | ||
if (buffer[i] === '\n') { | ||
indexData[i + 1] = ++line; | ||
} | ||
} | ||
return function (offset) { | ||
for (var i = offset; i >= 0 && buffer[i] != '\n'; i--); | ||
return indexData[i + 1]; | ||
}; | ||
} | ||
var cleanBlockComment = function (comment) { | ||
@@ -37,2 +59,3 @@ var removeFirstLine = comment.replace(/^.*?[\r\n]+|[\r\n].*?$/g, ''); | ||
lines = stripIndent(removedCommentChars).split('\n'); | ||
return { | ||
@@ -57,2 +80,4 @@ lines : lines, | ||
var lineNumberFor = index(code); | ||
while ( (match = docCommentRegEx.exec(code)) ) { | ||
@@ -73,6 +98,13 @@ var commentType = 'normal'; | ||
} | ||
var matchIndex = match.index + match[0].length; | ||
var lineNumberWithOffsetFor = function(offset){ | ||
return lineNumberFor(matchIndex + offset); | ||
}; | ||
comments.push({ | ||
lines: lines, | ||
type: commentType, | ||
context: this.parseContext(code.substr(match.index + match[0].length)) | ||
context: this.parseContext(code.substr(matchIndex), lineNumberWithOffsetFor) | ||
}); | ||
@@ -79,0 +111,0 @@ } |
{ | ||
"name": "cdocparser", | ||
"version": "0.3.0-pre3", | ||
"version": "0.3.0-pre4", | ||
"description": "Extract C style comments and extract context from source", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18226
355