Nova linha: diferenças entre revisões

Conteúdo apagado Conteúdo adicionado
Linha 39:
As diferentes convenções para o newline muitas vezes fazem com que os arquivos de texto copiados de uma plataforma para outra sejam mostrados de maneira incorreta. Por exemplo, arquivos criados no [[Unix]] ou [[Apple Macintosh]] serão vistos como uma longa e única linha no [[Microsoft Windows|Windows]]. Analogamente, um arquivo do Windows visto no Unix terá seus <tt>CR</tt> mostrados como um <tt>^M</tt> ao final de cada linha ou como um segundo pula linha.
 
O problema pode ser de difícil detecção. Por exemplo, um [[compilador]] poderá falhar com erros de sintaxe obscuros embora o arquivo fonte pareça normal. Os editores de textos mais recentes reconhecem todas as variações de newlines do tipo <tt>CR</tt> / <tt>LF</tt> permitindo ao usuário converter entre os diferentes padrões. Os [[Navegador|navegadores]] – em geral - também são capazes de fazê-lo.
The problem can be hard to spot if some programs handle the foreign newlines properly while others don't. For example, a [[compiler]] may fail with obscure syntax errors even though the source file looks correct when displayed on the [[Command line interface|console]] or in an [[Text editor|editor]]. Modern text editors generally recognize all flavours of <tt>CR</tt> / <tt>LF</tt> newlines and allow the user to convert between the different standards. [[Web browser]]s are usually also capable of displaying text files of different types.
 
The [[File Transfer Protocol]] can automatically convert newlines in files being transferred between [[Operating System|systems]] with different newline representations when the transfer is done in ''ASCII mode''. However, transferring binary files in this mode usually has disastrous results: Any occurrence of the newline byte sequence—which does not have line terminator semantics in this context, but is just a normal sequence of bytes—will be translated to whatever newline representation the other system uses, effectively corrupting the file. FTP clients often employ some [[Heuristic (computer science)|heuristics]] (for example inspection of [[filename extension]]s) to automatically select either binary or ASCII mode, but in the end it is up to the user to make sure his files are transferred in the correct mode. If there is any doubt as to the correct mode, binary mode should be used, as then no files will be altered by FTP, though they may display incorrectly.