Exemplo n.º 1
0
 // TODO: Doesn't belong here.
 private static String getCommonEnding(String left, String right) {
   StringBuilder ending = new StringBuilder();
   for (int i = 0; i < left.length() && i < right.length(); ++i) {
     char leftChar = left.charAt(left.length() - 1 - i);
     char rightChar = right.charAt(right.length() - 1 - i);
     if (leftChar != rightChar) {
       break;
     }
     ending.append(leftChar);
   }
   return ending.toString();
 }
Exemplo n.º 2
0
 private static String getUnmatchedBrackets(final String initialText) {
   String text = initialText.replaceAll("\\\\.", "_"); // Remove escaped characters.
   text = text.replaceAll("'.'", "_"); // Remove character literals.
   text = text.replaceAll("\"([^\\n]*?)\"", "_"); // Remove string literals.
   text = text.replaceAll("/\\*(?s).*?\\*/", "_"); // Remove C comments.
   text = text.replaceAll("//[^\\n]*", "_"); // Remove C++ comments.
   StringBuilder unmatchedBrackets = new StringBuilder();
   for (int i = 0; i < text.length(); ++i) {
     char ch = text.charAt(i);
     if (PBracketUtilities.isOpenBracket(ch) && ch != '<') {
       unmatchedBrackets.append(ch);
     } else if (PBracketUtilities.isCloseBracket(ch) && ch != '>') {
       char openBracket = PBracketUtilities.getPartnerForBracket(ch);
       int lastCharIndex = unmatchedBrackets.length() - 1;
       if (lastCharIndex >= 0 && unmatchedBrackets.charAt(lastCharIndex) == openBracket) {
         unmatchedBrackets.deleteCharAt(lastCharIndex);
       } else {
         unmatchedBrackets.append(ch);
       }
     }
   }
   return unmatchedBrackets.toString();
 }