Code example for CharMatcher

Methods: trimFrom

0
  @VisibleForTesting 
  static PythonVersion extractPythonVersion( 
      Path pythonPath,
      ProcessExecutor.Result versionResult) {
    if (versionResult.getExitCode() == 0) {
      String versionString = CharMatcher.WHITESPACE.trimFrom(versionResult.getStderr().get());
      Matcher matcher = PYTHON_VERSION_REGEX.matcher(versionString);
      if (!matcher.matches()) {
        throw new HumanReadableException( 
            "`%s --version` returned an invalid version string %s", 
            pythonPath,
            versionString);
      } 
      return new PythonVersion(matcher.group(1));
    } else { 
      throw new HumanReadableException(versionResult.getStderr().get());
    } 
  } 
}