From 7827d9101ebb0248f5a4cdfc20b751b1214b4cde Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Sat, 25 Jun 2011 08:45:49 +0000 Subject: Bug 48877 - Fixed XSSFRichTextString to respect leading and trailing line breaks git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1139505 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/usermodel/XSSFRichTextString.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java') diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java index 964e455e31..e3ed3223a7 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java @@ -440,17 +440,21 @@ public class XSSFRichTextString implements RichTextString { } /** - * Add the xml:spaces="preserve" attribute if the string has leading or trailing white spaces + * Add the xml:spaces="preserve" attribute if the string has leading or trailing spaces * * @param xs the string to check */ protected static void preserveSpaces(STXstring xs) { String text = xs.getStringValue(); - if (text != null && (text.startsWith(" ") || text.endsWith(" "))) { - XmlCursor c = xs.newCursor(); - c.toNextToken(); - c.insertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve"); - c.dispose(); + if (text != null && text.length() > 0) { + char firstChar = text.charAt(0); + char lastChar = text.charAt(text.length() - 1); + if(Character.isWhitespace(firstChar) || Character.isWhitespace(lastChar)) { + XmlCursor c = xs.newCursor(); + c.toNextToken(); + c.insertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve"); + c.dispose(); + } } } -- cgit v1.2.3