Extract get_line_{file,stringstream} into standalone methods.
authorCarl Hetherington <cth@carlh.net>
Thu, 11 Feb 2016 11:46:13 +0000 (11:46 +0000)
committerCarl Hetherington <cth@carlh.net>
Thu, 11 Feb 2016 11:46:13 +0000 (11:46 +0000)
src/subrip_reader.cc
src/subrip_reader.h
src/util.cc
src/util.h

index ddaa11239c7c8284c2a94f89e3da471bf8d2e1d3..6c0c63a26130877f87adfa6c0bb27847af7e3064 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "subrip_reader.h"
 #include "exceptions.h"
+#include "util.h"
 #include <boost/algorithm/string.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/regex.hpp>
@@ -47,37 +48,13 @@ using namespace sub;
 SubripReader::SubripReader (string const & s)
 {
        stringstream str (s);
-       this->read (boost::bind (&SubripReader::get_line_stringstream, this, &str));
+       this->read (boost::bind (&get_line_stringstream, &str));
 }
 
 /** @param f Subtitle file encoded in UTF-8 */
 SubripReader::SubripReader (FILE* f)
 {
-       this->read (boost::bind (&SubripReader::get_line_file, this, f));
-}
-
-optional<string>
-SubripReader::get_line_stringstream (stringstream* str) const
-{
-       string s;
-       getline (*str, s);
-       if (!str->good ()) {
-               return optional<string> ();
-       }
-
-       return s;
-}
-
-optional<string>
-SubripReader::get_line_file (FILE* f) const
-{
-       char buffer[256];
-       char* r = fgets (buffer, sizeof (buffer), f);
-       if (r == 0 || feof (f)) {
-               return optional<string> ();
-       }
-
-       return string (buffer);
+       this->read (boost::bind (&get_line_file, f));
 }
 
 void
index 11ce5306429b97d3a8e48d0a5f69e74bbd84a5a6..e9a9b35594140c3f1993c10ac6f49f4ee578f739 100644 (file)
@@ -47,8 +47,6 @@ private:
        static Time convert_time (std::string t);
        void convert_line (std::string t, int line_number, Time from, Time to);
        void maybe_content (RawSubtitle& p);
-       boost::optional<std::string> get_line_stringstream (std::stringstream* str) const;
-       boost::optional<std::string> get_line_file (FILE* file) const;
        void read (boost::function<boost::optional<std::string> ()> get_line);
 };
 
index 5f4cd39c464e4c6cdcc221185242d86473104930..5510d8ecd59dfcc74074df49c5b0b9fa1578d51c 100644 (file)
 */
 
 #include "util.h"
+#include <string>
+#include <sstream>
+#include <cstdio>
 
 using std::string;
+using std::stringstream;
+using std::getline;
+using boost::optional;
 
 /** @param s A string.
  *  @return true if the string contains only space, newline or tab characters, or is empty.
@@ -35,3 +41,27 @@ sub::empty_or_white_space (string s)
 
        return true;
 }
+
+optional<string>
+sub::get_line_stringstream (stringstream* str)
+{
+       string s;
+       getline (*str, s);
+       if (!str->good ()) {
+               return optional<string> ();
+       }
+
+       return s;
+}
+
+optional<string>
+sub::get_line_file (FILE* f)
+{
+       char buffer[256];
+       char* r = fgets (buffer, sizeof (buffer), f);
+       if (r == 0 || feof (f)) {
+               return optional<string> ();
+       }
+
+       return string (buffer);
+}
index e77d62eaf6a68c73914456f0513818569d783b3e..9d3edc247039fcfa7892d0778bbbf1ed365c2a0c 100644 (file)
 
 */
 
+#include <boost/optional.hpp>
 #include <string>
 
 namespace sub {
 
 extern bool empty_or_white_space (std::string s);
+extern boost::optional<std::string> get_line_stringstream (std::stringstream* str);
+extern boost::optional<std::string> get_line_file (FILE* f);
 
 }