Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed trailing whitespace from normalized strings on format #300

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ public static boolean isEmpty(String value) {
* @return the result of normalize space of the given string.
*/
public static void normalizeSpace(String str, StringBuilder b) {
String space = "";
for (int i = 0; i < str.length(); ++i) {
char c = str.charAt(i);
if (Character.isWhitespace(c)) {
if (i <= 0 || Character.isWhitespace(str.charAt(i - 1)))
if (i == 0 || Character.isWhitespace(str.charAt(i - 1))) {
continue;
b.append(' ');
}
space = " ";
continue;
}
b.append(space);
space = "";
b.append(c);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public XMLBuilder addContentComment(String content) {
if (isJoinCommentLines()) {
xml.append(" ");
xml.append(normalizeSpace(content));
xml.append(" ");
} else {
xml.append(content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void testTagHover() throws BadLocationException {
"<beans xmlns=\"http://www.springframework.org/schema/beans\" xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n"
+ " <bea|n>";
assertHover(xml,
"Defines a single (usually named) bean. A bean definition may contain nested tags for constructor arguments, property values, lookup methods, and replaced methods. Mixing constructor injection and setter injection on the same bean is explicitly supported. ",
"Defines a single (usually named) bean. A bean definition may contain nested tags for constructor arguments, property values, lookup methods, and replaced methods. Mixing constructor injection and setter injection on the same bean is explicitly supported.",
2);

};
Expand All @@ -39,7 +39,7 @@ public void testAttributeNameHover() throws BadLocationException {
"<beans xmlns=\"http://www.springframework.org/schema/beans\" xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n"
+ " <bean clas|s=>";
assertHover(xml,
"The fully qualified name of the bean's class, except if it serves only as a parent definition for child bean definitions. ",
"The fully qualified name of the bean's class, except if it serves only as a parent definition for child bean definitions.",
null);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void testJoinCDATALines() throws BadLocationException {
"line 2" + lineSeparator() +
"line 3" + lineSeparator() +
"]]> </a>";
String expected = "<a>" + lineSeparator() + " <![CDATA[line 1 line 2 line 3 ]]>" + lineSeparator() + "</a>";
String expected = "<a>" + lineSeparator() + " <![CDATA[line 1 line 2 line 3]]>" + lineSeparator() + "</a>";
XMLFormattingOptions formattingOptions = createDefaultFormattingOptions();
formattingOptions.setJoinCDATALines(true);
format(content, expected, formattingOptions);
Expand Down Expand Up @@ -353,7 +353,7 @@ public void testCommentFormatSameLine() throws BadLocationException {
" Content" + lineSeparator() +
"</a> <!-- My Comment -->";
String expected =
"<a>Content </a> <!-- My Comment -->" + lineSeparator() +
"<a>Content</a> <!-- My Comment -->" + lineSeparator() +
"";

XMLFormattingOptions formattingOptions = createDefaultFormattingOptions();
Expand Down Expand Up @@ -397,7 +397,7 @@ public void testElementContentNormalized() throws BadLocationException {
" Content5" + lineSeparator() +
"</a>";
String expected =
"<a>Content Content2 Content3 Content4 Content5 </a>";
"<a>Content Content2 Content3 Content4 Content5</a>";


XMLFormattingOptions formattingOptions = createDefaultFormattingOptions();
Expand Down Expand Up @@ -515,8 +515,8 @@ public void testContentFormatting1() throws BadLocationException {
" </b>" + lineSeparator() +
"</a>";
String expected =
"<a>Content " + lineSeparator() +
" <b>Content2 Content3 </b>" + lineSeparator() +
"<a>Content" + lineSeparator() +
" <b>Content2 Content3</b>" + lineSeparator() +
"</a>";

XMLFormattingOptions formattingOptions = createDefaultFormattingOptions();
Expand Down Expand Up @@ -587,7 +587,7 @@ public void testContentFormatting4() throws BadLocationException {
String content =
"<a> content </a>";
String expected =
"<a>content </a>";
"<a>content</a>";

XMLFormattingOptions formattingOptions = createDefaultFormattingOptions();
formattingOptions.setJoinContentLines(true);
Expand All @@ -601,7 +601,7 @@ public void testContentFormatting5() throws BadLocationException {
" Content" + lineSeparator() +
"</a>";
String expected =
"<a>Content </a>";
"<a>Content</a>";

XMLFormattingOptions formattingOptions = createDefaultFormattingOptions();
formattingOptions.setJoinContentLines(true);
Expand Down