From 0ca10663c6d265c1c95b7c8b9936461a1498ce2f Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 24 Sep 2021 14:39:48 +0000 Subject: [PATCH] put back the goto - it is terrible but I don't have time work out why it is needed git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1893597 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/usermodel/HeaderFooter.java | 92 ++++++++++--------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java index 44f1c6c68d..90b9556923 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java @@ -26,13 +26,13 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header protected HeaderFooter() { // } - + /** * @return the internal text representation (combining center, left and right parts). * Possibly empty string if no header or footer is set. Never null. */ - protected abstract String getRawText(); - + protected abstract String getRawText(); + private String[] splitParts() { String text = getRawText(); // default values @@ -40,6 +40,8 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header String _center = ""; String _right = ""; +// FIXME: replace outer goto. just eww. + outer: while (text.length() > 1) { if (text.charAt(0) != '&') { // Mimics the behaviour of Excel, which would put it in the center. @@ -48,43 +50,43 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header } int pos = text.length(); switch (text.charAt(1)) { - case 'L': - if (text.contains("&C")) { - pos = Math.min(pos, text.indexOf("&C")); - } - if (text.contains("&R")) { - pos = Math.min(pos, text.indexOf("&R")); - } - _left = text.substring(2, pos); - text = text.substring(pos); - return new String[] { _left, _center, _right, }; - case 'C': - if (text.contains("&L")) { - pos = Math.min(pos, text.indexOf("&L")); - } - if (text.contains("&R")) { - pos = Math.min(pos, text.indexOf("&R")); - } - _center = text.substring(2, pos); - text = text.substring(pos); - return new String[] { _left, _center, _right, }; - case 'R': - if (text.contains("&C")) { - pos = Math.min(pos, text.indexOf("&C")); - } - if (text.contains("&L")) { - pos = Math.min(pos, text.indexOf("&L")); - } - _right = text.substring(2, pos); - text = text.substring(pos); - return new String[] { _left, _center, _right, }; - default: - // Mimics the behaviour of Excel, which would put it in the center. - _center = text; - break; + case 'L': + if (text.contains("&C")) { + pos = Math.min(pos, text.indexOf("&C")); + } + if (text.contains("&R")) { + pos = Math.min(pos, text.indexOf("&R")); + } + _left = text.substring(2, pos); + text = text.substring(pos); + break; + case 'C': + if (text.contains("&L")) { + pos = Math.min(pos, text.indexOf("&L")); + } + if (text.contains("&R")) { + pos = Math.min(pos, text.indexOf("&R")); + } + _center = text.substring(2, pos); + text = text.substring(pos); + break; + case 'R': + if (text.contains("&C")) { + pos = Math.min(pos, text.indexOf("&C")); + } + if (text.contains("&L")) { + pos = Math.min(pos, text.indexOf("&L")); + } + _right = text.substring(2, pos); + text = text.substring(pos); + break; + default: + // Mimics the behaviour of Excel, which would put it in the center. + _center = text; + break outer; } } - return null; + return new String[] { _left, _center, _right, }; } /** @@ -98,7 +100,7 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header * @param newLeft The string to set as the left side. */ public final void setLeft(String newLeft) { - updatePart(0, newLeft); + updatePart(0, newLeft); } /** @@ -112,7 +114,7 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header * @param newCenter The string to set as the center. */ public final void setCenter(String newCenter) { - updatePart(1, newCenter); + updatePart(1, newCenter); } /** @@ -126,9 +128,9 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header * @param newRight The string to set as the right side. */ public final void setRight(String newRight) { - updatePart(2, newRight); + updatePart(2, newRight); } - + private void updatePart(int partIndex, String newValue) { String[] parts = splitParts(); parts[partIndex] = newValue == null ? "" : newValue; @@ -142,7 +144,7 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header String _left = parts[0]; String _center = parts[1]; String _right = parts[2]; - + if (_center.length() < 1 && _left.length() < 1 && _right.length() < 1) { setHeaderFooterText(""); return; @@ -320,7 +322,7 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header UNDERLINE_FIELD ("&U", true), DOUBLE_UNDERLINE_FIELD ("&E", true), ; - + private final String _representation; private final boolean _occursInPairs; private MarkupTag(String sequence, boolean occursInPairs) { @@ -342,4 +344,4 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header return _occursInPairs; } } -} +} \ No newline at end of file -- 2.39.5