Function TkbmMWJSONStreamer.ExpectNumber doesn’t work with exp floating values

Home Forums kbmMW Function TkbmMWJSONStreamer.ExpectNumber doesn’t work with exp floating values

Tagged: 

Viewing 1 reply thread
  • Author
    Posts
    • #57130
      VadimMest
      Participant

      Hi

      Function shows error during the parsing float values with exp values (like  1.2E+7 or 1.2E-8)

      I think this function needs to be changed

      function TkbmMWJSONStreamer.ExpectNumber(var AIsInteger:boolean):double;
      var
      sb:TkbmMWStringBuilder;
      bDot:boolean;
      bExp:boolean;
      begin
      bDot:=false;
      bExp:=false;
      sb:=TkbmMWStringBuilder.Create;
      try
      while (FPos<=FLength-KBMMW_STRINGCHARLENOFS) do
      begin
      case FSource[FPos] of
      ‘0’,
      ‘1’,
      ‘2’,
      ‘3’,
      ‘4’,
      ‘5’,
      ‘6’,
      ‘7’,
      ‘8’,
      ‘9’:
      begin
      sb.Append(FSource[FPos]);
      inc(FPos);
      end;

      ‘-‘:
      begin
      // vad if (sb.Length>0) then
      if (sb.Length>0) and (not bExp) then
      break;
      sb.Append(FSource[FPos]);
      inc(FPos);
      end;
      ‘+’:
      begin
      // vad if (sb.Length>0) then
      if (sb.Length>0) and (not bExp) then
      break;
      sb.Append(FSource[FPos]);
      inc(FPos);
      end;

      ‘.’:
      begin
      if bDot then
      break;
      sb.Append(FSource[FPos]);
      inc(FPos);
      bDot:=true;
      end;

      ‘e’,
      ‘E’:
      begin
      if bExp then
      break;
      sb.Append(FSource[FPos]);
      inc(FPos);
      bExp:=true;
      end
      else
      break;
      end;
      end;
      AIsInteger:=not (bDot or bExp);
      Result:=StrToFloat(sb.ToString,kbmMWONDefaultFormat.FormatSettings);
      finally
      sb.Free;
      end;
      end;

       

      • This topic was modified 2 years, 7 months ago by VadimMest.
    • #57177
      kimbomadsen
      Keymaster

      Hi,

      Thank you for your bugreport.

      Parsing scientific numbers will be improved in next release for both JSON and YAML.

      /Kim

Viewing 1 reply thread
  • You must be logged in to reply to this topic.