+ builder.append(escape(item));
+ }
+
+ return builder.toString();
+ }
+
+ /**
+ * Return a {@link String} representation of the given list of values.
+ * <p>
+ * NULL will be assimilated to an empty {@link String} if later non-null
+ * values exist, or just ignored if not.
+ * <p>
+ * Example:
+ * <ul>
+ * <li><tt>1</tt>,<tt>NULL</tt>, <tt>3</tt> will become <tt>1</tt>,
+ * <tt>""</tt>, <tt>3</tt></li>
+ * <li><tt>1</tt>,<tt>NULL</tt>, <tt>NULL</tt> will become <tt>1</tt></li>
+ * <li><tt>NULL</tt>, <tt>NULL</tt>, <tt>NULL</tt> will become an empty list
+ * </li>
+ * </ul>
+ *
+ * @param list
+ * the input value
+ * @param value
+ * the value to insert
+ * @param item
+ * the position to insert it at
+ *
+ * @return the raw {@link String} value that correspond to it
+ */
+ static public String fromList(List<String> list, String value, int item) {
+ if (list == null) {
+ list = new ArrayList<String>();
+ }
+
+ while (item >= list.size()) {
+ list.add(null);
+ }
+ list.set(item, value);
+
+ return fromList(list);
+ }
+
+ /**
+ * Return a {@link String} representation of the given list of values.
+ * <p>
+ * NULL will be assimilated to an empty {@link String} if later non-null
+ * values exist, or just ignored if not.
+ * <p>
+ * Example:
+ * <ul>
+ * <li><tt>1</tt>,<tt>NULL</tt>, <tt>3</tt> will become <tt>1</tt>,
+ * <tt>""</tt>, <tt>3</tt></li>
+ * <li><tt>1</tt>,<tt>NULL</tt>, <tt>NULL</tt> will become <tt>1</tt></li>
+ * <li><tt>NULL</tt>, <tt>NULL</tt>, <tt>NULL</tt> will become an empty list
+ * </li>
+ * </ul>
+ *
+ * @param list
+ * the input value
+ * @param value
+ * the value to insert
+ * @param item
+ * the position to insert it at
+ *
+ * @return the raw {@link String} value that correspond to it
+ */
+ static public String fromList(String list, String value, int item) {
+ return fromList(parseList(list, -1), value, item);
+ }
+
+ /**
+ * Escape the given value for list formating (no carets, no NEWLINES...).
+ * <p>
+ * You can unescape it with {@link BundleHelper#unescape(String)}
+ *
+ * @param value
+ * the value to escape
+ *
+ * @return an escaped value that can unquoted by the reverse operation
+ * {@link BundleHelper#unescape(String)}
+ */
+ static public String escape(String value) {
+ return '"' + value//
+ .replace("^", "^^") //
+ .replace("\"", "^\"") //
+ .replace("\n", "^\n") //
+ .replace("\r", "^\r") //
+ + '"';
+ }
+
+ /**
+ * Unescape the given value for list formating (change ^n into NEWLINE and
+ * so on).
+ * <p>
+ * You can escape it with {@link BundleHelper#escape(String)}
+ *
+ * @param value
+ * the value to escape
+ *
+ * @return an unescaped value that can reverted by the reverse operation
+ * {@link BundleHelper#escape(String)}, or NULL if it was badly
+ * formated
+ */
+ static public String unescape(String value) {
+ if (value.length() < 2 || !value.startsWith("\"")
+ || !value.endsWith("\"")) {
+ // Bad format
+ return null;
+ }
+
+ value = value.substring(1, value.length() - 1);
+
+ boolean prevIsBackslash = false;
+ StringBuilder builder = new StringBuilder();
+ for (char car : value.toCharArray()) {
+ if (prevIsBackslash) {
+ switch (car) {
+ case 'n':
+ case 'N':
+ builder.append('\n');
+ break;
+ case 'r':
+ case 'R':
+ builder.append('\r');
+ break;
+ default: // includes ^ and "
+ builder.append(car);
+ break;
+ }
+ prevIsBackslash = false;
+ } else {
+ if (car == '^') {
+ prevIsBackslash = true;
+ } else {
+ builder.append(car);
+ }
+ }
+ }
+
+ if (prevIsBackslash) {
+ // Bad format
+ return null;