def _read_float(self, reader): start = reader.get_cursor() result = "" while reader.can_read(): char = reader.peek() if char == ".": reader.skip() if reader.can_read() and reader.peek() == ".": break result += char elif char.isdigit() or char == "+" or char == "-": reader.skip() result += char else: break if not result: raise BuiltInExceptions.reader_expected_float( ).create_with_context(reader) # Verify result is a valid float try: return float(result) except ValueError: reader.set_cursor(start) raise BuiltInExceptions.reader_invalid_float().create_with_context( reader, result)
def read_float(self): start = self.cursor while self.can_read() and self.is_allowed_number(self.peek()): self.skip() number = self.string[start:self.cursor] if not number: raise BuiltInExceptions.reader_expected_float().create_with_context(self) try: return float(number) except ValueError: self.cursor = start raise BuiltInExceptions.reader_invalid_float().create_with_context(self, number)