| /* |
| * Copyright (C) 2016 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| package com.google.devrel.cluestick.studioclient; |
| |
| import org.jetbrains.annotations.Nullable; |
| |
| /** |
| * Result utility library for the Cluestick IntelliJ plugin. This is intentionally package-private. |
| */ |
| class ResultUtils { |
| |
| /** |
| * Value type for a GitHub repo. |
| */ |
| public static class GitHubInfo { |
| public final String user; |
| public final String repo; |
| |
| public GitHubInfo(String user, String repo) { |
| this.user = user; |
| this.repo = repo; |
| } |
| } |
| |
| private ResultUtils() {} |
| |
| /** |
| * Gets the basename of this path (e.g. foo/bar/bing.foo => bing.foo). |
| * @param path The entire input path. |
| * @return The basename of this path. |
| */ |
| public static String getBaseName(@Nullable String path) { |
| if (path != null) { |
| int index = path.lastIndexOf('/'); |
| if (index >= 0) { |
| return path.substring(index + 1); |
| } |
| } |
| return path; |
| } |
| |
| /** |
| * Builds a GitHubInfo pair from a raw source name, if possible. |
| * @param repo The raw source name. |
| * @return The possibly parsed GitHubInfo. |
| */ |
| public static GitHubInfo parseRepoName(@Nullable String repo) { |
| if (repo == null) { |
| return null; |
| } |
| String[] repoBits = repo.replace("github.com/", "").split("/"); |
| if (repoBits.length >= 2) { |
| return new GitHubInfo(repoBits[0], repoBits[1]); |
| } |
| return null; |
| } |
| |
| public static String escapeHTML(String raw) { |
| return raw.replace("&", "&").replace(">", ">").replace("<", "<"); |
| } |
| |
| } |