Skip to content

Commit 5fea7ce

Browse files
committed
Use Pattern to match list fields selector
1 parent 1583e2c commit 5fea7ce

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/testing/LocalResourceManagerHelper.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import java.util.concurrent.ConcurrentSkipListMap;
3838
import java.util.logging.Level;
3939
import java.util.logging.Logger;
40+
import java.util.regex.Matcher;
41+
import java.util.regex.Pattern;
4042
import java.util.zip.GZIPInputStream;
4143

4244
/**
@@ -56,6 +58,8 @@ public class LocalResourceManagerHelper {
5658
private static final URI BASE_CONTEXT;
5759
private static final Set<String> SUPPORTED_COMPRESSION_ENCODINGS =
5860
ImmutableSet.of("gzip", "x-gzip");
61+
private static final Pattern LIST_FIELDS_PATTERN =
62+
Pattern.compile("(.*?)projects\\((.*?)\\)(.*?)");
5963

6064
static {
6165
try {
@@ -237,17 +241,11 @@ private static Map<String, Object> parseListOptions(String query) throws IOExcep
237241
switch (argEntry[0]) {
238242
case "fields":
239243
// List fields are in the form "projects(field1, field2, ...),nextPageToken"
240-
String option = argEntry[1];
241-
int projectStart = option.indexOf("projects(");
242-
int projectEnd = option.indexOf(')');
243-
if (projectStart != -1 && projectEnd != -1
244-
&& projectEnd > projectStart + "projects(".length()) {
245-
String projectFields =
246-
option.substring(projectStart + "projects(".length(), projectEnd);
247-
options.put("projectFields", projectFields.split(","));
248-
option = option.replace(option.substring(projectStart, projectEnd), "");
244+
Matcher matcher = LIST_FIELDS_PATTERN.matcher(argEntry[1]);
245+
if (matcher.matches()) {
246+
options.put("projectFields", matcher.group(2).split(","));
247+
options.put("listFields", (matcher.group(1) + matcher.group(3)).split(","));
249248
}
250-
options.put("listFields", option.split(","));
251249
break;
252250
case "filter":
253251
options.put("filter", argEntry[1].split(" "));

0 commit comments

Comments
 (0)