Delete unused/unnecessary StringUtilities methods

Some were only used in StringUtilities tests, others were trivial to inline.
Several of the remaining are trivial and only used in tests, something that can
be cleaned up separately.

PiperOrigin-RevId: 393135659
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BUILD b/src/main/java/com/google/devtools/build/lib/analysis/BUILD
index 3e7d5c7..dfdd843 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BUILD
@@ -549,7 +549,6 @@
     name = "blaze_version_info",
     srcs = ["BlazeVersionInfo.java"],
     deps = [
-        "//src/main/java/com/google/devtools/build/lib/util:string",
         "//third_party:flogger",
         "//third_party:guava",
     ],
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BlazeVersionInfo.java b/src/main/java/com/google/devtools/build/lib/analysis/BlazeVersionInfo.java
index 0024b85..5e9e05c 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BlazeVersionInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BlazeVersionInfo.java
@@ -17,9 +17,9 @@
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 import com.google.common.flogger.GoogleLogger;
-import com.google.devtools.build.lib.util.StringUtilities;
 import java.util.Date;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * Determines the version information of the current process.
@@ -94,7 +94,9 @@
     if (buildData.isEmpty()) {
       return null;
     }
-    return StringUtilities.layoutTable(buildData);
+    return buildData.entrySet().stream()
+        .map(e -> e.getKey() + ": " + e.getValue())
+        .collect(Collectors.joining("\n"));
   }
 
   /**
diff --git a/src/main/java/com/google/devtools/build/lib/util/StringUtilities.java b/src/main/java/com/google/devtools/build/lib/util/StringUtilities.java
index c811c5f..d7eb908 100644
--- a/src/main/java/com/google/devtools/build/lib/util/StringUtilities.java
+++ b/src/main/java/com/google/devtools/build/lib/util/StringUtilities.java
@@ -14,14 +14,9 @@
 package com.google.devtools.build.lib.util;
 
 import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableList;
 import com.google.common.escape.CharEscaperBuilder;
 import com.google.common.escape.Escaper;
-
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
-import java.util.Map;
 
 /**
  * Various utility methods operating on strings.
@@ -30,18 +25,14 @@
 
   private static final Joiner NEWLINE_JOINER = Joiner.on('\n');
 
-  private static final Escaper KEY_ESCAPER = new CharEscaperBuilder()
-      .addEscape('!', "!!")
-      .addEscape('<', "!<")
-      .addEscape('>', "!>")
-      .toEscaper();
-
   private static final Escaper CONTROL_CHAR_ESCAPER = new CharEscaperBuilder()
       .addEscape('\r', "\\r")
       .addEscapes(new char[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, /*13=\r*/
           14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 127}, "<?>")
       .toEscaper();
 
+  private StringUtilities() {}
+
   /**
    * Java doesn't have multiline string literals, so having to join a bunch
    * of lines is a very common problem. So, here's a static method that we
@@ -59,39 +50,6 @@
   }
 
   /**
-   * combineKeys(x1, ..., xn):
-   *   Computes a string that encodes the sequence
-   *   x1, ..., xn.  Distinct sequences map to distinct strings.
-   *
-   *   The encoding is intended to be vaguely human-readable.
-   */
-  public static String combineKeys(Iterable<String> parts) {
-    final StringBuilder buf = new StringBuilder(128);
-    for (String part : parts) {
-      // We enclose each part in angle brackets to separate them.  Some
-      // trickiness is required to ensure that the result is unique (distinct
-      // sequences map to distinct strings): we escape any angle bracket
-      // characters in the parts by preceding them with an escape character
-      // (we use "!") and we also need to escape any escape characters.
-      buf.append('<');
-      buf.append(KEY_ESCAPER.escape(part));
-      buf.append('>');
-    }
-    return buf.toString();
-  }
-
-  /**
-   * combineKeys(x1, ..., xn):
-   *   Computes a string that encodes the sequence
-   *   x1, ..., xn.  Distinct sequences map to distinct strings.
-   *
-   *   The encoding is intended to be vaguely human-readable.
-   */
-  public static String combineKeys(String... parts) {
-    return combineKeys(ImmutableList.copyOf(parts));
-  }
-
-  /**
    * Replaces all occurrences of 'literal' in 'input' with 'replacement'.
    * Like {@link String#replaceAll(String, String)} but for literal Strings
    * instead of regular expression patterns.
@@ -123,25 +81,6 @@
   }
 
   /**
-   * Creates a simple key-value table of the form
-   *
-   * <pre>
-   * key: some value
-   * another key: some other value
-   * yet another key: and so on ...
-   * </pre>
-   *
-   * The return value will not include a final {@code "\n"}.
-   */
-  public static String layoutTable(Map<String, String> data) {
-    List<String> tableLines = new ArrayList<>();
-    for (Map.Entry<String, String> entry : data.entrySet()) {
-      tableLines.add(entry.getKey() + ": " + entry.getValue());
-    }
-    return NEWLINE_JOINER.join(tableLines);
-  }
-
-  /**
    * Returns an easy-to-read string approximation of a number of bytes,
    * e.g. "21MB".  Note, these are IEEE units, i.e. decimal not binary powers.
    */
