Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7441123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:57:41+00:00 2026-05-29T10:57:41+00:00

I am parsing very large files (Unicode – Delphi 2009), and I have a

  • 0

I am parsing very large files (Unicode – Delphi 2009), and I have a very efficient routine for doing so using PChar variables as outlined in the Stackoverflow question: What is the fastest way to Parse a line in Delphi?

Everything was working great until I ran into a file that had some embedded hex:00 characters in it. This character signals the end of a PChar string and my parsing stops at that point.

However, when you load the file, as in:

FileStream := TFileStream.Create(Filename, fmOpenRead or fmShareDenyWrite);
Size := FileStream.Size;

then you find that the size of the file is much larger. If you open the file with Notepad, it loads to the end of the file, not stopping at the first hex:00 as the PChar does.

How can I read to the end of the file while still using PChar parsing without slowing down my reading/parsing too much?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:57:42+00:00Added an answer on May 29, 2026 at 10:57 am

    The accepted code in your other question is breaking out when it reaches a #0 character. To fix that you just need to save the length of the input and check that instead. The updated code would look something like this:

    type
      TLexer = class
      private
        FData: string;
        FTokenStart: PChar;
        FCurrPos: PChar;
        FEndPos: PChar;                                         // << New
        function GetCurrentToken: string;
      public
        constructor Create(const AData: string);
        function GetNextToken: Boolean;
        property CurrentToken: string read GetCurrentToken;
      end;
    
    { TLexer }
    
    constructor TLexer.Create(const AData: string);
    begin
      FData := AData;
      FCurrPos := PChar(FData);
      FEndPos := FCurrPos + Length(AData);                      // << New
    end;
    
    function TLexer.GetCurrentToken: string;
    begin
      SetString(Result, FTokenStart, FCurrPos - FTokenStart);
    end;
    
    function TLexer.GetNextToken: Boolean;
    var
      cp: PChar;
    begin
      cp := FCurrPos; // copy to local to permit register allocation
    
      // skip whitespace
      while (cp <> FEndPos) and (cp^ <= #32) do                 // << Changed
        Inc(cp);
    
      // terminate at end of input
      Result := cp <> FEndPos;                                  // << Changed
    
      if Result then
      begin
        FTokenStart := cp;
        Inc(cp);
        while (cp <> FEndPos) and (cp^ > #32) do                // << Changed
          Inc(cp);
      end;
    
      FCurrPos := cp;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across one very good library for parsing CUE files. But when I
Ok, I have a very frustrating problem. I am parsing a webpage and need
I had to do heavy I/o bound operation, i.e Parsing large files and converting
I am parsing a very large file of records (one per line, each of
I have a very large XML file that I need to parse so I
What is the cost of parsing a large XML file using PHP on every
I am using python 2.7 with latest lxml library. I am parsing a large
I have access to a large C++ project, full of files and with a
I am currently using Poco::XML to parse through a number of very large XML
I have a very large CSV file (Millions of records) I have developed a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.