MCPcopy Create free account
hub / github.com/apache/fory / _numeric_literal_fits

Function _numeric_literal_fits

python/pyfory/converter.py:82–146  ·  view source on GitHub ↗
(value: str)

Source from the content-addressed store, hash-verified

80
81
82def _numeric_literal_fits(value: str) -> bool:
83 if not value or len(value) > _MAX_COMPATIBLE_NUMERIC_TEXT_LENGTH:
84 return False
85 index = 0
86 if value[index] == "-":
87 index += 1
88 if index == len(value):
89 return False
90
91 significant_digits = 0
92 seen_nonzero = False
93 if value[index] == "0":
94 index += 1
95 if index < len(value) and _is_digit(value[index]):
96 return False
97 elif "1" <= value[index] <= "9":
98 while index < len(value) and _is_digit(value[index]):
99 if value[index] != "0" or seen_nonzero:
100 seen_nonzero = True
101 significant_digits += 1
102 index += 1
103 else:
104 return False
105
106 fractional_digits = 0
107 if index < len(value) and value[index] == ".":
108 index += 1
109 fraction_start = index
110 while index < len(value) and _is_digit(value[index]):
111 if value[index] != "0" or seen_nonzero:
112 seen_nonzero = True
113 significant_digits += 1
114 fractional_digits += 1
115 index += 1
116 if index == fraction_start:
117 return False
118
119 exponent = 0
120 if index < len(value) and value[index] in ("e", "E"):
121 index += 1
122 exponent_negative = False
123 if index < len(value) and value[index] == "-":
124 exponent_negative = True
125 index += 1
126 if index == len(value):
127 return False
128 if value[index] == "0":
129 index += 1
130 if index < len(value) and _is_digit(value[index]):
131 return False
132 elif "1" <= value[index] <= "9":
133 while index < len(value) and _is_digit(value[index]):
134 exponent = exponent * 10 + ord(value[index]) - ord("0")
135 if exponent > _MAX_COMPATIBLE_DECIMAL_DIGITS:
136 return False
137 index += 1
138 else:
139 return False

Callers 1

_decimal_from_textFunction · 0.85

Calls 2

_is_digitFunction · 0.85
_decimal_shape_fitsFunction · 0.85

Tested by

no test coverage detected