2 * @file FileTextEncoding.cpp
4 * @brief Implementation of FileTextEncoding structure
8 #include "FileTextEncoding.h"
11 FileTextEncoding::FileTextEncoding()
17 * @brief Forget any encoding info we have
19 void FileTextEncoding::Clear()
22 m_unicoding = ucr::NONE;
29 void FileTextEncoding::SetCodepage(int codepage)
31 m_codepage = codepage;
35 m_unicoding = ucr::UTF8;
38 m_unicoding = ucr::UCS2LE;
41 m_unicoding = ucr::UCS2BE;
44 m_unicoding = ucr::NONE;
49 void FileTextEncoding::SetUnicoding(ucr::UNICODESET unicoding)
51 m_unicoding = unicoding;
60 m_codepage = 0; // not sure what to do here
65 m_codepage = ucr::CP_UTF_8;
68 m_codepage = ucr::CP_UCS2LE;
71 m_codepage = ucr::CP_UCS2BE;
77 * @brief Return string representation of encoding, eg "UCS-2LE", or "1252"
78 * @todo This resource lookup should be done in GUI code?
80 String FileTextEncoding::GetName() const
82 if (m_unicoding == ucr::UTF8)
85 return _T("UTF-8 (B)");
90 if (m_unicoding == ucr::UCS2LE)
91 return _T("UCS-2 LE");
92 if (m_unicoding == ucr::UCS2BE)
93 return _T("UCS-2 BE");
98 if (m_codepage == ucr::CP_UTF_8)
100 // We detected codepage to be UTF-8, but unicoding was not set
104 return strutils::to_str(m_codepage);
107 int FileTextEncoding::Collate(const FileTextEncoding & fte1, const FileTextEncoding & fte2)
109 if (fte1.m_unicoding > fte2.m_unicoding)
111 if (fte1.m_unicoding < fte2.m_unicoding)
113 if (fte1.m_codepage > fte2.m_codepage)
115 if (fte1.m_codepage < fte2.m_codepage)
117 if (fte1.m_bom > fte2.m_bom)
119 if (fte1.m_bom < fte2.m_bom)