Files
textmate/Frameworks/file/src/encoding.h
Allan Odgaard d1de4a8854 Use encoding::type for save related API
There is also a new document_t::encoding_for_save_as_path which returns the encoding that would be used for the document, if saved at the given path. If the document was loaded from disk, it will return the encoding used during load, otherwise it will check tmProperties for which encoding should be used for the path provided. Save dialog for untitled documents will be pre-populated with the result of the above function.
2012-08-26 16:13:20 +02:00

48 lines
1.8 KiB
C++

#ifndef FILE_ENCODING_H_CM7CPD1M
#define FILE_ENCODING_H_CM7CPD1M
#include "bytes.h"
#include <oak/oak.h>
PUBLIC extern std::string const kCharsetNoEncoding;
PUBLIC extern std::string const kCharsetASCII;
PUBLIC extern std::string const kCharsetUTF8;
PUBLIC extern std::string const kCharsetUTF16BE;
PUBLIC extern std::string const kCharsetUTF16LE;
PUBLIC extern std::string const kCharsetUTF32BE;
PUBLIC extern std::string const kCharsetUTF32LE;
PUBLIC extern std::string const kCharsetUnknown;
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 = false) : _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 */