simple translator: accept DOS, Mac and Unix line breaks when importing text

This commit is contained in:
hallgren
2012-09-17 15:58:40 +00:00
parent fd298007be
commit 1a4f828870

View File

@@ -483,7 +483,7 @@ Translator.prototype.import=function(el) {
}
function done() {
function add_segments(text) {
var ls=text.split("\n")
var ls=lines(text)
var segs= punct.firstChild.checked
? split_punct(text,punctchars.value)
: paras.firstChild.checked
@@ -571,7 +571,7 @@ Translator.prototype.import_globalsight=function(el) {
}
function done() {
function import_text(name,text) {
var ls=text.split("\n")
var ls=lines(text)
if(ls.length>0 && ls[0]=="# GlobalSight Download File") {
t.current=null;
t.local.put("current",null)
@@ -973,6 +973,13 @@ function split_punct(text,punct) {
return segs
}
// Break a string into lines
function lines(text) {
var ls=text.split("\r\n") // DOS
if(ls.length<=1) ls=text.split(/\n|\r/) // Unix | Mac
return ls
}
function supports_local_files() {
// See http://www.html5rocks.com/en/tutorials/file/dndfiles/
return window.File && window.FileList && window.FileReader