RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
PathUtil.java
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5package org.wpilib.telemetry.util;
6
8public final class PathUtil {
9 private PathUtil() {
10 throw new UnsupportedOperationException("This is a utility class!");
11 }
12
20 public static String normalizeTableName(String path) {
21 path = normalizeName(path);
22 if (path.charAt(path.length() - 1) != '/') {
23 path = path + '/';
24 }
25 return path;
26 }
27
36 public static String normalizeBackendPrefix(String prefix) {
37 if (prefix.isEmpty()) {
38 return "";
39 }
40 String normalized = normalizeName(prefix);
41 while (normalized.length() > 1 && normalized.endsWith("/")) {
42 normalized = normalized.substring(0, normalized.length() - 1);
43 }
44 return normalized;
45 }
46
53 public static String normalizeName(String path) {
54 if (!path.isEmpty() && path.charAt(0) == '/' && !path.contains("//")) {
55 return path;
56 }
57
58 StringBuilder normalized = new StringBuilder(path.length() + 1);
59 if (path.isEmpty() || path.charAt(0) != '/') {
60 normalized.append('/');
61 }
62 char previousChar = '\0';
63 for (int i = 0; i < path.length(); i++) {
64 char ch = path.charAt(i);
65 if (ch != '/' || previousChar != '/') {
66 normalized.append(ch);
67 }
68 previousChar = ch;
69 }
70 return normalized.toString();
71 }
72
82 public static boolean isPathOrDescendant(String path, String root) {
83 if (root.isEmpty() || "/".equals(root) || path.equals(root)) {
84 return true;
85 }
86 if (root.endsWith("/")) {
87 return path.startsWith(root);
88 }
89 return path.length() > root.length()
90 && path.startsWith(root)
91 && path.charAt(root.length()) == '/';
92 }
93}
static boolean isPathOrDescendant(String path, String root)
Definition PathUtil.java:82
static String normalizeBackendPrefix(String prefix)
Definition PathUtil.java:36
static String normalizeTableName(String path)
Definition PathUtil.java:20
static String normalizeName(String path)
Definition PathUtil.java:53