public static Color parseColor()

in util/values/src/main/java/jetbrains/jetpad/values/Color.java [48:80]


  public static Color parseColor(String text) {
    int firstParen = findNext(text, "(", 0);
    String prefix = text.substring(0, firstParen);

    int firstComma = findNext(text, ",", firstParen + 1);
    int secondComma = findNext(text, ",", firstComma + 1);

    int thirdComma = -1;

    if (prefix.equals(RGBA)) {
      thirdComma = findNext(text, ",", secondComma + 1);
    } else if (prefix.equals(COLOR)) {
      thirdComma = text.indexOf(",", secondComma + 1);
    } else if (!prefix.equals(RGB)) {
      throw new IllegalArgumentException();
    }

    int lastParen = findNext(text, ")", thirdComma + 1);
    int red = Integer.parseInt(text.substring(firstParen + 1, firstComma).trim());
    int green = Integer.parseInt(text.substring(firstComma + 1, secondComma).trim());

    int blue;
    int alpha;
    if (thirdComma == -1) {
      blue = Integer.parseInt(text.substring(secondComma + 1, lastParen).trim());
      alpha = 255;
    } else {
      blue = Integer.parseInt(text.substring(secondComma + 1, thirdComma).trim());
      alpha = Integer.parseInt(text.substring(thirdComma + 1, lastParen).trim());
    }

    return new Color(red, green, blue, alpha);
  }