@@ -158,50 +97,10 @@
   }
 
   /**
-   * Returns true if 'source' contains 'target' as a sub-array.
-   */
-  public static boolean containsSubarray(char[] source, char[] target) {
-    if (target.length > source.length) {
-      return false;
-    }
-    for (int i = 0; i < source.length - target.length + 1; i++) {
-      boolean matches = true;
-      for (int j = 0; j < target.length; j++) {
-        if (source[i + j] != target[j]) {
-          matches = false;
-          break;
-        }
-      }
-      if (matches) {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  /**
    * Replace control characters with visible strings.
    * @return the sanitized string.
    */
   public static String sanitizeControlChars(String message) {
     return CONTROL_CHAR_ESCAPER.escape(message);
   }
-
-  /**
-   * Converts a Java style function name to a Python style function name the following way:
-   * every upper case character gets replaced with an underscore and its lower case counterpart.
-   * <p>E.g. fooBar --> foo_bar 
-   */
-  public static String toPythonStyleFunctionName(String javaStyleFunctionName) {
-    StringBuilder sb = new StringBuilder();
-    for (int i = 0; i < javaStyleFunctionName.length(); i++) {
-      char c = javaStyleFunctionName.charAt(i);
-      if (Character.isUpperCase(c)) {
-        sb.append('_').append(Character.toLowerCase(c));
-      } else {
-        sb.append(c);
-      }
-    }
-    return sb.toString();
-  }
 }
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/BlazeVersionInfoTest.java b/src/test/java/com/google/devtools/build/lib/runtime/BlazeVersionInfoTest.java
index 3a9b722..7ad80b0 100644
--- a/src/test/java/com/google/devtools/build/lib/runtime/BlazeVersionInfoTest.java
+++ b/src/test/java/com/google/devtools/build/lib/runtime/BlazeVersionInfoTest.java
@@ -18,11 +18,8 @@
 
 import com.google.common.collect.ImmutableMap;
 import com.google.devtools.build.lib.analysis.BlazeVersionInfo;
-import com.google.devtools.build.lib.util.StringUtilities;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
-import java.util.TreeMap;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
@@ -56,14 +53,12 @@
   }
 
   @Test
-  public void testFancySummaryFormatting() {
-    Map<String, String> data = new HashMap<>();
-    data.put("Some entry", "foo");
-    data.put("Another entry", "bar");
-    data.put("And a third entry", "baz");
+  public void testGetSummaryReturnsOrderedTablifiedData() {
+    ImmutableMap<String, String> data =
+        ImmutableMap.of("key3", "foo", "key2", "bar", "key1", "baz");
+
     BlazeVersionInfo info = new BlazeVersionInfo(data);
-    Map<String, String> sortedData = new TreeMap<>(data);
-    assertThat(info.getSummary()).isEqualTo(StringUtilities.layoutTable(sortedData));
+    assertThat(info.getSummary()).isEqualTo("key1: baz\nkey2: bar\nkey3: foo");
   }
 
   @Test
diff --git a/src/test/java/com/google/devtools/build/lib/util/StringUtilitiesTest.java b/src/test/java/com/google/devtools/build/lib/util/StringUtilitiesTest.java
index 519f35d..e7a65dd 100644
--- a/src/test/java/com/google/devtools/build/lib/util/StringUtilitiesTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/StringUtilitiesTest.java
@@ -14,16 +14,9 @@
 package com.google.devtools.build.lib.util;
 
 import static com.google.common.truth.Truth.assertThat;
-import static com.google.devtools.build.lib.util.StringUtilities.combineKeys;
 import static com.google.devtools.build.lib.util.StringUtilities.joinLines;
-import static com.google.devtools.build.lib.util.StringUtilities.layoutTable;
 import static com.google.devtools.build.lib.util.StringUtilities.prettyPrintBytes;
-import static org.junit.Assert.fail;
 
-import com.google.common.collect.Maps;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
@@ -32,8 +25,6 @@
 @RunWith(JUnit4.class)
 public class StringUtilitiesTest {
 
-  // Tests of StringUtilities.joinLines()
-
   @Test
   public void emptyLinesYieldsEmptyString() {
     assertThat(joinLines()).isEmpty();
@@ -50,65 +41,6 @@
         .isEqualTo("two lines\nwith trailing newline\n");
   }
 
-  // Tests of StringUtilities.combineKeys()
-
-  /** Simple test of format */
-  @Test
-  public void combineKeysFormat() {
-    assertThat(combineKeys("a", "b!c", "<d>")).isEqualTo("<a><b!!c><!<d!>>");
-  }
-
-  /**
-   * Test that combining different keys gives different results,
-   * i.e. that there are no collisions.
-   * We test all combinations of up to 3 keys from the test_keys
-   * array (defined below).
-   */
-  @Test
-  public void testCombineKeys() {
-    // This map is really just used as a set, but
-    // if the test fails, the values in the map may be
-    // useful for debugging.
-    Map<String,String[]> map = new HashMap<>();
-    for (int numKeys = 0; numKeys <= 3; numKeys++) {
-      testCombineKeys(map, numKeys, new String[numKeys]);
-    }
-  }
-
-  private void testCombineKeys(Map<String,String[]> map,
-        int n, String[] keys) {
-    if (n == 0) {
-      String[] keys_copy = keys.clone();
-      String combined_key = combineKeys(keys_copy);
-      String[] prev_keys = map.put(combined_key, keys_copy);
-      if (prev_keys != null) {
-        fail("combineKeys collision:\n"
-            + "key sequence 1: " + Arrays.toString(prev_keys) + "\n"
-            + "key sequence 2: " + Arrays.toString(keys_copy) + "\n"
-            + "combined key sequence 1: " + combineKeys(prev_keys) + "\n"
-            + "combined key sequence 2: " + combineKeys(keys_copy) + "\n");
-      }
-    } else {
-      for (String key : test_keys) {
-        keys[n - 1] = key;
-        testCombineKeys(map, n - 1, keys);
-      }
-    }
-  }
-
-  private static final String[] test_keys = {
-        // ordinary strings
-        "", "a", "word", "//depot/foo/bar",
-        // likely delimiter characters
-        " ", ",", "\\", "\"", "\'", "\0", "\u00ff",
-        // strings starting in special delimiter
-        " foo", ",foo", "\\foo", "\"foo", "\'foo", "\0foo", "\u00fffoo",
-        // strings ending in special delimiter
-        "bar ", "bar,", "bar\\", "bar\"", "bar\'", "bar\0", "bar\u00ff",
-        // white-box testing of the delimiters that combineKeys() uses
-        "<", ">", "!", "!<", "!>", "!!", "<!", ">!"
-  };
-
   @Test
   public void replaceAllLiteral() throws Exception {
     assertThat(StringUtilities.replaceAllLiteral("bababa", "ba", "ab")).isEqualTo("ababab");
@@ -117,17 +49,6 @@
   }
 
   @Test
-  public void testLayoutTable() throws Exception {
-    Map<String, String> data = Maps.newTreeMap();
-    data.put("foo", "bar");
-    data.put("bang", "baz");
-    data.put("lengthy key", "lengthy value");
-
-    assertThat(layoutTable(data))
-        .isEqualTo(joinLines("bang: baz", "foo: bar", "lengthy key: lengthy value"));
-  }
-
-  @Test
   public void testPrettyPrintBytes() {
     String[] expected = {
       "2B",
@@ -159,33 +80,4 @@
     assertThat(StringUtilities.sanitizeControlChars("\r")).isEqualTo("\\r");
     assertThat(StringUtilities.sanitizeControlChars(" abc123")).isEqualTo(" abc123");
   }
-
-  @Test
-  public void containsSubarray() {
-    assertThat(StringUtilities.containsSubarray("abcde".toCharArray(), "ab".toCharArray()))
-        .isTrue();
-    assertThat(StringUtilities.containsSubarray("abcde".toCharArray(), "de".toCharArray()))
-        .isTrue();
-    assertThat(StringUtilities.containsSubarray("abcde".toCharArray(), "bc".toCharArray()))
-        .isTrue();
-    assertThat(StringUtilities.containsSubarray("abcde".toCharArray(), "".toCharArray())).isTrue();
-  }
-
-  @Test
-  public void notContainsSubarray() {
-    assertThat(StringUtilities.containsSubarray("abc".toCharArray(), "abcd".toCharArray()))
-        .isFalse();
-    assertThat(StringUtilities.containsSubarray("abc".toCharArray(), "def".toCharArray()))
-        .isFalse();
-    assertThat(StringUtilities.containsSubarray("abcde".toCharArray(), "bd".toCharArray()))
-        .isFalse();
-  }
-
-  @Test
-  public void toPythonStyleFunctionName() {
-    assertThat(StringUtilities.toPythonStyleFunctionName("a")).isEqualTo("a");
-    assertThat(StringUtilities.toPythonStyleFunctionName("aB")).isEqualTo("a_b");
-    assertThat(StringUtilities.toPythonStyleFunctionName("aBC")).isEqualTo("a_b_c");
-    assertThat(StringUtilities.toPythonStyleFunctionName("aBcD")).isEqualTo("a_bc_d");
-  }
 }