Changeset 22 in default
- Timestamp:
- 11/02/10 10:19:44 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/EbnfFormatterVisitor.java
r21 r22 148 148 } 149 149 150 private String scanBackWhitespaces(String str, int position) { 151 StringBuffer whiteSpaces = new StringBuffer(); 152 int currentPosition = position; 153 while (isWhitespace(str.charAt(currentPosition))) { 154 whiteSpaces.append(str.charAt(currentPosition)); 155 currentPosition--; 156 } 157 return whiteSpaces.toString(); 158 } 159 160 private String stripEndingNewline(String str) { 161 int position = str.length() - 1; 162 while ((str.charAt(position) == '\n') || (str.charAt(position) == '\r')) { 163 position--; 164 } 165 return str.substring(0, position + 1); 166 } 167 150 168 private void weaveComments() { 151 169 bufferPosition = 0; … … 165 183 LeafNode currentComment = allComments.get(allCommentsPosition); 166 184 if (currentComment.getTotalOffset() == bufferPositionOriginalText) { 167 result.append(currentComment.getText());185 168 186 169 187 if (isMultiLineComment(currentComment.getText())) { 188 result.append(currentComment.getText()); 170 189 result.append("\n"); 171 } 190 } else { 191 String lastWhiteSpaces = scanBackWhitespaces(result.toString(), result.toString().length()-1); 192 result.delete(result.toString().length() - lastWhiteSpaces.length(), result.toString().length()); 193 result.append(" " + stripEndingNewline(currentComment.getText())); 194 result.append(lastWhiteSpaces); 195 } 172 196 bufferPositionOriginalText+=currentComment.getLength(); 173 197 allCommentsPosition++; 174 198 } 175 199 } 176 177 200 } else { 178 201 result.append(formattedText.substring(bufferPositionFormattedText, bufferPositionFormattedText+1));
Note: See TracChangeset
for help on using the changeset viewer.