From 118e164e50bd49d57bce9f5132aff37f300caea6 Mon Sep 17 00:00:00 2001 From: Chris Little Date: Thu, 19 Jan 2012 04:30:00 +0000 Subject: consolidated code to trim leading/trailing whitespace and concatenate lines that don't begin with tags git-svn-id: https://www.crosswire.org/svn/sword-tools/trunk@348 07627401-56e2-0310-80f4-f8cd0041bdcd --- modules/perlconverters/usfm2osis.pl | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'modules/perlconverters') diff --git a/modules/perlconverters/usfm2osis.pl b/modules/perlconverters/usfm2osis.pl index 41e02b3..b287f99 100644 --- a/modules/perlconverters/usfm2osis.pl +++ b/modules/perlconverters/usfm2osis.pl @@ -194,6 +194,27 @@ foreach $file (@files) { } close (SFM); + for ($i = 0; $i < scalar(@filedata);$i++) { + $line = @filedata[$i]; + + ### Trim leading/trailing whitespace +# $line =~ s/[\r\n]+//g; + $line =~ s/\s*$//; + $line =~ s/^\s*//; + + if ($line !~ /^\s*$/) { + if ($line !~ /^\\/) { + @filedata[$i-1] .= " $line"; + splice(@filedata, $i, 1); + $i-- + } + else { + @filedata[$i] = $line; + } + } + } + + $ollevel = 0; $vers = 0; $chap = 0; @@ -212,11 +233,6 @@ foreach $file (@files) { #encoding stuff for ($i = 0; $i < scalar(@filedata); $i++) { $line = @filedata[$i]; - $line =~ s/[\r\n]//g; - - ### Trim leading/trailing whitespace - $line =~ s/\s*$//; - $line =~ s/^\s*//; ### Basic XML entity encoding $line =~ s/&(?![a-zA-Z0-9])/&/g; -- cgit