mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-25 06:17:33 +00:00
fix: Improve line endings in the output files
https://github.com/plantuml/plantuml/pull/1183
This commit is contained in:
parent
44b4051016
commit
534fc27942
@ -105,14 +105,14 @@ public abstract class AbstractPSystem implements Diagram {
|
||||
}
|
||||
|
||||
final public String getMetadata() {
|
||||
if (source == null) {
|
||||
if (source == null)
|
||||
return getVersion();
|
||||
}
|
||||
final String rawString = source.getRawString();
|
||||
final String plainString = source.getPlainString();
|
||||
if (rawString != null && rawString.equals(plainString)) {
|
||||
|
||||
final String rawString = source.getRawString("\n");
|
||||
final String plainString = source.getPlainString("\n");
|
||||
if (rawString != null && rawString.equals(plainString))
|
||||
return rawString + BackSlash.NEWLINE + getVersion();
|
||||
}
|
||||
|
||||
return rawString + BackSlash.NEWLINE + plainString + BackSlash.NEWLINE + getVersion();
|
||||
}
|
||||
|
||||
@ -121,9 +121,9 @@ public abstract class AbstractPSystem implements Diagram {
|
||||
}
|
||||
|
||||
final public long seed() {
|
||||
if (source == null) {
|
||||
if (source == null)
|
||||
return 42;
|
||||
}
|
||||
|
||||
return getSource().seed();
|
||||
}
|
||||
|
||||
@ -150,9 +150,9 @@ public abstract class AbstractPSystem implements Diagram {
|
||||
}
|
||||
|
||||
public DisplayPositionned getTitle() {
|
||||
if (source == null) {
|
||||
if (source == null)
|
||||
return DisplayPositioned.single(Display.empty(), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
|
||||
}
|
||||
|
||||
return DisplayPositioned.single(source.getTitle(), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ public class BlockUml {
|
||||
// ::comment when __CORE__
|
||||
public String getEncodedUrl() throws IOException {
|
||||
final Transcoder transcoder = TranscoderUtil.getDefaultTranscoder();
|
||||
final String source = getDiagram().getSource().getPlainString();
|
||||
final String source = getDiagram().getSource().getPlainString("\n");
|
||||
final String encoded = transcoder.encode(source);
|
||||
return encoded;
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ public abstract class UmlDiagram extends TitledDiagram implements Diagram, Annot
|
||||
if (source == null)
|
||||
return "";
|
||||
|
||||
return source.getPlainString();
|
||||
return source.getPlainString("\n");
|
||||
}
|
||||
|
||||
static private List<String> getFailureText1(Throwable exception, String graphvizVersion, String textDiagram) {
|
||||
|
@ -160,32 +160,30 @@ final public class UmlSource {
|
||||
// }
|
||||
|
||||
/**
|
||||
* Return the source as a single String with <code>\n</code> as line separator.
|
||||
* Return the source as a single String.
|
||||
*
|
||||
* @return the whole diagram source
|
||||
*/
|
||||
public String getPlainString() {
|
||||
public String getPlainString(String separator) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (StringLocated s : source) {
|
||||
sb.append(s.getString());
|
||||
sb.append('\r');
|
||||
sb.append(BackSlash.CHAR_NEWLINE);
|
||||
sb.append(separator);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getRawString() {
|
||||
public String getRawString(String separator) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (StringLocated s : rawSource) {
|
||||
sb.append(s.getString());
|
||||
sb.append('\r');
|
||||
sb.append(BackSlash.CHAR_NEWLINE);
|
||||
sb.append(separator);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public long seed() {
|
||||
return StringUtils.seed(getPlainString());
|
||||
return StringUtils.seed(getPlainString("\n"));
|
||||
}
|
||||
|
||||
public String getLine(LineLocation n) {
|
||||
|
@ -109,7 +109,7 @@ public class PSystemDitaa extends AbstractPSystem {
|
||||
final protected ImageData exportDiagramNow(OutputStream os, int num, FileFormatOption fileFormat)
|
||||
throws IOException {
|
||||
if (fileFormat.getFileFormat() == FileFormat.ATXT) {
|
||||
os.write(getSource().getPlainString().getBytes());
|
||||
os.write(getSource().getPlainString(BackSlash.lineSeparator()).getBytes());
|
||||
return ImageDataSimple.ok();
|
||||
}
|
||||
|
||||
|
@ -113,6 +113,7 @@ import net.sourceforge.plantuml.style.SName;
|
||||
import net.sourceforge.plantuml.style.Style;
|
||||
import net.sourceforge.plantuml.style.StyleSignatureBasic;
|
||||
import net.sourceforge.plantuml.svek.GraphvizCrash;
|
||||
import net.sourceforge.plantuml.text.BackSlash;
|
||||
|
||||
public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprite {
|
||||
|
||||
@ -256,7 +257,8 @@ public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprit
|
||||
|
||||
} catch (Throwable t) {
|
||||
Logme.error(t);
|
||||
final UDrawable crash = new GraphvizCrash(getSource().getPlainString(), false, t);
|
||||
final UDrawable crash = new GraphvizCrash(getSource().getPlainString(BackSlash.lineSeparator()),
|
||||
false, t);
|
||||
crash.drawU(ug);
|
||||
|
||||
}
|
||||
|
@ -122,6 +122,7 @@ import net.sourceforge.plantuml.svek.image.EntityImageStateEmptyDescription;
|
||||
import net.sourceforge.plantuml.svek.image.EntityImageSynchroBar;
|
||||
import net.sourceforge.plantuml.svek.image.EntityImageTips;
|
||||
import net.sourceforge.plantuml.svek.image.EntityImageUseCase;
|
||||
import net.sourceforge.plantuml.text.BackSlash;
|
||||
import net.sourceforge.plantuml.text.Guillemet;
|
||||
import net.sourceforge.plantuml.utils.Log;
|
||||
|
||||
@ -455,11 +456,12 @@ public final class GeneralImageBuilder {
|
||||
try {
|
||||
svg = dotStringFactory.getSvg(basefile, dotStrings);
|
||||
} catch (IOException e) {
|
||||
return new GraphvizCrash(source.getPlainString(), GraphvizUtils.graphviz244onWindows(), e);
|
||||
return new GraphvizCrash(source.getPlainString(BackSlash.lineSeparator()),
|
||||
GraphvizUtils.graphviz244onWindows(), e);
|
||||
}
|
||||
if (svg.length() == 0)
|
||||
return new GraphvizCrash(source.getPlainString(), GraphvizUtils.graphviz244onWindows(),
|
||||
new EmptySvgException());
|
||||
return new GraphvizCrash(source.getPlainString(BackSlash.lineSeparator()),
|
||||
GraphvizUtils.graphviz244onWindows(), new EmptySvgException());
|
||||
|
||||
final String graphvizVersion = extractGraphvizVersion(svg);
|
||||
try {
|
||||
@ -469,7 +471,8 @@ public final class GeneralImageBuilder {
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
Log.error("Exception " + e);
|
||||
throw new UnparsableGraphvizException(e, graphvizVersion, svg, source.getPlainString());
|
||||
throw new UnparsableGraphvizException(e, graphvizVersion, svg,
|
||||
source.getPlainString(BackSlash.lineSeparator()));
|
||||
}
|
||||
// ::done
|
||||
// ::uncomment when __CORE__
|
||||
|
@ -47,6 +47,10 @@ public class BackSlash {
|
||||
public static final String BS_BS_N = "\\n";
|
||||
public static final String NEWLINE = "\n";
|
||||
public static final char CHAR_NEWLINE = '\n';
|
||||
|
||||
public static final String lineSeparator() {
|
||||
return System.lineSeparator();
|
||||
}
|
||||
|
||||
public static char hiddenNewLine() {
|
||||
return StringUtils.PRIVATE_BLOCK + BackSlash.CHAR_NEWLINE;
|
||||
@ -67,9 +71,9 @@ public class BackSlash {
|
||||
}
|
||||
|
||||
public static List<String> getWithNewlines(CharSequence s) {
|
||||
if (s == null) {
|
||||
if (s == null)
|
||||
return null;
|
||||
}
|
||||
|
||||
final List<String> result = new ArrayList<>();
|
||||
final StringBuilder current = new StringBuilder();
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
@ -94,9 +98,9 @@ public class BackSlash {
|
||||
}
|
||||
|
||||
public static String translateBackSlashes(CharSequence s) {
|
||||
if (s == null) {
|
||||
if (s == null)
|
||||
return null;
|
||||
}
|
||||
|
||||
// final String tmps = s.toString();
|
||||
// if (tmps.indexOf('\\') == -1) {
|
||||
// return tmps;
|
||||
@ -121,24 +125,24 @@ public class BackSlash {
|
||||
}
|
||||
|
||||
public static String untranslateBackSlashes(CharSequence s) {
|
||||
if (s == null) {
|
||||
if (s == null)
|
||||
return null;
|
||||
}
|
||||
|
||||
final StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c > StringUtils.PRIVATE_BLOCK && c < '\uE07F') {
|
||||
if (c > StringUtils.PRIVATE_BLOCK && c < '\uE07F')
|
||||
c = (char) (c - StringUtils.PRIVATE_BLOCK);
|
||||
}
|
||||
|
||||
result.append(c);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static char translateChar(char c) {
|
||||
if (c > 128) {
|
||||
if (c > 128)
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
return (char) (StringUtils.PRIVATE_BLOCK + c);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ public class A0000_TestResult {
|
||||
DPI: 96
|
||||
dimension: [ 185.5185 ; 113.0000 ]
|
||||
scaleFactor: 1.0000
|
||||
seed: 5605069588648637213
|
||||
seed: 7067927655347766828
|
||||
svgLinkTarget: _top
|
||||
hoverPathColorRGB: null
|
||||
preserveAspectRatio: none
|
||||
|
@ -7,7 +7,7 @@ public class A0001_TestResult {
|
||||
DPI: 96
|
||||
dimension: [ 296.7331 ; 285.0000 ]
|
||||
scaleFactor: 1.0000
|
||||
seed: -1212656935193060805
|
||||
seed: 1230863714434809965
|
||||
svgLinkTarget: _top
|
||||
hoverPathColorRGB: null
|
||||
preserveAspectRatio: none
|
||||
|
@ -7,7 +7,7 @@ public class A0002_TestResult {
|
||||
DPI: 96
|
||||
dimension: [ 660.1096 ; 994.5000 ]
|
||||
scaleFactor: 1.0000
|
||||
seed: -9181376250803721714
|
||||
seed: -2543044357581316352
|
||||
svgLinkTarget: _top
|
||||
hoverPathColorRGB: null
|
||||
preserveAspectRatio: none
|
||||
|
@ -7,7 +7,7 @@ public class A0003_TestResult {
|
||||
DPI: 96
|
||||
dimension: [ 367.7447 ; 76.0000 ]
|
||||
scaleFactor: 2.0000
|
||||
seed: -6040919743496430850
|
||||
seed: 2061842952546013393
|
||||
svgLinkTarget: _top
|
||||
hoverPathColorRGB: null
|
||||
preserveAspectRatio: none
|
||||
|
@ -7,7 +7,7 @@ public class A0004_TestResult {
|
||||
DPI: 96
|
||||
dimension: [ 550.6156 ; 680.0000 ]
|
||||
scaleFactor: 1.0000
|
||||
seed: 6985134683589840646
|
||||
seed: -1093380870564056548
|
||||
svgLinkTarget: _top
|
||||
hoverPathColorRGB: null
|
||||
preserveAspectRatio: none
|
||||
|
@ -7,7 +7,7 @@ public class A0005_TestResult {
|
||||
DPI: 96
|
||||
dimension: [ 134.0935 ; 286.0000 ]
|
||||
scaleFactor: 1.0000
|
||||
seed: 1145907385572836867
|
||||
seed: -2035695693520640443
|
||||
svgLinkTarget: _top
|
||||
hoverPathColorRGB: null
|
||||
preserveAspectRatio: none
|
||||
|
@ -7,7 +7,7 @@ public class A0006_TestResult {
|
||||
DPI: 96
|
||||
dimension: [ 149.3989 ; 231.0000 ]
|
||||
scaleFactor: 1.0000
|
||||
seed: -2375783792654745998
|
||||
seed: -967197275408610478
|
||||
svgLinkTarget: _top
|
||||
hoverPathColorRGB: null
|
||||
preserveAspectRatio: none
|
||||
|
Loading…
Reference in New Issue
Block a user