MCPcopy
hub / github.com/google/guava / tryParse

Method tryParse

guava/src/com/google/common/primitives/Floats.java:722–735  ·  view source on GitHub ↗

Parses the specified string as a single-precision floating point value. The ASCII character {@code '-'} (<code>'&#92;u002D'</code>) is recognized as the minus sign. <p>Unlike {@link Float#parseFloat(String)}, this method returns {@code null} instead of throwing an exception if parsing fails. Valid

(String string)

Source from the content-addressed store, hash-verified

720 * @since 14.0
721 */
722 @GwtIncompatible // regular expressions
723 public static @Nullable Float tryParse(String string) {
724 if (Doubles.FLOATING_POINT_PATTERN.matcher(string).matches()) {
725 // TODO(lowasser): could be potentially optimized, but only with
726 // extensive testing
727 try {
728 return parseFloat(string);
729 } catch (NumberFormatException e) {
730 // Float.parseFloat has changed specs several times, so fall through
731 // gracefully
732 }
733 }
734 return null;
735 }
736}

Callers 3

checkTryParseMethod · 0.95
testTryParseFailuresMethod · 0.95

Calls 2

matchesMethod · 0.45
matcherMethod · 0.45

Tested by 3

checkTryParseMethod · 0.76
testTryParseFailuresMethod · 0.76