オープンソース開発されているフリーのテキストエディタ「CotEditor」v4.1.2において、AppleScript系の機能が追加されています。
・DocumentオブジェクトのhasBOM属性
has BOM (boolean, r/o) : Is the file encoding of the document has BOM (byte order mark)?
・convertコマンドのBOMオプション
convert v : Convert the document text to new encoding. convert document : The document to convert encoding. [lossy boolean] : Allows lossy conversion? [BOM boolean] : Has the new encoding a BOM (byte order mark)? to text : The new encoding, either in localized encoding name or an IANA charset name. → boolean : Did the convertion succeed?
・新設のjumpコマンド
jump v : Move the caret to the specified location. At least, either one of a parameter is required. jump document : The document to move. to line integer : The number of the line to go. If a negative value is provided, the line is counted from the end of the document. [column integer] : The location in the line to jump. If a negative value is provided, the column is counted from the end of the line.
こんなサンプル書類があったとして、
AppleScriptのdocumentオブジェクトの文字データを取得してダンプしてみても、
--No BOM {"E3", "81", "B4", "E3", "82", "88", "E3", "81", "BE", "E3", "82", "8B", "E3", "82", "BD", "E3", "83", "95", "E3", "83", "88", "E3", "82", "A6", "E3", "82", "A7", "E3", "82", "A2", "0A", "61", "62", "63", "64", "E9", "AB", "98", "E5", "B3", "B6", "E5", "B1", "8B", "65", "66", "67", "68", "69", "0A", "0A"} --with BOM {"E3", "81", "B4", "E3", "82", "88", "E3", "81", "BE", "E3", "82", "8B", "E3", "82", "BD", "E3", "83", "95", "E3", "83", "88", "E3", "82", "A6", "E3", "82", "A7", "E3", "82", "A2", "0A", "61", "62", "63", "64", "E9", "AB", "98", "E5", "B3", "B6", "E5", "B1", "8B", "65", "66", "67", "68", "69", "0A", "0A"}
この状態ではhasBOM属性値で差があっても、内部データでは差が出ません。これをファイルに書き込んで、ファイル内容についてチェックを行うと、
--No BOM 0000000 81e3 e3b4 8882 81e3 e3be 8b82 82e3 e3bd 0000010 9583 83e3 e388 a682 82e3 e3a7 a282 610a 0000020 6362 e964 98ab b3e5 e5b6 8bb1 6665 6867 0000030 0a69 000a 0000033 --With BOM 0000000 bbef e3bf b481 82e3 e388 be81 82e3 e38b 0000010 bd82 83e3 e395 8883 82e3 e3a6 a782 82e3 0000020 0aa2 6261 6463 abe9 e598 b6b3 b1e5 658b 0000030 6766 6968 0a0a 0000036
のように、差を検出できます。
More from my site
(Visited 104 times, 1 visits today)