Here you can find the source of prettyPrintWarningMessage(final List
Parameter | Description |
---|---|
results | the pretty printed message |
message | the message |
private static void prettyPrintWarningMessage(final List<String> results, final String message)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { private static final int TEXT_WARNING_WIDTH = 68; private static final String TEXT_WARNING_PREFIX = "* "; private static final char ESCAPE_CHAR = '\u001B'; /**/* w w w . j ava2 s . c o m*/ * pretty print the warning message supplied * * @param results the pretty printed message * @param message the message */ private static void prettyPrintWarningMessage(final List<String> results, final String message) { for (final String line : message.split("\\r?\\n")) { final StringBuilder builder = new StringBuilder(line); while (builder.length() > TEXT_WARNING_WIDTH) { int space = getLastSpace(builder, TEXT_WARNING_WIDTH); if (space <= 0) { space = TEXT_WARNING_WIDTH; } results.add(String.format("%s%s", TEXT_WARNING_PREFIX, builder.substring(0, space))); builder.delete(0, space + 1); } results.add(String.format("%s%s", TEXT_WARNING_PREFIX, builder)); } } /** * Returns the last whitespace location in string, before width characters. * @param message The message to break. * @param width The width of the line. * @return The last whitespace location. */ private static int getLastSpace(final CharSequence message, final int width) { final int length = message.length(); int stopPos = width; int currPos = 0; int lastSpace = -1; boolean inEscape = false; while (currPos < stopPos && currPos < length) { final char c = message.charAt(currPos); if (c == ESCAPE_CHAR) { stopPos++; inEscape = true; } else if (inEscape) { stopPos++; if (Character.isLetter(c)) { inEscape = false; } } else if (Character.isWhitespace(c)) { lastSpace = currPos; } currPos++; } return lastSpace; } }