Changeset 22 in default


Ignore:
Timestamp:
11/02/10 10:19:44 (14 years ago)
Author:
zeiss
Message:
 
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  
    148148        } 
    149149         
     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         
    150168        private void weaveComments() { 
    151169                bufferPosition = 0; 
     
    165183                                        LeafNode currentComment = allComments.get(allCommentsPosition);  
    166184                                        if (currentComment.getTotalOffset() == bufferPositionOriginalText) { 
    167                                                 result.append(currentComment.getText()); 
     185                                                 
    168186                                                 
    169187                                                if (isMultiLineComment(currentComment.getText())) { 
     188                                                        result.append(currentComment.getText()); 
    170189                                                        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                                                } 
    172196                                                bufferPositionOriginalText+=currentComment.getLength(); 
    173197                                                allCommentsPosition++; 
    174198                                        } 
    175199                                } 
    176                                  
    177200                        } else { 
    178201                                result.append(formattedText.substring(bufferPositionFormattedText, bufferPositionFormattedText+1)); 
Note: See TracChangeset for help on using the changeset viewer.