MCPcopy Create free account
hub / github.com/questdb/questdb / splitLpsz

Method splitLpsz

core/src/main/java/io/questdb/std/Chars.java:1207–1246  ·  view source on GitHub ↗

Split character sequence into a list of lpsz strings. This function uses space as a delimiter and it honours spaces in double quotes. Main use for this code is to produce list of C-compatible argument values from command line. @param args command line @return list of 0-terminated strings

(CharSequence args)

Source from the content-addressed store, hash-verified

1205 * @return list of 0-terminated strings
1206 */
1207 @SuppressWarnings("resource")
1208 public static ObjList<Path> splitLpsz(CharSequence args) {
1209 final ObjList<Path> paths = new ObjList<>();
1210 int n = args.length();
1211 int lastLen = 0;
1212 int lastIndex = 0;
1213 boolean inQuote = false;
1214 for (int i = 0; i < n; i++) {
1215 char b = args.charAt(i);
1216
1217 switch (b) {
1218 case ' ':
1219 // ab c
1220 if (lastLen > 0) {
1221 if (inQuote) {
1222 lastLen++;
1223 } else {
1224 paths.add(new Path().of(args, lastIndex, lastLen + lastIndex));
1225 lastLen = 0;
1226 }
1227 }
1228 break;
1229 case '"':
1230 inQuote = !inQuote;
1231 break;
1232 default:
1233 if (lastLen == 0) {
1234 lastIndex = i;
1235 }
1236 lastLen++;
1237 break;
1238
1239 }
1240 }
1241
1242 if (lastLen > 0) {
1243 paths.add(new Path().of(args, lastIndex, lastLen + lastIndex));
1244 }
1245 return paths;
1246 }
1247
1248 public static boolean startsWith(@Nullable CharSequence cs, @Nullable CharSequence starts) {
1249 if (cs == null || starts == null) {

Callers 7

testPathListMethod · 0.95
forkExecMethod · 0.95

Calls 4

addMethod · 0.95
lengthMethod · 0.65
ofMethod · 0.65
charAtMethod · 0.45

Tested by 6

testPathListMethod · 0.76