一、前言
关于instinct源码包com.googlecode.instinct.internal.util.StringUtil字符串工具类,进行文本缩进indent处理、去除文本缩进unindent处理、每一行进行文本缩进indentEachLine、字符串删除第一行removeFirstNewline、指定文本删除一次removeFirst、删除最后一行内容removeLastNewline、删除指定最后一行内容removeLast,参见下面源码说明部分。
二、源码说明
package com.googlecode.instinct.internal.util;@b@@b@import java.util.regex.Matcher;@b@import java.util.regex.Pattern;@b@@b@public final class StringUtil@b@{@b@ public static final String NEW_LINE = System.getProperty("line.separator");@b@ public static final String INDENT = "\t";@b@ private static final Pattern START_OF_LINE = Pattern.compile("^", 8);@b@@b@ private StringUtil()@b@ {@b@ throw new UnsupportedOperationException();@b@ }@b@@b@ public static String indent(String text) {@b@ return "\t" + text;@b@ }@b@@b@ public static String unindent(String text) {@b@ return removeFirst(text, "\t");@b@ }@b@@b@ public static String indentEachLine(CharSequence text) {@b@ return START_OF_LINE.matcher(text).replaceAll("\t");@b@ }@b@@b@ public static String removeFirstNewline(String text) {@b@ return removeFirst(text, NEW_LINE);@b@ }@b@@b@ public static String removeFirst(String text, String toRemove)@b@ {@b@ return ((text.startsWith(toRemove)) ? text.substring(toRemove.length()) : text);@b@ }@b@@b@ public static String removeLastNewline(String text) {@b@ return removeLast(text, NEW_LINE);@b@ }@b@@b@ public static String removeLast(String text, String toRemove)@b@ {@b@ return ((text.endsWith(toRemove)) ? text.substring(0, text.length() - toRemove.length()) : text);@b@ }@b@}