mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Introduce encoding::type
This wraps charset, byte order mark, and newline character(s).
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define FILE_ENCODING_H_CM7CPD1M
|
||||
|
||||
#include "bytes.h"
|
||||
#include <oak/oak.h>
|
||||
|
||||
PUBLIC extern std::string const kCharsetNoEncoding;
|
||||
PUBLIC extern std::string const kCharsetASCII;
|
||||
@@ -16,6 +17,31 @@ namespace encoding
|
||||
{
|
||||
PUBLIC io::bytes_ptr convert (io::bytes_ptr content, std::string const& from, std::string const& to);
|
||||
|
||||
struct type
|
||||
{
|
||||
type () { }
|
||||
type (std::string const& newlines, std::string const& charset, bool byte_order_mark) : _newlines(newlines), _charset(charset), _byte_order_mark(byte_order_mark) { }
|
||||
|
||||
std::string const& newlines () const { return _newlines; }
|
||||
std::string const& charset () const { return _charset; }
|
||||
bool byte_order_mark () const { return _byte_order_mark && supports_byte_order_mark(_charset); }
|
||||
|
||||
void set_newlines (std::string const& newlines) { _newlines = newlines; }
|
||||
void set_charset (std::string const& charset) { _charset = charset; _byte_order_mark = charset != kCharsetUTF8 && supports_byte_order_mark(charset); }
|
||||
void set_byte_order_mark (bool flag) { _byte_order_mark = flag; }
|
||||
|
||||
static bool supports_byte_order_mark (std::string const& charset)
|
||||
{
|
||||
static std::string const Encodings[] = { kCharsetUTF8, kCharsetUTF16BE, kCharsetUTF16LE, kCharsetUTF32BE, kCharsetUTF32LE };
|
||||
return oak::contains(beginof(Encodings), endof(Encodings), charset);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _newlines = NULL_STR;
|
||||
std::string _charset = kCharsetNoEncoding;
|
||||
bool _byte_order_mark = false;
|
||||
};
|
||||
|
||||
} /* encoding */
|
||||
|
||||
#endif /* end of include guard: FILE_ENCODING_H_CM7CPD1M */
|
||||
|
||||
Reference in New Issue
Block a user