diff --git a/hutool-setting/src/main/java/cn/hutool/setting/toml/TomlReader.java b/hutool-setting/src/main/java/cn/hutool/setting/toml/TomlReader.java index 5bf0a00d0..4e3c30330 100644 --- a/hutool-setting/src/main/java/cn/hutool/setting/toml/TomlReader.java +++ b/hutool-setting/src/main/java/cn/hutool/setting/toml/TomlReader.java @@ -20,29 +20,19 @@ import java.time.ZonedDateTime; import java.util.*; /** - * TOML文件读取 - *

DateTimes support

+ * TOML文件读取
+ * 来自:https://github.com/TheElectronWill/TOML-javalib *

- * The datetime support is more extended than in the TOML specification. This reader supports three kind of datetimes: - *

    - *
  1. Full RFC 3339. Examples: 1979-05-27T07:32:00Z, 1979-05-27T00:32:00-07:00, 1979-05-27T00:32:00.999999-07:00
  2. - *
  3. Without local offset. Examples: 1979-05-27T07:32:00, 1979-05-27T00:32:00.999999
  4. - *
  5. Without time (just the date). Example: 2015-03-20
  6. - *
- * Moreover, parsing datetimes gives different objects according to the informations provided. For example, 2015-03-20 - * is parsed as a {@link LocalDate}, 2015-03-20T19:04:35 as a {@link LocalDateTime}, and 2015-03-20T19:04:35+01:00 as a - * {@link ZonedDateTime}. - *

- *

Lenient bare keys

+ * 日期格式支持: + * *

- * This library allows "lenient" bare keys by default, as opposite to the "strict" bare keys required by the TOML - * specification. Strict bare keys may only contain letters, numbers, underscores, and dashes (A-Za-z0-9_-). Lenient - * bare keys may contain any character except those below the space character ' ' in the unicode table, '.', '[', ']' - * and '='. The behaviour of TomlReader regarding bare keys is set in its constructor. - *

+ * 此类支持更加宽松的key,除了{@code A-Za-z0-9_- },还支持' ','.', '[', ']' 和 '=' * * @author TheElectronWill - * */ public class TomlReader { @@ -54,8 +44,8 @@ public class TomlReader { /** * Creates a new TomlReader. * - * @param data the TOML data to read - * @param strictAsciiBareKeys true to allow only strict bare keys, {@code false} to allow lenient ones. + * @param data the TOML data to read + * @param strictAsciiBareKeys {@code true} to allow only strict bare keys, {@code false} to allow lenient ones. */ public TomlReader(final String data, final boolean strictAsciiBareKeys) { this.data = data; @@ -155,6 +145,7 @@ public class TomlReader { } } + @SuppressWarnings("unchecked") public Map read() { final Map map = nextTableContent(); @@ -249,16 +240,16 @@ public class TomlReader { childMap = new HashMap<>(4); valueMap.put(part, childMap); } else if (child instanceof Map) {// table - childMap = (Map) child; + childMap = (Map) child; } else {// array - final List list = (List) child; + final List> list = (List>) child; childMap = list.get(list.size() - 1); } valueMap = childMap; } if (twoBrackets) {// element of a table array final String name = keyParts.get(keyParts.size() - 1); - Collection tableArray = (Collection) valueMap.get(name); + Collection> tableArray = (Collection>) valueMap.get(name); if (tableArray == null) { tableArray = new ArrayList<>(2); valueMap.put(name, tableArray); @@ -272,7 +263,7 @@ public class TomlReader { return map; } - private List nextArray() { + private List nextArray() { final ArrayList list = new ArrayList<>(); while (true) { final char c = nextUseful(true); @@ -430,7 +421,8 @@ public class TomlReader { final StringBuilder sb = new StringBuilder(); sb.append(first); char c; - whileLoop: while (hasNext()) { + whileLoop: + while (hasNext()) { c = next(); switch (c) { case ':': @@ -504,7 +496,7 @@ public class TomlReader { } // else continue reading } throw new SettingException( - "Invalid key/value pair at line " + line + " end of data reached before the value attached to the key was found"); + "Invalid key/value pair at line " + line + " end of data reached before the value attached to the key was found"); } private String nextLiteralString() {