Results 1 to 6 of 6

Thread: Line-by-line file processing?

  1. #1

    Cool Line-by-line file processing?

    Hi. Perhaps I shouldn't have to ask this, but here it goes anyway: I read the overview on file i/o, and it basically just said use CL_File and drop the data in a CL_DataBuffer. I didn't see convenient functions anywhere for processing the data line-by-line. Is there, say, a convenient function for pulling the lines out of a CL_DataBuffer? ("lines" as in text data separated by whatever happens to be the end-of-line character on the system.) If not, what would you recommend as the easiest and most portable way of going about this?

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I'm not sure that I fully understand your approach.

    If you want to read lines from a text file:

    Use:
    Code:
    CL_File::CL_File  (  const CL_String &  filename   )   
     
       Constructs a file object read only.
    Since CL_File inherits CL_IOData, you can use:
    Code:
    CL_String8 CL_IODevice::read_string_text  (  const char *  skip_initial_chars,  
      const char *  read_until_chars,  
      bool  allow_eof = true 
     )   
     
       Reads a string from the input source where the source is a text file. 
    
    
    Parameters:
     skip_initital_chars  Ignore any of these characters at the start of the string. NULL = Do not ignore any characters  
     read_until_chars  Read from the input until any of these characters are found. NULL = Read until the end of the file  
    
    Returns:
    The string read.
    skip_initial_chars = "\r\n", read_until_chars = "\r\n"

    There may be an example in Tests/Core/IOData

  3. #3

    Default

    Yeah, thanks, I think that was what I was looking for. I somehow did not notice all those function in CL_IODevice.

  4. #4

    Default

    Two related questions:

    1. How do you know if you've reached the EOF?

    2. What does the allow_eof switch do? (This is not explained in the reference docs.)

  5. #5
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Quote Originally Posted by CoderMan View Post
    Two related questions:

    1. How do you know if you've reached the EOF?

    2. What does the allow_eof switch do? (This is not explained in the reference docs.)

    1) When get_size() == get_position(). (Remember to cache get_size(), to assist in performance)

    2) If allow_eof is true, this function does not throw an exception when the end of file is found.

    The documentation needs clarified, same with lots of the clanlib API ... but it's a huge task!

  6. #6

    Default

    Quote Originally Posted by rombust View Post
    1) When get_size() == get_position(). (Remember to cache get_size(), to assist in performance)

    2) If allow_eof is true, this function does not throw an exception when the end of file is found.

    The documentation needs clarified, same with lots of the clanlib API ... but it's a huge task!
    Thanks. I'm not complaining... I appreciate all your hard work. Keep it up!

    Maybe one day I'll become a ClanLib guru and help out with the documentation. Obviously I'm not quite there yet.

Similar Threads

  1. Writing to XML file
    By Solitude in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 07-07-2009, 05:26 AM
  2. autogen.sh line feed issue
    By exigo in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 06-10-2009, 09:33 PM
  3. Particles from a line or area?
    By CheshireWhiskers in forum Novashell Game Creation System
    Replies: 4
    Last Post: 05-18-2008, 04:07 PM
  4. More on the green line problem, bug in Clanlib?
    By pTymN in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 03-22-2007, 04:43 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •