CSV again.

Mike Kerner MikeKerner at roadrunner.com
Sun Oct 18 21:52:42 EDT 2015


Well, there goes that idea.  There are tutorials right on Git, but it might
be easier if you (and anyone else so not-inclined to Git) post here and
those of us who are at least inclined to try will make do with doing that
work for you.

Anyway, here's what I have as the latest version, with a couple of things I
added to it, marked as "mikey"

function CSVToTab pData,pcoldelim
      local tNuData -- contains tabbed copy of data
      local tReturnPlaceholder -- replaces cr in field data to avoid line
      --                       breaks which would be misread as records;
      local tNuDelim  -- new character to replace the delimiter
      local tStatus, theInsideStringSoFar
      --
      put numtochar(11) into tReturnPlaceholder -- vertical tab as
placeholder
      put numtochar(29) into tNuDelim
      --
      if pcoldelim is empty then put comma into pcoldelim
      -- Normalize line endings:
      replace crlf with cr in pData          -- Win to UNIX
      replace numtochar(13) with cr in pData -- Mac to UNIX

      put CR after pData #last line may not properly parse, otherwise #mikey

      put "outside" into tStatus
      set the itemdel to quote
      repeat for each item k in pData
            -- put tStatus && k & CR after msg
            switch tStatus

                  case "inside"
                        put k after theInsideStringSoFar
                        put "passedquote" into tStatus
                        next repeat

                  case "passedquote"
                        -- decide if it was a duplicated escapedQuote or a
closing quote
                        if k is empty then   -- it's a duplicated quote
                              put quote after theInsideStringSoFar
                              put "inside" into tStatus
                              next repeat
                        end if
                        -- not empty - so we remain inside the cell, though
we have left the quoted section
                        -- NB this allows for quoted sub-strings within the
cell content !!
                        replace cr with tReturnPlaceholder in
theInsideStringSoFar
                        put theInsideStringSoFar after tNuData

                  case "outside"
                        replace pcoldelim with tNuDelim in k
                        -- and deal with the "empty trailing item" issue in
Livecode
                        replace (tNuDelim & CR) with tNuDelim & tNuDelim &
CR in k
                        put k after tNuData
                        put "inside" into tStatus
                        put empty into theInsideStringSoFar
                        next repeat
                  default
                        put "defaulted"
                        break
            end switch
      end repeat
      replace tNuDelim with tab in tNuData #mikey
      delete last char of tNuData #added at top to assist last line parse
#mikey
      return tNuData
end CSVToTab




On Sun, Oct 18, 2015 at 8:06 PM, Alex Tweedly <alex at tweedly.net> wrote:

>
>
> On 18/10/2015 13:57, Mike Kerner wrote:
>
>> https://github.com/macMikey/LiveCode-Libraries/tree/master/csv
>>
>> I've found some corner cases and made some others.
>>
>>
>> OK, I confess:
>
> I've never used git or github, and I have no idea how to get access to
> these.  :-)
>
> I know I need to learn, but honestly this is not the right time for me to
> do that - is there a 5-minute tutorial (or step-by-step instruction) that I
> can follow to at least get these files ?
>
> Many thanks
> Alex.
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."



More information about the use-livecode mailing list