Beispiel #1
0
 /**
  * Removes the '^' formatting.
  *
  * @param value
  * @return
  */
 public static String removeFormatting(final String value) {
   if (value == null) {
     return null;
   }
   PrimativeTokenizer tokenizer = PrimativeTokenizer.getStringInstance(value, debug);
   StringBuffer tooltip = new StringBuffer();
   boolean removeIndentFormatting = false;
   boolean startOfLine = true;
   Token token = null;
   try {
     tokenizer.initialize();
     token = tokenizer.next();
   } catch (IOException e) {
     return value;
   } catch (LogFile.LockException e) {
     e.printStackTrace();
     return value;
   }
   try {
     while (value != null && !token.is(Token.Type.EOF)) {
       // Remove indent formatting whitespace that comes after new-line formatting
       // character.
       if (removeIndentFormatting) {
         removeIndentFormatting = false;
         if (token.is(Token.Type.WHITESPACE)) {
           token = tokenizer.next();
           startOfLine = false;
           continue;
         }
       }
       // Remove the new-line formatting character ('^' at the beginning of the line).
       if (startOfLine && token.equals(Token.Type.SYMBOL, NEW_LINE_CHAR)) {
         // new-line may be followed by indent formatting that should be removed
         removeIndentFormatting = true;
         startOfLine = false;
       }
       // Convert end of line to a space.
       else if (token.is(Token.Type.EOL)) {
         tooltip.append(' ');
         // signal the start of the next line, so that new-line formatting
         // characters can be found
         startOfLine = true;
       } else {
         tooltip.append(token.getValue());
         startOfLine = false;
       }
       token = tokenizer.next();
     }
   } catch (IOException e) {
     return value;
   }
   return tooltip.toString();
 }
Beispiel #2
0
 /**
  * Uses the '^' formatting to format the value.
  *
  * @param value
  * @return
  */
 public static String[] format(final String value) {
   if (value == null) {
     return null;
   }
   PrimativeTokenizer tokenizer = PrimativeTokenizer.getStringInstance(value, debug);
   ArrayList list = new ArrayList();
   StringBuffer buffer = new StringBuffer(128);
   boolean startOfLine = true;
   boolean firstToken = true;
   Token token = null;
   try {
     tokenizer.initialize();
     token = tokenizer.next();
   } catch (IOException e) {
     return new String[] {value};
   } catch (LogFile.LockException e) {
     e.printStackTrace();
     return new String[] {value};
   }
   try {
     while (token != null && !token.is(Token.Type.EOF)) {
       if (startOfLine) {
         startOfLine = false;
         // Handle new-line character ('^' at the start of the line).
         if (token.equals(Token.Type.SYMBOL, NEW_LINE_CHAR)) {
           list.add(buffer.toString());
           buffer = new StringBuffer(128);
           startOfLine = false;
           token = tokenizer.next();
           continue;
         } else if (!firstToken) {
           // wasn't really the end of the line so convert EOL to a space.
           buffer.append(' ');
         } else {
           firstToken = false;
         }
         // still need to process the current token
       }
       if (token.is(Token.Type.EOL)) {
         // Wait to convert end-of-line to a space. If the next token is '^', then this
         // really is the end of a line.
         startOfLine = true;
       } else {
         buffer.append(token.getValue());
         startOfLine = false;
       }
       token = tokenizer.next();
     }
   } catch (IOException e) {
     return new String[] {value};
   }
   if (buffer.length() > 0) {
     list.add(buffer.toString());
   }
   if (list.size() == 0) {
     return new String[0];
   }
   if (list.size() == 1) {
     return new String[] {(String) list.get(0)};
   }
   return (String[]) list.toArray(new String[list.size()]);
 }