@Test public void testToNewline() { String result = StringUtils.toNewline("\\n"); assertEquals(result, "\n"); result = StringUtils.toNewline("\\r"); assertEquals(result, "\r"); result = StringUtils.toNewline(""); assertEquals(result, "\n"); result = StringUtils.toNewline(",,"); assertEquals(result, ""); result = StringUtils.toNewline("0,,"); assertEquals(result, "\u0000"); result = StringUtils.toNewline("0,0,0"); assertEquals(result, "\u0000\u0000\u0000"); result = StringUtils.toNewline("0,38,64,116"); assertEquals(result, "\u0000&@t"); }
public static String toNewline(String value) { value = toNotEmptyString(value, Constants.DEFAULT_NEWLINE); char[] chars; if (!value.matches(DIGITS_REGEX)) { String[] split = value.split("\\\\"); chars = new char[split.length - 1]; for (int count = 0; count < split.length; count++) if (split[count].equalsIgnoreCase("n")) chars[count - 1] = '\n'; else if (split[count].equalsIgnoreCase("r")) chars[count - 1] = '\r'; else if (split[count].length() != 0) { throw new RuntimeException("Unable to parse sequence of newline characters. Please specify this input as a comma delimited list of base-10 ASCII character codes."); } } else { String[] split = value.split(DEFAULT_DELIMITER); chars = new char[split.length]; for (int count = 0; count < split.length; count++) chars[count] = (char) Integer.parseInt(split[count]); } return new String(chars); }
StringUtils { public static String toNewline(String value) { value = toNotEmptyString(value, Constants.DEFAULT_NEWLINE); char[] chars; if (!value.matches(DIGITS_REGEX)) { String[] split = value.split("\\\\"); chars = new char[split.length - 1]; for (int count = 0; count < split.length; count++) if (split[count].equalsIgnoreCase("n")) chars[count - 1] = '\n'; else if (split[count].equalsIgnoreCase("r")) chars[count - 1] = '\r'; else if (split[count].length() != 0) { throw new RuntimeException("Unable to parse sequence of newline characters. Please specify this input as a comma delimited list of base-10 ASCII character codes."); } } else { String[] split = value.split(DEFAULT_DELIMITER); chars = new char[split.length]; for (int count = 0; count < split.length; count++) chars[count] = (char) Integer.parseInt(split[count]); } return new String(chars); } }
StringUtils { public static String toNewline(String value) { value = toNotEmptyString(value, Constants.DEFAULT_NEWLINE); char[] chars; if (!value.matches(DIGITS_REGEX)) { String[] split = value.split("\\\\"); chars = new char[split.length - 1]; for (int count = 0; count < split.length; count++) if (split[count].equalsIgnoreCase("n")) chars[count - 1] = '\n'; else if (split[count].equalsIgnoreCase("r")) chars[count - 1] = '\r'; else if (split[count].length() != 0) { throw new RuntimeException("Unable to parse sequence of newline characters. Please specify this input as a comma delimited list of base-10 ASCII character codes."); } } else { String[] split = value.split(DEFAULT_DELIMITER); chars = new char[split.length]; for (int count = 0; count < split.length; count++) chars[count] = (char) Integer.parseInt(split[count]); } return new String(chars); }  }
StringUtils { public static String toNewline(String value) { value = toNotEmptyString(value, Constants.DEFAULT_NEWLINE); char[] chars; if (!value.matches(DIGITS_REGEX)) { String[] split = value.split("\\\\"); chars = new char[split.length - 1]; for (int count = 0; count < split.length; count++) if (split[count].equalsIgnoreCase("n")) chars[count - 1] = '\n'; else if (split[count].equalsIgnoreCase("r")) chars[count - 1] = '\r'; else if (split[count].length() != 0) { throw new RuntimeException("Unable to parse sequence of newline characters. Please specify this input as a comma delimited list of base-10 ASCII character codes."); } } else { String[] split = value.split(DEFAULT_DELIMITER); chars = new char[split.length]; for (int count = 0; count < split.length; count++) chars[count] = (char) Integer.parseInt(split[count]); } return new String(chars); }  static boolean toBoolean(String value, boolean defaultValue); static int toInt(String value, int defaultValue); static String toNotEmptyString(String value, String defaultValue); static String toNewline(String value); static Path toPath(String value, Path defaultValue); static String getStackTraceAsString(Throwable t); static int validatePortNumber(String portStringValue, String portInputName); }
StringUtils { public static String toNewline(String value) { value = toNotEmptyString(value, Constants.DEFAULT_NEWLINE); char[] chars; if (!value.matches(DIGITS_REGEX)) { String[] split = value.split("\\\\"); chars = new char[split.length - 1]; for (int count = 0; count < split.length; count++) if (split[count].equalsIgnoreCase("n")) chars[count - 1] = '\n'; else if (split[count].equalsIgnoreCase("r")) chars[count - 1] = '\r'; else if (split[count].length() != 0) { throw new RuntimeException("Unable to parse sequence of newline characters. Please specify this input as a comma delimited list of base-10 ASCII character codes."); } } else { String[] split = value.split(DEFAULT_DELIMITER); chars = new char[split.length]; for (int count = 0; count < split.length; count++) chars[count] = (char) Integer.parseInt(split[count]); } return new String(chars); }  static boolean toBoolean(String value, boolean defaultValue); static int toInt(String value, int defaultValue); static String toNotEmptyString(String value, String defaultValue); static String toNewline(String value); static Path toPath(String value, Path defaultValue); static String getStackTraceAsString(Throwable t); static int validatePortNumber(String portStringValue, String portInputName); static final String DEFAULT_DELIMITER; static final String DIGITS_REGEX; }