-
-
Notifications
You must be signed in to change notification settings - Fork 441
Expand file tree
/
Copy pathUtils.java
More file actions
124 lines (106 loc) · 3.22 KB
/
Copy pathUtils.java
File metadata and controls
124 lines (106 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package app.f3d.F3D;
import java.util.List;
public class Utils {
/**
* Enumeration of supported Windows known folders.
*/
public enum KnownFolder {
ROAMINGAPPDATA(0),
LOCALAPPDATA(1),
PICTURES(2);
private final int value;
KnownFolder(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public static KnownFolder fromValue(int value) {
for (KnownFolder folder : KnownFolder.values()) {
if (folder.value == value) {
return folder;
}
}
throw new IllegalArgumentException("Invalid KnownFolder value: " + value);
}
}
// Load the native library
static {
System.loadLibrary("f3d-java");
}
private Utils() {
}
/**
* Compute the Levenshtein distance between two strings.
*
* @param strA first string
* @param strB second string
* @return Levenshtein distance between the two strings
*/
public static native int textDistance(String strA, String strB);
/**
* Tokenize a string using the same logic as bash.
*
* @param str input string to tokenize
* @param keepComments if true, keep comments with '#'
* @return list of tokens
*/
public static native List<String> tokenize(String str, boolean keepComments);
/**
* Tokenize a string with keepComments enabled.
*
* @param str input string to tokenize
* @return list of tokens
*/
public static List<String> tokenize(String str) {
return tokenize(str, true);
}
/**
* Collapse a filesystem path.
*
* @param path input path
* @param baseDirectory base directory for relative paths
* @return collapsed absolute path string
*/
public static native String collapsePath(String path, String baseDirectory);
/**
* Collapse a filesystem path using current directory as base.
*
* @param path input path
* @return collapsed absolute path string
*/
public static String collapsePath(String path) {
return collapsePath(path, "");
}
/**
* Converts a glob expression to a regular expression.
*
* @param glob glob expression
* @param pathSeparator path separator character
* @return regular expression string
*/
public static native String globToRegex(String glob, char pathSeparator);
/**
* Converts a glob expression to a regular expression with default separator '/'.
*
* @param glob glob expression
* @return regular expression string
*/
public static String globToRegex(String glob) {
return globToRegex(glob, '/');
}
/**
* Get the value of an environment variable.
*
* @param env environment variable name
* @return value of the environment variable, or null if not set
*/
public static native String getEnv(String env);
/**
* Get a Windows known folder.
*
* @param knownFolder known folder identifier
* @return folder path, or null on non-Windows platforms or error
*/
public static native String getKnownFolder(KnownFolder knownFolder);
}