Read file with accented characters ?

Zax zax at tripoy.com
Wed May 24 05:47:19 EDT 2006


I tried this function but it returns wrong result with Rev 2.5.1

So finally I will use the following process:

    open file MyFile for binary read
    if the result <> "" then
    read from file MyFile  until EOF
    close file MyFile
    put the number of lines in it into NumOfLines
    open file MyFile for text read
    read from file MyFile until EOF
    close file MyFile
    if the number of lines in it <> NumOfLines then get IsoToMac(it)

It opens the text file twice - once as binary as the other as text - and
compares the number of lines. If the number of lines is different, then it's
not a pure Mac text file, so I have to use IsoToMac() to fix accented
characters.

Thanks all for your help.
 
> In a message dated 5/23/06 1:29:03 AM, Zax <zax at tripoy.com> writes:
>> I have to say I don't know how to check the line endings in a safe way
>> :(

>    Perhaps something like this might work:
> 
> function WhatMyLineEnding DerFile
>   # DerFile had better have been read as a binary file;
>   # otherwise, Rev will have automagically converted all end-of-line
> characters
>   # to whatever is used by *your* machine
>   put numToChar (10) into MyLinefeed
>   put numToChar (13) into MyReturn
> 
>   put the length of DerFile into OldLength
> 
>   # how many lines?
>   put the number of lines in DerFile into NumOfLines
> 
>   # how many linefeeds?
>   put DerFile into Fred
>   if char -1 of Fred <> MyLinefeed then put 1 into NumOfLFs
>   replace MyLinefeed with "" in Fred
>   add (OldLength - the length of Fred) to NumOfLFs
> 
>   # how many returns?
>   put DerFile into Fred
>   if char -1 of Fred <> MyReturn then put 1 into NumOfReturns
>   replace MyReturn with "" in Fred
>   add (OldLength - the length of Fred) to NumOfReturns
> 
>   # how many (return+linefeed)s?
>   put DerFile into Fred
>   if (char -2 to -1 of Fred) <> (MyReturn & MyLinefeed) then put 1 into
> NumOfCRLFs
>   replace (MyReturn & MyLinefeed) with "" in Fred
>   add (OldLength - the length of Fred) div 2 to NumOfCRLFs
> 
>   switch
>     case (NumOfCRLFs = NumOfLines)
>       put "Win/DOS" into FileSource
>     break
> 
>     case (NumOfLFs = NumOfLines)
>       put "Unix" into FileSource
>     break
> 
>     case (NumOfReturns = NumOfLines)
>       put "Mac" into FileSource
>     break
> 
>     default
>       put "???" into FileSource
>   end switch
> 
>   return FileSource
> end WhatsMyLineEnding
> 
>     Hopefully, this handler can identify which flavor of line-endings are
> used in any arbitrary file...

----------------------
Zax 





More information about the use-livecode mailing list