Added encoding option.

This commit is contained in:
Michael Mathews 2010-06-12 10:43:44 +01:00
parent 04bc22c2fa
commit 4820ac398d
4 changed files with 27 additions and 20 deletions

View File

@ -60,7 +60,7 @@
sourceFiles = jsdoc.src.getFilePaths(opts._);
jsdoc.parser.parseFiles(sourceFiles);
jsdoc.parser.parseFiles(sourceFiles, opts.encoding);
if (opts.validate) {
var jsonSchema = require('sitepen/jsonSchema');

View File

@ -6,31 +6,37 @@
(function() {
var slash = java.lang.System.getProperty('file.separator') || '/',
File = Packages.java.io.File,
File = java.io.File,
defaultEncoding = java.lang.System.getProperty('file.encoding');
exports.read = function(path, options) {
exports.read = function(path, encoding) {
var options = options || {},
encoding = options.encoding || defaultEncoding;
encoding = encoding || defaultEncoding,
input;
print('encoding is '+encoding);
input = new java.util.Scanner(
new File(path),
encoding
).useDelimiter("\\Z");
return readFile(path, encoding);
return String( input.next() );
}
exports.write = function(path, content, options) {
exports.write = function(path, content, encoding) {
var options = options || {},
encoding = options.encoding || defaultEncoding,
out;
encoding = encoding || defaultEncoding,
output;
out = new Packages.java.io.PrintWriter(
new Packages.java.io.OutputStreamWriter(
new Packages.java.io.FileOutputStream(path),
output = new java.io.PrintWriter(
new java.io.OutputStreamWriter(
new java.io.FileOutputStream(path),
encoding
)
);
out.write(content);
out.flush();
out.close();
output.write(content);
output.flush();
output.close();
}
/**

View File

@ -18,9 +18,10 @@
destination: 'jsdoc.xml'
};
argsParser.addOption('t', 'template', true, 'The name of the template to use.');
argsParser.addOption('t', 'template', true, 'The name of the template to use. Default: the "default" template');
argsParser.addOption('e', 'encoding', true, 'Assume this encoding when reading all source files. Default: your system default encoding');
argsParser.addOption('T', 'test', false, 'Run unit tests and quit.');
argsParser.addOption('d', 'destination', true, 'The path to output folder.');
argsParser.addOption('d', 'destination', true, 'The path to output folder. Default: ./jsdocs');
argsParser.addOption('h', 'help', false, 'Print help message and quit.');
argsParser.addOption('V', 'validate', false, 'Validate the results produced by parsing the source code.');

View File

@ -125,17 +125,17 @@
/**
*/
exports.parseFiles = function(sourceFiles) {
exports.parseFiles = function(sourceFiles, encoding) {
var ast = getParser(),
fs = require('common/fs'),
source = '';
for (i = 0, leni = sourceFiles.length; i < leni; i++) {
try {
source = fs.read(sourceFiles[i]);
source = fs.read(sourceFiles[i], encoding);
}
catch(e) {
print('ERROR: ' + e);
print('FILE READ ERROR: ' + e);
continue;
}