38 CheckUTF8(
const char* s,
const char* g)
40 while(s < g && *s != 0
42 return s == g || *s == 0;
47 CheckEncoding(
const char* s,
size_t n)
53 InitializeTextFile(TextFile& tf,
size_t& bl)
58 bl = tf.CheckBOM(tf.Encoding);
63 #define YSL_TXT_CHECK_ENCODING_N 64U
66 #undef YSL_TXT_CHECK_ENCODING_N
71 tf.Encoding = CheckEncoding(s, n);
78 TextFile::TextFile(
const_path_t filename, std::ios_base::openmode mode,
80 : File(filename, mode),
83 if(GetSize() == 0 && mode & std::ios_base::out)
104 InitializeTextFile(*
this, bl);
107 : File(filename, u
"r"),
110 InitializeTextFile(*
this, bl);
117 string str(s,
char());
120 for(
size_t i(0); i != s; ++i)
121 str[i] = std::fgetc(
GetPtr());
122 return std::move(str);
128 using std::char_traits;
136 if(char_traits<char>::compare(tmp,
BOM_UTF_16LE, 2) == 0)
141 if(char_traits<char>::compare(tmp,
BOM_UTF_16BE, 2) == 0)
146 if(char_traits<char>::compare(tmp,
BOM_UTF_8, 3) == 0)
151 if(char_traits<char>::compare(tmp,
BOM_UTF_32LE, 4) == 0)
156 if(char_traits<char>::compare(tmp,
BOM_UTF_32BE, 4) == 0)
167 Seek(bl + pos, SEEK_SET);