code: public static int estimatedBinaryLengthAsUTF8(String value)
    {
      int length = 0;
      for (int i = 0; i < value.length(); i++) {
        char var10 = value.charAt(i);
        if (var10 < 0x80) {
          length += 1;
        } else if (var10 < 0x800) {
          length += 2;
        } else if (Character.isSurrogate(var10)) {
          length += 4;
          i++;
        } else {
          length += 3;
        }
      }
      return length;
    }
docs: does not check validity of format and returns over-estimated result for invalid string (see UT)