forked from mia/Aegisub
Remove the charset detection from TextFileReader since it's never used
This commit is contained in:
parent
8bdb7d32ad
commit
17170fc5fe
4 changed files with 9 additions and 12 deletions
|
@ -83,9 +83,6 @@ SubsController::SubsController(agi::Context *context)
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubsController::Load(agi::fs::path const& filename, std::string charset) {
|
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 {
|
try {
|
||||||
if (charset.empty())
|
if (charset.empty())
|
||||||
charset = CharSetDetect::GetEncoding(filename);
|
charset = CharSetDetect::GetEncoding(filename);
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "ass_dialogue.h"
|
#include "ass_dialogue.h"
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
#include "ass_time.h"
|
#include "ass_time.h"
|
||||||
|
#include "charset_detect.h"
|
||||||
#include "text_file_reader.h"
|
#include "text_file_reader.h"
|
||||||
#include "text_file_writer.h"
|
#include "text_file_writer.h"
|
||||||
#include "video_context.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;
|
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
|
// 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())
|
if (file.HasMoreLines())
|
||||||
return regex_match(file.ReadLineFromFile(), line_regex);
|
return regex_match(file.ReadLineFromFile(), line_regex);
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
|
|
||||||
#include "text_file_reader.h"
|
#include "text_file_reader.h"
|
||||||
|
|
||||||
#include "charset_detect.h"
|
|
||||||
|
|
||||||
#include <libaegisub/io.h>
|
#include <libaegisub/io.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -32,12 +30,10 @@
|
||||||
#include <boost/algorithm/string/trim.hpp>
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
|
|
||||||
TextFileReader::TextFileReader(agi::fs::path const& filename, std::string encoding, bool trim)
|
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() {
|
TextFileReader::~TextFileReader() {
|
||||||
|
|
|
@ -43,7 +43,7 @@ public:
|
||||||
/// @param filename File to open
|
/// @param filename File to open
|
||||||
/// @param enc Encoding to use, or empty to autodetect
|
/// @param enc Encoding to use, or empty to autodetect
|
||||||
/// @param trim Whether to trim whitespace from lines read
|
/// @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
|
/// @brief Destructor
|
||||||
~TextFileReader();
|
~TextFileReader();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue