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._); sourceFiles = jsdoc.src.getFilePaths(opts._);
jsdoc.parser.parseFiles(sourceFiles); jsdoc.parser.parseFiles(sourceFiles, opts.encoding);
if (opts.validate) { if (opts.validate) {
var jsonSchema = require('sitepen/jsonSchema'); var jsonSchema = require('sitepen/jsonSchema');

View File

@ -6,31 +6,37 @@
(function() { (function() {
var slash = java.lang.System.getProperty('file.separator') || '/', var slash = java.lang.System.getProperty('file.separator') || '/',
File = Packages.java.io.File, File = java.io.File,
defaultEncoding = java.lang.System.getProperty('file.encoding'); defaultEncoding = java.lang.System.getProperty('file.encoding');
exports.read = function(path, options) { exports.read = function(path, encoding) {
var options = options || {}, 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 || {}, var options = options || {},
encoding = options.encoding || defaultEncoding, encoding = encoding || defaultEncoding,
out; output;
out = new Packages.java.io.PrintWriter( output = new java.io.PrintWriter(
new Packages.java.io.OutputStreamWriter( new java.io.OutputStreamWriter(
new Packages.java.io.FileOutputStream(path), new java.io.FileOutputStream(path),
encoding encoding
) )
); );
out.write(content); output.write(content);
out.flush(); output.flush();
out.close(); output.close();
} }
/** /**

View File

@ -18,9 +18,10 @@
destination: 'jsdoc.xml' 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('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('h', 'help', false, 'Print help message and quit.');
argsParser.addOption('V', 'validate', false, 'Validate the results produced by parsing the source code.'); 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(), var ast = getParser(),
fs = require('common/fs'), fs = require('common/fs'),
source = ''; source = '';
for (i = 0, leni = sourceFiles.length; i < leni; i++) { for (i = 0, leni = sourceFiles.length; i < leni; i++) {
try { try {
source = fs.read(sourceFiles[i]); source = fs.read(sourceFiles[i], encoding);
} }
catch(e) { catch(e) {
print('ERROR: ' + e); print('FILE READ ERROR: ' + e);
continue; continue;
} }