1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-06 18:30:52 +00:00
plantuml/src/net/sourceforge/plantuml/StringUtils.java

569 lines
15 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
2017-03-15 19:13:31 +00:00
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
2010-11-15 20:35:36 +00:00
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2010-11-15 20:35:36 +00:00
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
2022-12-17 11:10:05 +00:00
package net.sourceforge.plantuml;
2010-11-15 20:35:36 +00:00
import java.util.ArrayList;
2011-01-05 18:23:06 +00:00
import java.util.Collections;
2010-11-15 20:35:36 +00:00
import java.util.List;
2015-04-07 18:18:37 +00:00
import java.util.Locale;
2010-11-15 20:35:36 +00:00
import java.util.regex.Matcher;
import java.util.regex.Pattern;
2017-10-07 09:46:53 +00:00
import net.sourceforge.plantuml.asciiart.Wcwidth;
2016-05-31 19:41:55 +00:00
import net.sourceforge.plantuml.command.regex.Matcher2;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.command.regex.MyPattern;
2016-05-31 19:41:55 +00:00
import net.sourceforge.plantuml.command.regex.Pattern2;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2022-12-17 11:10:05 +00:00
import net.sourceforge.plantuml.utils.Direction;
import net.sourceforge.plantuml.utils.Log;
2011-01-29 15:09:35 +00:00
2015-04-07 18:18:37 +00:00
// Do not move
2010-11-15 20:35:36 +00:00
public class StringUtils {
2020-12-14 18:31:06 +00:00
public static final char USER_NEWLINE = '\uEE00';
public static final char USER_TAB = '\uEE01';
public static final char HR_SIMPLE = '\uEEFF';
public static final char HR_DOUBLE = '\uEEFE';
public static final char HR_DOTTED = '\uEEFD';
public static final char HR_BOLD = '\uEEFC';
public static final char PRIVATE_FIELD = '\uEEFB';
public static final char PROTECTED_FIELD = '\uEEFA';
public static final char PACKAGE_PRIVATE_FIELD = '\uEEF9';
public static final char PUBLIC_FIELD = '\uEEF8';
public static final char PRIVATE_METHOD = '\uEEF7';
public static final char PROTECTED_METHOD = '\uEEF6';
public static final char PACKAGE_PRIVATE_METHOD = '\uEEF5';
public static final char PUBLIC_METHOD = '\uEEF4';
public static final char IE_MANDATORY = '\uEEF3';
2021-01-10 20:52:19 +00:00
public static final char BOLD_START = '\uEEF2';
public static final char BOLD_END = '\uEEF1';
2020-12-14 18:31:06 +00:00
// Used in BackSlash
public static final char PRIVATE_BLOCK = '\uE000';
public static final char INTERNAL_BOLD = '\uE100';
public static String toInternalBoldNumber(String s) {
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
final char c = s.charAt(i);
2022-02-17 18:27:32 +00:00
if (c >= '0' && c <= '9')
2020-12-14 18:31:06 +00:00
sb.append(Character.toChars('\uE100' + c - '0'));
2022-02-17 18:27:32 +00:00
else
2020-12-14 18:31:06 +00:00
sb.append(c);
}
return sb.toString();
}
public static void appendInternalToRealBoldNumber(StringBuilder sb, char c) {
2022-02-17 18:27:32 +00:00
if (c >= '\uE100' && c <= ('\uE100' + 9))
2020-12-14 18:31:06 +00:00
sb.append(Character.toChars(0x1d7ce + c - '\uE100'));
2022-02-17 18:27:32 +00:00
else
2020-12-14 18:31:06 +00:00
sb.append(c);
2022-02-17 18:27:32 +00:00
2020-12-14 18:31:06 +00:00
}
public static void appendInternalToPlainNumber(StringBuilder sb, char c) {
2022-02-17 18:27:32 +00:00
if (c >= '\uE100' && c <= ('\uE100' + 9))
2020-12-14 18:31:06 +00:00
sb.append(Character.toChars('0' + c - '\uE100'));
2022-02-17 18:27:32 +00:00
else
2020-12-14 18:31:06 +00:00
sb.append(c);
2022-02-17 18:27:32 +00:00
2020-12-14 18:31:06 +00:00
}
2016-05-31 19:41:55 +00:00
final static public List<String> getSplit(Pattern2 pattern, String line) {
final Matcher2 m = pattern.matcher(line);
2022-02-17 18:27:32 +00:00
if (m.find() == false)
2010-11-15 20:35:36 +00:00
return null;
2022-02-17 18:27:32 +00:00
2021-05-14 08:42:57 +00:00
final List<String> result = new ArrayList<>();
2022-02-17 18:27:32 +00:00
for (int i = 1; i <= m.groupCount(); i++)
2010-11-15 20:35:36 +00:00
result.add(m.group(i));
2022-02-17 18:27:32 +00:00
2010-11-15 20:35:36 +00:00
return result;
}
public static boolean isNotEmpty(CharSequence s) {
return !isEmpty(s);
2010-11-15 20:35:36 +00:00
}
2011-08-08 17:48:29 +00:00
public static boolean isNotEmpty(List<? extends CharSequence> input) {
return input != null && input.size() > 0;
}
public static boolean isEmpty(CharSequence s) {
2022-02-17 18:27:32 +00:00
if (s == null)
return true;
final int length = s.length();
2022-02-17 18:27:32 +00:00
if (length == 0)
return true;
for (int i = 0; i < length; i++) {
2022-02-17 18:27:32 +00:00
if (!isSpaceOrTabOrNull(s.charAt(i)))
return false;
}
return true;
2010-11-15 20:35:36 +00:00
}
public static String manageHtml(String s) {
s = s.replace("<", "&lt;");
s = s.replace(">", "&gt;");
return s;
}
2013-12-10 19:36:50 +00:00
public static String unicode(String s) {
final StringBuilder result = new StringBuilder();
2022-02-17 18:27:32 +00:00
for (char c : s.toCharArray())
2013-12-10 19:36:50 +00:00
if (c > 127 || c == '&' || c == '|') {
final int i = c;
result.append("&#" + i + ";");
} else {
result.append(c);
}
2022-02-17 18:27:32 +00:00
2013-12-10 19:36:50 +00:00
return result.toString();
}
public static String unicodeForHtml(String s) {
final StringBuilder result = new StringBuilder();
2022-02-17 18:27:32 +00:00
for (char c : s.toCharArray())
2013-12-10 19:36:50 +00:00
if (c > 127 || c == '&' || c == '|' || c == '<' || c == '>') {
final int i = c;
result.append("&#" + i + ";");
} else {
result.append(c);
}
2022-02-17 18:27:32 +00:00
2013-12-10 19:36:50 +00:00
return result.toString();
}
public static String unicodeForHtml(Display display) {
final StringBuilder result = new StringBuilder();
for (int i = 0; i < display.size(); i++) {
result.append(unicodeForHtml(display.get(i).toString()));
2022-02-17 18:27:32 +00:00
if (i < display.size() - 1)
2013-12-10 19:36:50 +00:00
result.append("<br>");
2022-02-17 18:27:32 +00:00
2013-12-10 19:36:50 +00:00
}
return result.toString();
}
2010-11-15 20:35:36 +00:00
public static String manageArrowForSequence(String s) {
2013-12-10 19:36:50 +00:00
s = s.replace('=', '-').toLowerCase();
2010-11-15 20:35:36 +00:00
return s;
}
2013-12-10 19:36:50 +00:00
public static String capitalize(String s) {
return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
}
2015-05-31 18:56:03 +00:00
2015-04-07 18:18:37 +00:00
public static String goUpperCase(String s) {
return s.toUpperCase(Locale.ENGLISH);
}
public static char goUpperCase(char c) {
return goUpperCase("" + c).charAt(0);
}
public static String goLowerCase(String s) {
return s.toLowerCase(Locale.ENGLISH);
}
public static char goLowerCase(char c) {
return goLowerCase("" + c).charAt(0);
}
2013-12-10 19:36:50 +00:00
2010-11-15 20:35:36 +00:00
public static String manageArrowForCuca(String s) {
final Direction dir = getArrowDirection(s);
s = s.replace('=', '-');
s = s.replaceAll("\\w*", "");
2022-02-17 18:27:32 +00:00
if (dir == Direction.LEFT || dir == Direction.RIGHT)
2010-11-15 20:35:36 +00:00
s = s.replaceAll("-+", "-");
2022-02-17 18:27:32 +00:00
if (s.length() == 2 && (dir == Direction.UP || dir == Direction.DOWN))
2010-11-15 20:35:36 +00:00
s = s.replaceFirst("-", "--");
2022-02-17 18:27:32 +00:00
2010-11-15 20:35:36 +00:00
return s;
}
public static String manageQueueForCuca(String s) {
final Direction dir = getQueueDirection(s);
s = s.replace('=', '-');
s = s.replaceAll("\\w*", "");
2022-02-17 18:27:32 +00:00
if (dir == Direction.LEFT || dir == Direction.RIGHT)
2010-11-15 20:35:36 +00:00
s = s.replaceAll("-+", "-");
2022-02-17 18:27:32 +00:00
if (s.length() == 1 && (dir == Direction.UP || dir == Direction.DOWN))
2010-11-15 20:35:36 +00:00
s = s.replaceFirst("-", "--");
2022-02-17 18:27:32 +00:00
2010-11-15 20:35:36 +00:00
return s;
}
public static Direction getArrowDirection(String s) {
2022-02-17 18:27:32 +00:00
if (s.endsWith(">"))
2010-11-15 20:35:36 +00:00
return getQueueDirection(s.substring(0, s.length() - 1));
2022-02-17 18:27:32 +00:00
2010-11-15 20:35:36 +00:00
if (s.startsWith("<")) {
2022-02-17 18:27:32 +00:00
if (s.length() == 2)
2010-11-15 20:35:36 +00:00
return Direction.LEFT;
2022-02-17 18:27:32 +00:00
2010-11-15 20:35:36 +00:00
return Direction.UP;
}
throw new IllegalArgumentException(s);
}
public static Direction getQueueDirection(String s) {
2022-02-17 18:27:32 +00:00
if (s.indexOf('<') != -1 || s.indexOf('>') != -1)
2010-11-15 20:35:36 +00:00
throw new IllegalArgumentException(s);
2022-02-17 18:27:32 +00:00
2010-11-15 20:35:36 +00:00
s = s.toLowerCase();
2022-02-17 18:27:32 +00:00
if (s.contains("left"))
2010-11-15 20:35:36 +00:00
return Direction.LEFT;
2022-02-17 18:27:32 +00:00
if (s.contains("right"))
2010-11-15 20:35:36 +00:00
return Direction.RIGHT;
2022-02-17 18:27:32 +00:00
if (s.contains("up"))
2010-11-15 20:35:36 +00:00
return Direction.UP;
2022-02-17 18:27:32 +00:00
2010-11-15 20:35:36 +00:00
if (s.contains("down")) {
return Direction.DOWN;
}
2022-02-17 18:27:32 +00:00
if (s.contains("l"))
2010-11-15 20:35:36 +00:00
return Direction.LEFT;
2022-02-17 18:27:32 +00:00
if (s.contains("r"))
2010-11-15 20:35:36 +00:00
return Direction.RIGHT;
2022-02-17 18:27:32 +00:00
if (s.contains("u"))
2010-11-15 20:35:36 +00:00
return Direction.UP;
2022-02-17 18:27:32 +00:00
if (s.contains("d"))
2010-11-15 20:35:36 +00:00
return Direction.DOWN;
2022-02-17 18:27:32 +00:00
if (s.length() == 1)
2010-11-15 20:35:36 +00:00
return Direction.RIGHT;
2022-02-17 18:27:32 +00:00
2010-11-15 20:35:36 +00:00
return Direction.DOWN;
}
2013-12-10 19:36:50 +00:00
// public static Code eventuallyRemoveStartingAndEndingDoubleQuote(Code s) {
// return Code.of(eventuallyRemoveStartingAndEndingDoubleQuote(s.getCode()));
// }
2015-04-07 18:18:37 +00:00
public static String eventuallyRemoveStartingAndEndingDoubleQuote(String s, String format) {
2022-02-17 18:27:32 +00:00
if (s == null)
2019-12-10 21:45:49 +00:00
return null;
2022-02-17 18:27:32 +00:00
2015-04-07 18:18:37 +00:00
if (format.contains("\"") && s.length() > 1 && isDoubleQuote(s.charAt(0))
2022-02-17 18:27:32 +00:00
&& isDoubleQuote(s.charAt(s.length() - 1)))
2010-11-15 20:35:36 +00:00
return s.substring(1, s.length() - 1);
2022-02-17 18:27:32 +00:00
if (format.contains("(") && s.startsWith("(") && s.endsWith(")"))
2010-11-15 20:35:36 +00:00
return s.substring(1, s.length() - 1);
2022-02-17 18:27:32 +00:00
if (format.contains("[") && s.startsWith("[") && s.endsWith("]"))
2010-11-15 20:35:36 +00:00
return s.substring(1, s.length() - 1);
2022-02-17 18:27:32 +00:00
if (format.contains(":") && s.startsWith(":") && s.endsWith(":"))
2010-11-15 20:35:36 +00:00
return s.substring(1, s.length() - 1);
2022-02-17 18:27:32 +00:00
2010-11-15 20:35:36 +00:00
return s;
}
2015-04-07 18:18:37 +00:00
public static String eventuallyRemoveStartingAndEndingDoubleQuote(String s) {
2022-02-17 18:27:32 +00:00
if (s == null)
2017-04-05 17:37:42 +00:00
return s;
2022-02-17 18:27:32 +00:00
2015-04-07 18:18:37 +00:00
return eventuallyRemoveStartingAndEndingDoubleQuote(s, "\"([:");
}
private static boolean isDoubleQuote(char c) {
return c == '\"' || c == '\u201c' || c == '\u201d' || c == '\u00ab' || c == '\u00bb';
}
2010-11-15 20:35:36 +00:00
public static boolean isCJK(char c) {
final Character.UnicodeBlock block = Character.UnicodeBlock.of(c);
2013-12-10 19:36:50 +00:00
Log.println("block=" + block);
2010-11-15 20:35:36 +00:00
return false;
}
public static char hiddenLesserThan() {
return '\u0005';
}
public static char hiddenBiggerThan() {
return '\u0006';
}
2015-06-20 10:54:49 +00:00
2010-11-15 20:35:36 +00:00
public static String hideComparatorCharacters(String s) {
s = s.replace('<', hiddenLesserThan());
s = s.replace('>', hiddenBiggerThan());
return s;
}
public static String showComparatorCharacters(String s) {
s = s.replace(hiddenLesserThan(), '<');
s = s.replace(hiddenBiggerThan(), '>');
return s;
}
2017-10-07 09:46:53 +00:00
private static int getWidth(Display stringsToDisplay) {
2013-12-10 19:36:50 +00:00
int result = 1;
2022-02-17 18:27:32 +00:00
for (CharSequence s : stringsToDisplay)
if (s != null && result < s.length())
2013-12-10 19:36:50 +00:00
result = s.length();
2022-02-17 18:27:32 +00:00
2013-12-10 19:36:50 +00:00
return result;
}
// ::comment when WASM
2017-10-07 09:46:53 +00:00
public static int getWcWidth(Display stringsToDisplay) {
int result = 1;
for (CharSequence s : stringsToDisplay) {
2022-02-17 18:27:32 +00:00
if (s == null)
2018-03-09 21:37:34 +00:00
continue;
2022-02-17 18:27:32 +00:00
2017-10-07 09:46:53 +00:00
final int length = Wcwidth.length(s);
2022-02-17 18:27:32 +00:00
if (result < length)
2017-10-07 09:46:53 +00:00
result = length;
2022-02-17 18:27:32 +00:00
2017-10-07 09:46:53 +00:00
}
return result;
}
// ::done
2017-10-07 09:46:53 +00:00
2010-11-15 20:35:36 +00:00
public static int getHeight(List<? extends CharSequence> stringsToDisplay) {
return stringsToDisplay.size();
}
2013-12-10 19:36:50 +00:00
public static int getHeight(Display stringsToDisplay) {
return stringsToDisplay.size();
}
2011-02-14 11:56:34 +00:00
public static boolean isDiagramCacheable(String uml) {
2022-02-17 18:27:32 +00:00
if (uml.length() < 35)
2017-03-15 19:13:31 +00:00
return false;
2022-02-17 18:27:32 +00:00
2020-06-28 12:40:33 +00:00
// uml = uml.toLowerCase();
// if (uml.startsWith("@startuml\nversion\n")) {
// return false;
// }
// if (uml.startsWith("@startuml\nlicense\n")) {
// return false;
// }
// if (uml.startsWith("@startuml\nlicence\n")) {
// return false;
// }
// if (uml.startsWith("@startuml\nauthor\n")) {
// return false;
// }
// if (uml.startsWith("@startuml\ndonors\n")) {
// return false;
// }
//// if (uml.startsWith("@startuml\ncheckversion")) {
//// return false;
//// }
// if (uml.startsWith("@startuml\ntestdot\n")) {
// return false;
// }
// if (uml.startsWith("@startuml\nsudoku\n")) {
// return false;
// }
// if (uml.startsWith("@startuml\nstdlib\n")) {
2020-05-30 15:20:23 +00:00
// return false;
// }
2011-02-14 11:56:34 +00:00
return true;
}
2011-08-08 17:48:29 +00:00
2017-03-12 17:22:02 +00:00
public static int getPragmaRevision(String uml) {
uml = uml.toLowerCase();
final String header = "@startuml\n!pragma revision ";
2022-02-17 18:27:32 +00:00
if (uml.startsWith(header) == false)
2017-03-12 17:22:02 +00:00
return -1;
2022-02-17 18:27:32 +00:00
2017-03-12 17:22:02 +00:00
int x1 = header.length();
int x2 = x1;
2022-02-17 18:27:32 +00:00
while (x2 < uml.length() && Character.isDigit(uml.charAt(x2)))
2017-03-12 17:22:02 +00:00
x2++;
2022-02-17 18:27:32 +00:00
if (x1 == x2)
2017-03-12 17:22:02 +00:00
return -1;
2022-02-17 18:27:32 +00:00
2017-03-12 17:22:02 +00:00
return Integer.parseInt(uml.substring(x1, x2));
}
2011-08-08 17:48:29 +00:00
public static List<String> splitComma(String s) {
2015-05-31 18:56:03 +00:00
s = trin(s);
2021-05-14 08:42:57 +00:00
final List<String> result = new ArrayList<>();
2021-05-23 15:35:13 +00:00
final Pattern2 p = MyPattern.cmpile("([%pLN_.]+|[%g][^%g]+[%g])");
2016-05-31 19:41:55 +00:00
final Matcher2 m = p.matcher(s);
2022-02-17 18:27:32 +00:00
while (m.find())
2011-08-08 17:48:29 +00:00
result.add(eventuallyRemoveStartingAndEndingDoubleQuote(m.group(0)));
2022-02-17 18:27:32 +00:00
2011-08-08 17:48:29 +00:00
return Collections.unmodifiableList(result);
}
2013-12-10 19:36:50 +00:00
2011-08-08 17:48:29 +00:00
public static String getUid(String uid1, int uid2) {
return uid1 + String.format("%04d", uid2);
}
2013-12-10 19:36:50 +00:00
public static <O> List<O> merge(List<O> l1, List<O> l2) {
2021-05-14 08:42:57 +00:00
final List<O> result = new ArrayList<>(l1);
2013-12-10 19:36:50 +00:00
result.addAll(l2);
return Collections.unmodifiableList(result);
}
2011-08-08 17:48:29 +00:00
2015-04-07 18:18:37 +00:00
public static boolean endsWithBackslash(final String s) {
return s.endsWith("\\") && s.endsWith("\\\\") == false;
}
2016-12-21 22:10:29 +00:00
public static String rot(String s) {
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
2022-02-17 18:27:32 +00:00
if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M'))
2016-12-21 22:10:29 +00:00
c += 13;
2022-02-17 18:27:32 +00:00
else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z'))
2016-12-21 22:10:29 +00:00
c -= 13;
2022-02-17 18:27:32 +00:00
else if (c > 126)
2017-10-07 09:46:53 +00:00
throw new IllegalArgumentException(s);
2022-02-17 18:27:32 +00:00
2016-12-21 22:10:29 +00:00
sb.append(c);
}
return sb.toString();
}
2015-09-06 17:28:59 +00:00
public static String manageUnicodeNotationUplus(String s) {
2017-03-12 17:22:02 +00:00
final Pattern pattern = Pattern.compile("\\<U\\+([0-9a-fA-F]{4,5})\\>");
2015-09-06 17:28:59 +00:00
final Matcher matcher = pattern.matcher(s);
final StringBuffer result = new StringBuffer(); // Can't be switched to StringBuilder in order to support Java 8
2015-09-06 17:28:59 +00:00
while (matcher.find()) {
final String num = matcher.group(1);
final int value = Integer.parseInt(num, 16);
2019-07-14 20:09:26 +00:00
final String replace = new String(Character.toChars(value));
matcher.appendReplacement(result, Matcher.quoteReplacement(replace));
2015-09-06 17:28:59 +00:00
}
matcher.appendTail(result);
return result.toString();
}
public static String manageAmpDiese(String s) {
final Pattern pattern = Pattern.compile("\\&#([0-9]+);");
final Matcher matcher = pattern.matcher(s);
final StringBuffer result = new StringBuffer(); // Can't be switched to StringBuilder in order to support Java 8
2015-09-06 17:28:59 +00:00
while (matcher.find()) {
final String num = matcher.group(1);
final char c = (char) Integer.parseInt(num);
matcher.appendReplacement(result, "" + c);
}
matcher.appendTail(result);
return result.toString();
}
2015-11-01 18:37:20 +00:00
public static String manageTildeArobaseStart(String s) {
s = s.replaceAll("~@start", "@start");
return s;
}
2015-06-20 10:54:49 +00:00
public static String trinNoTrace(CharSequence s) {
return s.toString().trim();
2015-05-31 18:56:03 +00:00
}
2019-03-29 22:14:07 +00:00
public static String trin(String arg) {
2022-02-17 18:27:32 +00:00
if (arg.length() == 0)
2019-03-29 22:14:07 +00:00
return arg;
2022-02-17 18:27:32 +00:00
return trinEndingInternal(arg, getPositionStartNonSpace(arg));
}
private static int getPositionStartNonSpace(String arg) {
2015-06-20 10:54:49 +00:00
int i = 0;
2022-02-17 18:27:32 +00:00
while (i < arg.length() && isSpaceOrTabOrNull(arg.charAt(i)))
2015-06-20 10:54:49 +00:00
i++;
2022-02-17 18:27:32 +00:00
return i;
}
private static String trinEnding(String arg) {
2022-02-17 18:27:32 +00:00
if (arg.length() == 0)
return arg;
2022-02-17 18:27:32 +00:00
return trinEndingInternal(arg, 0);
}
private static String trinEndingInternal(String arg, int from) {
2015-06-20 10:54:49 +00:00
int j = arg.length() - 1;
2022-02-17 18:27:32 +00:00
while (j >= from && isSpaceOrTabOrNull(arg.charAt(j)))
2015-06-20 10:54:49 +00:00
j--;
2022-02-17 18:27:32 +00:00
if (from == 0 && j == arg.length() - 1)
2019-03-29 22:14:07 +00:00
return arg;
2022-02-17 18:27:32 +00:00
return arg.substring(from, j + 1);
2015-05-31 18:56:03 +00:00
}
2018-08-26 12:09:50 +00:00
private static boolean isSpaceOrTabOrNull(char c) {
return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\0';
}
2020-11-21 17:33:24 +00:00
public static String manageEscapedTabs(String s) {
return s.replace("\\t", "\t");
}
public static long seed(String string) {
long h = 1125899906842597L; // prime
final int len = string.length();
2022-02-17 18:27:32 +00:00
for (int i = 0; i < len; i++)
h = 31 * h + string.charAt(i);
2022-02-17 18:27:32 +00:00
return h;
}
2022-02-17 18:27:32 +00:00
public static String sharp000000(int color) {
final int v = 0xFFFFFF & color;
String s = "000000" + Integer.toHexString(v).toUpperCase();
s = s.substring(s.length() - 6);
return "#" + s;
}
2015-04-07 18:18:37 +00:00
// http://docs.oracle.com/javase/tutorial/i18n/format/dateFormat.html
2010-11-15 20:35:36 +00:00
}