Cocoa endOfLine Woes

Hey all,

I was hoping someone might be able to help me shed some light on an issue I’m having converting my application to Cocoa. (I do know that the default endOfLine character was changed to chr(10) for Cocoa)

I using the Einhugur e-CryptIt plugin to encrypt strings that are saved to a text file. Any end-of-line characters that the user might put into the string is converted into a custom tag so that I don’t have to worry about differences between platforms. When they’re read back in, they are decrypted, the tag replaced with a platform specific endOfLine delimiter, and put into a text area control.

This has all worked fine and continues to work fine with a Carbon build. However, when running a Cocoa build the text area displays a “?” character where the delimiter is supposed to be. If I use replaceAll to put something like “???” instead of the endOfLine, the “???” shows up fine and there doesn’t appear to be any other invisible character there or anything odd (but clearly there is no line break).

If I just go through and try to duplicate this issue with a string variable that I type into Xojo, I can’t replicate it. Additionally, the “?” character shows up whether I try to replace the custom end-of-line tag with chr(10), chr(13), or endOfLine.

Ideas?! O_o

Have you defined the encoding when getting the string back from the file?

Why are there diamonds in my user interface?

Why convert the EOL character before encrypting? You have to convert anyway when you decrypt, right? See ReplaceLineEndings in the LR, in case you are not familiar.

You’re better off making sure that you know the encoding going in so you can be sure the encoding is right on the way out. Something like this pseudo-code:

Sub Encrypt (s As String)
  if s.Encoding is nil then
    s = s.DefineEncoding( Encodings.UTF8 ) // Or try to guess the right encoding
  else
    s = s.ConvertEncoding( Encodings.UTF8 )
  end if
  // Now encrypt it
End Sub

Sub Decrypt (s As String)
  s = DecryptTheString( s )
  s = s.DefineEncoding( Encodings.UTF8 )
  s = ReplaceLineEndings( s, EndOfLine )
End Sub

My M_String module has functions for guessing the right encoding of a string, if that’s of use to you.

Hi all. Thanks for the responses. The strings are all written from Xojo, so I figured they were going to stay UTF-8. However, it seems that the encryption/decryption does something there? Regardless, if I define the encoding as UTF-8 after the decryption (like you mentioned Eli) then everything works as expected. I had tried convertEncoding before and that didn’t work and that’s why I forgot about defineEncoding.

I’m betting that the encryption / decryption turns it into runs of bytes - not utf-8 strings which are only utf-8 strings once you define the encoding those runs of bytes SHOULD be interpreted as