Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Created support for parsing the code in other encodings. #25

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 5 additions & 3 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var _ = require('lodash');
var fs = require('fs');
var path = require('path');
var util = require('util');
var iconv = require('iconv-lite');

var findFiles = require('./utils/find_files');

Expand Down Expand Up @@ -82,7 +83,7 @@ Parser.prototype.parseFiles = function(options, parsedFiles, parsedFilenames) {
// Parser
for (var i = 0; i < files.length; i += 1) {
var filename = options.src + files[i];
var parsedFile = self.parseFile(filename);
var parsedFile = self.parseFile(filename, options.encoding);
if (parsedFile) {
app.log.verbose('parse file: ' + filename);
parsedFiles.push(parsedFile);
Expand All @@ -94,14 +95,15 @@ Parser.prototype.parseFiles = function(options, parsedFiles, parsedFilenames) {
/**
* Execute Fileparsing
*/
Parser.prototype.parseFile = function(filename) {
Parser.prototype.parseFile = function(filename, encoding) {
var self = this;

app.log.debug('inspect file: ' + filename);

self.filename = filename;
self.extension = path.extname(filename).toLowerCase();
self.src = fs.readFileSync(filename, 'utf8').toString();
var fileContent = fs.readFileSync(filename,{encoding:"binary"});
self.src = iconv.decode(fileContent, encoding);
app.log.debug('size: ' + self.src.length);

// unify line-breaks
Expand Down