home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.forth      Forth programmers eat a lot of Bratwurst      117,927 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 117,724 of 117,927   
   Hans Bezemer to dxf   
   Re: Back & Forth - CSV is dead, long liv   
   17 Nov 25 19:43:25   
   
   From: the.beez.speaks@gmail.com   
      
   On 17-11-2025 00:48, dxf wrote:   
   > On 16/11/2025 1:12 am, Hans Bezemer wrote:   
   >> A well behaved CSV is easy to parse. However, if there are quotes,   
   delimiters or line terminators involved, it gets complicated quickly.   
   >> ...   
   >   
   > Can't say I've had the need - but then I recently found myself having to   
   > parse an assembler include file which I never expected.  Never say never?   
   > Prompted by your video I've ported your csv parser grateful at not having   
   > to reinvent this particular wheel!  Thanks.  TSV?  That was new to me too.   
      
   For those interested - this is a non-destructive routine C routine to   
   parse a TSV record. It resembles WORD a bit. Given you provide the right   
   size, it's memory safe as well. Empty fields are properly parsed as well.   
      
   Expanding escape codes is quite trivial IMHO. By saving "IN" and   
   comparing it to the updated value of "IN" we can detect a EOL.   
      
   Hans Bezemer   
      
   #include    
      
   static unsigned In = 0;   
      
   char *parse_tsv (char *src, char *dst, size_t n)   
   {   
      char *p = dst;   
      
      src += In;   
      
      while ((*src != '\t') && (*src != '\0') && (n)) {   
        *dst = *src; In++; dst++; src++; n--;   
      }   
      
      *dst = '\0'; if (*src == '\t') In++;   
      return (p);   
   }   
      
      
   int main ()   
   {   
      char s[] = "\tThis\t\tis\tthe\tend";   
      char d[64];   
      unsigned q;   
      
      do {   
        q = In;   
        printf ("token=[%s]\n", parse_tsv (s, d, 63));   
      } while (q != In);   
   }   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca