RobotCore
1.0
WPILib port to raspberry Pi
Toggle main menu visibility
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
5
package
org.wpilib.tunable.util;
6
8
public
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
56
public
static
String
normalizePrefix
(String prefix) {
57
return
prefix.isEmpty() ?
""
:
normalizeName
(prefix);
58
}
59
66
public
static
String
childTablePath
(String path) {
67
if
(path.isEmpty() || path.charAt(path.length() - 1) !=
'/'
) {
68
return
path +
'/'
;
69
}
70
return
path;
71
}
72
79
public
static
String
normalizeChildName
(String name) {
80
String normalized =
normalizeName
(name);
81
if
(!normalized.isEmpty() && normalized.charAt(0) ==
'/'
) {
82
return
normalized.substring(1);
83
}
84
return
normalized;
85
}
86
93
public
static
String
normalizeName
(String path) {
94
if
(!path.isEmpty() && path.charAt(0) ==
'/'
&& !path.contains(
"//"
)) {
95
return
path;
96
}
97
98
StringBuilder normalized =
new
StringBuilder(path.length() + 1);
99
if
(path.isEmpty() || path.charAt(0) !=
'/'
) {
100
normalized.append(
'/'
);
101
}
102
char
previousChar =
'\0'
;
103
for
(
int
i = 0; i < path.length(); i++) {
104
char
ch = path.charAt(i);
105
if
(ch !=
'/'
|| previousChar !=
'/'
) {
106
normalized.append(ch);
107
}
108
previousChar = ch;
109
}
110
return
normalized.toString();
111
}
112
122
public
static
boolean
isPathOrDescendant
(String path, String root) {
123
if
(root.isEmpty() ||
"/"
.equals(root) || path.equals(root)) {
124
return
true
;
125
}
126
if
(root.endsWith(
"/"
)) {
127
return
path.startsWith(root);
128
}
129
return
path.length() > root.length()
130
&& path.startsWith(root)
131
&& path.charAt(root.length()) ==
'/'
;
132
}
133
}
org.wpilib.tunable.util.PathUtil.childTablePath
static String childTablePath(String path)
Definition
PathUtil.java:66
org.wpilib.tunable.util.PathUtil.isPathOrDescendant
static boolean isPathOrDescendant(String path, String root)
Definition
PathUtil.java:122
org.wpilib.tunable.util.PathUtil.normalizeBackendPrefix
static String normalizeBackendPrefix(String prefix)
Definition
PathUtil.java:36
org.wpilib.tunable.util.PathUtil.normalizeName
static String normalizeName(String path)
Definition
PathUtil.java:93
org.wpilib.tunable.util.PathUtil.normalizeTableName
static String normalizeTableName(String path)
Definition
PathUtil.java:20
org.wpilib.tunable.util.PathUtil.normalizeChildName
static String normalizeChildName(String name)
Definition
PathUtil.java:79
org.wpilib.tunable.util.PathUtil.normalizePrefix
static String normalizePrefix(String prefix)
Definition
PathUtil.java:56
org
wpilib
tunable
util
PathUtil.java
Generated by
1.18.0