Remove the charset detection from TextFileReader since it's never used

This commit is contained in:
Thomas Goyne 2013-04-13 08:15:36 -07:00
parent 8bdb7d32ad
commit 17170fc5fe
4 changed files with 9 additions and 12 deletions

View file

@ -83,9 +83,6 @@ SubsController::SubsController(agi::Context *context)
}
void SubsController::Load(agi::fs::path const& filename, std::string charset) {
// TextFileReader does this automatically, but relying on that results in
// the user being prompted twice if it can't be auto-detected, since we
// open the file twice below.
try {
if (charset.empty())
charset = CharSetDetect::GetEncoding(filename);

View file

@ -39,6 +39,7 @@
#include "ass_dialogue.h"
#include "ass_file.h"
#include "ass_time.h"
#include "charset_detect.h"
#include "text_file_reader.h"
#include "text_file_writer.h"
#include "video_context.h"
@ -74,7 +75,10 @@ bool MicroDVDSubtitleFormat::CanReadFile(agi::fs::path const& filename) const {
if (!agi::fs::HasExtension(filename, "sub")) return false;
// Since there is an infinity of .sub formats, load first line and check if it's valid
TextFileReader file(filename);
auto encoding = CharSetDetect::GetEncoding(filename);
if (encoding == "binary") return false;
TextFileReader file(filename, encoding);
if (file.HasMoreLines())
return regex_match(file.ReadLineFromFile(), line_regex);

View file

@ -23,8 +23,6 @@
#include "text_file_reader.h"
#include "charset_detect.h"
#include <libaegisub/io.h>
#include <algorithm>
@ -32,12 +30,10 @@
#include <boost/algorithm/string/trim.hpp>
TextFileReader::TextFileReader(agi::fs::path const& filename, std::string encoding, bool trim)
: trim(trim)
: file(agi::io::Open(filename, true))
, trim(trim)
, iter(agi::line_iterator<std::string>(*file, encoding))
{
if (encoding.empty())
encoding = CharSetDetect::GetEncoding(filename);
file.reset(agi::io::Open(filename, true));
iter = agi::line_iterator<std::string>(*file, encoding);
}
TextFileReader::~TextFileReader() {

View file

@ -43,7 +43,7 @@ public:
/// @param filename File to open
/// @param enc Encoding to use, or empty to autodetect
/// @param trim Whether to trim whitespace from lines read
TextFileReader(agi::fs::path const& filename, std::string encoding="", bool trim=true);
TextFileReader(agi::fs::path const& filename, std::string encoding, bool trim=true);
/// @brief Destructor
~TextFileReader();