MetaUtils { public static String[] splitPathToDetachedPath(String path) throws IllegalPathException { List<String> nodes = new ArrayList<>(); int startIndex = 0; for (int i = 0; i < path.length(); i++) { if (path.charAt(i) == IoTDBConstant.PATH_SEPARATOR) { nodes.add(path.substring(startIndex, i)); startIndex = i + 1; } else if (path.charAt(i) == '"') { int endIndex = path.indexOf('"', i + 1); while (endIndex != -1 && path.charAt(endIndex - 1) == '\\') { endIndex = path.indexOf('"', endIndex + 1); } if (endIndex != -1 && (endIndex == path.length() - 1 || path.charAt(endIndex + 1) == '.')) { nodes.add(path.substring(startIndex, endIndex + 1)); i = endIndex + 1; startIndex = endIndex + 2; } else { throw new IllegalPathException("Illegal path: " + path); } } else if (path.charAt(i) == '\'') { throw new IllegalPathException("Illegal path with single quote: " + path); } } if (startIndex <= path.length() - 1) { nodes.add(path.substring(startIndex)); } return nodes.toArray(new String[0]); } private  MetaUtils(); static String[] splitPathToDetachedPath(String path);  }
@Test public void testSplitPathToNodes() throws IllegalPathException { assertEquals(Arrays.asList("root", "sg", "d1", "s1").toArray(), MetaUtils.splitPathToDetachedPath("root.sg.d1.s1")); assertEquals(Arrays.asList("root", "sg", "d1", "\"s.1\"").toArray(), MetaUtils.splitPathToDetachedPath("root.sg.d1.\"s.1\"")); assertEquals(Arrays.asList("root", "sg", "d1", "\"s\\\".1\"").toArray(), MetaUtils.splitPathToDetachedPath("root.sg.d1.\"s\\\".1\"")); assertEquals(Arrays.asList("root", "\"s g\"", "d1", "\"s.1\"").toArray(), MetaUtils.splitPathToDetachedPath("root.\"s g\".d1.\"s.1\"")); assertEquals(Arrays.asList("root", "\"s g\"", "\"d_.1\"", "\"s.1.1\"").toArray(), MetaUtils.splitPathToDetachedPath("root.\"s g\".\"d_.1\".\"s.1.1\"")); assertEquals(Arrays.asList("root", "1").toArray(), MetaUtils.splitPathToDetachedPath("root.1")); assertEquals(Arrays.asList("root", "sg", "d1", "s", "1").toArray(), MetaUtils.splitPathToDetachedPath("root.sg.d1.s.1")); try { MetaUtils.splitPathToDetachedPath("root.sg.\"d.1\"\"s.1\""); } catch (IllegalPathException e) { Assert.assertTrue(e.getMessage().contains("Illegal path: ")); } try { MetaUtils.splitPathToDetachedPath("root.sg.d1.\'s1\'"); } catch (IllegalPathException e) { Assert.assertTrue(e.getMessage().contains("Illegal path with single quote: ")); } }