This page covers the encodings Caxton reads, which of them are detected when a file opens, and how detection decides. It also covers File ▸ Reopen with Encoding, which reads the same bytes another way, File ▸ Save with Encoding…, which writes the file in another encoding, Text ▸ Line Endings for converting to LF, CRLF or CR, and Text ▸ Byte Order Mark with Add and Remove. The Inspector's Why this encoding and Invalid bytes rows, Edit ▸ Find ▸ Go to First Invalid Byte, and saving a file back in its own encoding are described here too.
The encodings
Listed in the order of the Reopen with Encoding menu, under the menu's names, followed by the two UTF-32 forms, which the menu does not list.
| Encoding | Detected on open | Notes |
|---|---|---|
| UTF-8 | Yes | Validated as UTF-8. An all-ASCII file is read as UTF-8. |
| UTF-8 (BOM) | Yes | UTF-8 that starts with a byte order mark, detected by the mark. Save writes the mark back. |
| UTF-16 LE | Yes | By its byte order mark. Without one, by the pattern of zero bytes, or for Japanese, Chinese and Korean text by its code units. |
| UTF-16 BE | Yes | By its byte order mark. Without one, by the pattern of zero bytes, or for Japanese, Chinese and Korean text by its code units. |
| Shift-JIS | Yes | Japanese. |
| EUC-JP | Yes | Japanese. |
| GB18030 | Yes | Simplified Chinese. |
| Big5 | Yes | Traditional Chinese. |
| EUC-KR | Yes | Korean. |
| Windows-1252 | Yes | Western European. Detected even when only a few accented characters appear. |
| ISO-8859-1 | As Windows-1252 | Western European. Windows-1252 reads the same letters, so a file in ISO-8859-1 opens as Windows-1252. Choose it in File ▸ Reopen with Encoding. |
| Windows-1251 | Yes | Cyrillic. |
| KOI8-R | Yes | Cyrillic. |
| ISO-8859-5 | Yes | Cyrillic. |
| Windows-1250 | Yes | Central European. |
| ISO-8859-2 | Yes | Central European. |
| Windows-1254 | Reopen only | Turkish. Choose it in File ▸ Reopen with Encoding. |
| Windows-1257 | Reopen only | Baltic. Choose it in File ▸ Reopen with Encoding. |
| UTF-32 LE | By byte order mark only | Read when the file starts with its byte order mark. Not in the Reopen with Encoding menu, so a UTF-32 file without the mark cannot be read as UTF-32. |
| UTF-32 BE | By byte order mark only | Same as UTF-32 LE, in the other byte order. |
How detection decides
- A byte order mark is definitive.
- Otherwise the file is checked as UTF-8. Detection samples four windows through the file plus the tail: all-ASCII is near certain, and a valid multibyte window confirms UTF-8.
- A window that is not valid UTF-8, beyond those few bad bytes, brings the legacy encodings in. The candidates are scored by how the decoded text reads, and a legacy detection never claims more than 85 percent confidence, which keeps the reopen hint visible for it. The five CJK tables are told apart by the script each one reads, kana for the Japanese tables and hangul for EUC-KR, and by the byte ranges the file uses, so a Big5 file is not read as GB18030 and a short GB18030 file is not read as EUC-JP. The one case the bytes cannot settle is a Japanese file with no kana at all, a bare list of names or addresses: it can open as GB18030 with the reopen hint showing, and Reopen with Encoding reads it as EUC-JP or Shift-JIS. A Shift-JIS, EUC-JP, Big5, EUC-KR or GB18030 file is still recognized with a few damaged bytes in it. A file whose only high bytes read as Western text, such as an accented letter before an ordinary letter or a degree sign before C or F, is read as Western text and not as a CJK file, so a file with one or two Chinese characters among English words can open as Windows-1252.
- A few bad bytes in an otherwise UTF-8 file are treated as damage, not as a reason to read the whole file in a legacy encoding. The start of the file is read as UTF-8 when it holds at most 12 invalid sequences and at least 16 valid multi-byte characters for each one. A short file with a handful of accents and a bad byte is too little to tell, and can still open as Windows-1252 with the reopen hint showing.
When a file opens as UTF-8 at low confidence and some bytes look like a legacy encoding, the banner names it (Some bytes look like Windows-1252. Reopen with that encoding?) and Reopen with Encoding preselects it, marked as suggested.
Inspecting the encoding
The Encoding section of the Inspector (⌥⌘I) answers three questions about the file in front of you. Why this encoding gives the evidence that decided it, for instance Caxton read this file as UTF-8 because all of it is valid UTF-8, with 1,204 multi-byte sequences. or Caxton read this file as Windows-1252 because it is not valid UTF-8 and its bytes fit Western European text best. ISO-8859-1 fits almost as well. Invalid bytes counts the bytes that are not valid in that encoding. Its First and Next buttons, like Edit ▸ Find ▸ Go to First Invalid Byte and Go to Next Invalid Byte, take you to each place with the bytes selected. Invisibles counts the invisible characters by kind.
The Inspector's Selection section names the character at the caret with its code point, its name and its bytes in the file's encoding. In the Problems panel, Show Raw opens the bytes behind a structural problem, sixteen to a line as hex and as text, with the problem's bytes marked and the same span as decoded text below. All of this is reading, so it is free on Caxton Free at any file size.
Reopen with Encoding
File ▸ Reopen with Encoding reinterprets the file in any of the 18. UTF-8 reads the file as UTF-8 without a byte order mark and UTF-8 (BOM) as UTF-8 with one. A forced encoding wins over the byte order mark. With unsaved edits, Caxton asks first (Reopen and discard unsaved changes?): reopening re-reads the file from disk, so Reopen discards your edits and Cancel keeps them. Transcoding runs in the background with progress and a cancel, and one undecodable byte no longer fails the open: only the bytes that cannot be decoded become replacement characters.
- A file reopened this way is written as UTF-8 on Save As, and before you click the panel notes that it saves a UTF-8 copy, with the file's original encoding beside it.
- Follow works on reopened files; appended bytes are transcoded as they arrive.
- A file pattern rule can set the encoding for a glob, so a recurring legacy export opens correctly without the menu.
Saving in the file's encoding
A file opened in an encoding other than UTF-8 is converted to UTF-8 while you work on it, and Save converts it back, so the file keeps its encoding and its byte order mark. One limit: in Shift-JIS as Windows writes it, code page 932, a few characters have two codes, and Save writes each with the code the Mac's converter chooses. Such a character reads the same after the save, and its bytes can differ from the original: 髙 read from FB FC is saved as EE E0. When your edits contain characters the file's encoding cannot represent, Save stops and asks (Can't save in Shift-JIS, naming the encoding): Save as UTF-8 changes the file's encoding on disk to UTF-8 and saves, and Cancel leaves the file as it was so you can remove the characters.
Operations that stream their result to a new document or file keep the byte order mark of a UTF-8 file that has one: a sort, dedupe or repair past 256 MB, a quarantine file, a duplicate group export and a frequency table export all begin with it. A file that was converted from another encoding streams out as UTF-8 without a mark, as its Save As does.
Converting a file
Three commands change the shape of a file without changing its text: its encoding, its line endings and its byte order mark. Each is an edit, so on Caxton Free it works in a file within 10 MB and is Caxton Pro above that. Each answers the same way in the text view and in the grid, and in a slice or a tail each asks you to open the file whole.
Save with Encoding
File ▸ Save with Encoding… saves the file in another encoding. Reopen with Encoding changes how the bytes are read, and Save with Encoding changes the bytes. The form has an Encoding popup with the 18 encodings of the Reopen with Encoding menu and a checkbox, Start the file with a byte order mark. The mark is a choice for UTF-16. UTF-8 has an entry of its own with the mark, and the other encodings have none.
Save with Encoding opens on the encoding the file has now.
Save first makes sure that every character of the document can be written in the encoding you chose. When they all can, the file is replaced in one step, with your unsaved edits in it, and the document carries on in the new encoding with its undo history and its bookmarks. The conversion is listed in the Operations panel while it runs and can be cancelled there, which leaves the file as it was.
When a character cannot be written, nothing is saved. The banner counts the characters the encoding cannot write, names the first one with its line and its code point, and offers Go to It, which selects that character in the text or its cell in the grid. A file that already has the encoding you chose is left alone, and the banner points to File ▸ Save for your changes. For an untitled document the form leads to the Save panel, and the new file is written in the encoding you chose.
Line endings
Text ▸ Line Endings holds Convert to LF, Convert to CRLF and Convert to CR. The check mark sits on the ending the document has now, and a document that mixes endings has no check. The command always converts the whole file, whatever is selected and whatever a filter shows, on up to 256 MB. It opens a preview that counts the endings that change by kind and the ones that already match, with a few samples, and it applies as one undo step that restores the bytes exactly. Nothing but line endings is touched, and bookmarks stay on their lines.
Convert to LF counts the line endings that change and the ones that already match.
In the grid, a line break inside a quoted cell is data of that cell, so it stays as it is and the preview counts it. In the text view every line break is a line ending and is converted. A document with no line break at all has nothing to convert, and the command sets the ending its new lines will take.
Byte order mark
Text ▸ Byte Order Mark holds Add and Remove, and the one that does not apply is dimmed, which tells you whether the file has a mark. The mark is not part of the text, so the command changes what the next save writes: the banner confirms that the next save starts the file with a byte order mark, or leaves it out. The document counts as edited, and ⌘Z takes the change back. Both items are dimmed for a file in an encoding that has no mark, for an untitled document, which takes its mark from Save with Encoding, and for the Scratchpad.
Removing the mark from a UTF-16 or UTF-32 file asks first, because the mark is how other programs know what the file is. Caxton keeps reading the open window in its encoding either way.
Invalid bytes are left alone
Caxton edits bytes, not a re-encoded copy. Line operations such as duplicate and move are byte-exact even around invalid UTF-8, and Text menu transforms refuse a target that contains invalid UTF-8 and name the line, instead of rewriting those bytes as replacement characters. Mixed international text (CJK, emoji, combining marks) renders and edits correctly, with caret movement that respects grapheme clusters.