diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-07-22 09:26:54 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-07-22 09:26:54 +0100 |
| commit | e245921978ee9c7c6e025c7416bdf808d789fa44 (patch) | |
| tree | 17a6c18cc1d0294f7e87d7c6638d4cc23f81b7e5 /src | |
| parent | d7e0ebee4d94f10a8b80c1e61bf7b162c6a1ac12 (diff) | |
Use locked_sstream.
Diffstat (limited to 'src')
| -rw-r--r-- | src/compose.hpp | 32 | ||||
| -rw-r--r-- | src/raw_convert.h | 4 | ||||
| -rw-r--r-- | src/smpte_dcp_reader.cc | 1 | ||||
| -rw-r--r-- | src/ssa_reader.cc | 5 | ||||
| -rw-r--r-- | src/stl_binary_writer.cc | 2 | ||||
| -rw-r--r-- | src/subrip_reader.cc | 4 | ||||
| -rw-r--r-- | src/util.cc | 5 | ||||
| -rw-r--r-- | src/util.h | 4 |
8 files changed, 28 insertions, 29 deletions
diff --git a/src/compose.hpp b/src/compose.hpp index b3f410c..ebabe67 100644 --- a/src/compose.hpp +++ b/src/compose.hpp @@ -33,7 +33,7 @@ #ifndef STRING_COMPOSE_H #define STRING_COMPOSE_H -#include <sstream> +#include <locked_sstream.h> #include <string> #include <list> #include <map> // for multimap @@ -56,7 +56,7 @@ namespace StringPrivate std::string str() const; private: - std::ostringstream os; + locked_stringstream os; int arg_no; // we store the output as a list - when the output string is requested, the @@ -104,7 +104,7 @@ namespace StringPrivate case '8': case '9': return true; - + default: return false; } @@ -118,21 +118,21 @@ namespace StringPrivate os << obj; std::string rep = os.str(); - + if (!rep.empty()) { // manipulators don't produce output for (specification_map::const_iterator i = specs.lower_bound(arg_no), end = specs.upper_bound(arg_no); i != end; ++i) { output_list::iterator pos = i->second; ++pos; - + output.insert(pos, rep); } - + os.str(std::string()); //os.clear(); ++arg_no; } - + return *this; } @@ -140,7 +140,7 @@ namespace StringPrivate : arg_no(1) { std::string::size_type b = 0, i = 0; - + // fill in output with the strings between the %1 %2 %3 etc. and // fill in specs with the positions while (i < fmt.length()) { @@ -152,7 +152,7 @@ namespace StringPrivate else if (is_number(fmt[i + 1])) { // aha! a spec! // save string output.push_back(fmt.substr(b, i - b)); - + int n = 1; // number of digits int spec_no = 0; @@ -165,9 +165,9 @@ namespace StringPrivate spec_no /= 10; output_list::iterator pos = output.end(); --pos; // safe since we have just inserted a string> - + specs.insert(specification_map::value_type(spec_no, pos)); - + // jump over spec string i += n; b = i; @@ -178,7 +178,7 @@ namespace StringPrivate else ++i; } - + if (i - b > 0) // add the rest of the string output.push_back(fmt.substr(b, i - b)); } @@ -187,17 +187,17 @@ namespace StringPrivate { // assemble string std::string str; - + for (output_list::const_iterator i = output.begin(), end = output.end(); i != end; ++i) str += *i; - + return str; } } // now for the real thing(s) -namespace String +namespace String { // a series of functions which accept a format string on the form "text %1 // more %2 less %3" and a number of templated parameters and spits out the @@ -308,7 +308,7 @@ namespace String .arg(o10); return c.str(); } - + template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11> diff --git a/src/raw_convert.h b/src/raw_convert.h index 6b9b68f..3afb8f7 100644 --- a/src/raw_convert.h +++ b/src/raw_convert.h @@ -20,7 +20,7 @@ #ifndef LIBSUB_RAW_CONVERT_H #define LIBSUB_RAW_CONVERT_H -#include <sstream> +#include <locked_sstream.h> #include <iomanip> namespace sub { @@ -32,7 +32,7 @@ template <typename P, typename Q> P raw_convert (Q v, int precision = 16) { - std::stringstream s; + locked_stringstream s; s.imbue (std::locale::classic ()); s << std::setprecision (precision); s << v; diff --git a/src/smpte_dcp_reader.cc b/src/smpte_dcp_reader.cc index d8cb875..7a3d94c 100644 --- a/src/smpte_dcp_reader.cc +++ b/src/smpte_dcp_reader.cc @@ -29,7 +29,6 @@ using std::string; using std::list; -using std::stringstream; using boost::shared_ptr; using namespace sub; diff --git a/src/ssa_reader.cc b/src/ssa_reader.cc index 58d2e7c..147f1ba 100644 --- a/src/ssa_reader.cc +++ b/src/ssa_reader.cc @@ -22,15 +22,14 @@ #include "sub_assert.h" #include "raw_convert.h" #include "subtitle.h" +#include <locked_sstream.h> #include <boost/algorithm/string.hpp> #include <boost/bind.hpp> #include <boost/foreach.hpp> -#include <sstream> #include <iostream> #include <vector> using std::string; -using std::stringstream; using std::vector; using std::map; using std::cout; @@ -43,7 +42,7 @@ using namespace sub; /** @param s Subtitle string encoded in UTF-8 */ SSAReader::SSAReader (string const & s) { - stringstream str (s); + locked_stringstream str (s); this->read (boost::bind (&get_line_stringstream, &str)); } diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc index aa8943c..f1afa2c 100644 --- a/src/stl_binary_writer.cc +++ b/src/stl_binary_writer.cc @@ -72,7 +72,7 @@ put_string (char* p, unsigned int n, string s) static void put_int_as_string (char* p, int v, unsigned int n) { - std::stringstream s; + locked_stringstream s; /* Be careful to ensure we get no thousands separators */ s.imbue (std::locale::classic ()); s << setw (n) << setfill ('0'); diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc index e5f113d..94a48c0 100644 --- a/src/subrip_reader.cc +++ b/src/subrip_reader.cc @@ -24,6 +24,7 @@ #include "subrip_reader.h" #include "exceptions.h" #include "util.h" +#include <locked_sstream.h> #include <boost/algorithm/string.hpp> #include <boost/lexical_cast.hpp> #include <boost/regex.hpp> @@ -37,7 +38,6 @@ using std::vector; using std::list; using std::cout; using std::hex; -using std::stringstream; using boost::lexical_cast; using boost::to_upper; using boost::optional; @@ -47,7 +47,7 @@ using namespace sub; /** @param s Subtitle string encoded in UTF-8 */ SubripReader::SubripReader (string const & s) { - stringstream str (s); + locked_stringstream str (s); this->read (boost::bind (&get_line_stringstream, &str)); } diff --git a/src/util.cc b/src/util.cc index 66490c1..57f5e1c 100644 --- a/src/util.cc +++ b/src/util.cc @@ -18,13 +18,12 @@ */ #include "util.h" +#include <locked_sstream.h> #include <string> -#include <sstream> #include <iostream> #include <cstdio> using std::string; -using std::stringstream; using std::getline; using boost::optional; @@ -44,7 +43,7 @@ sub::empty_or_white_space (string s) } optional<string> -sub::get_line_stringstream (stringstream* str) +sub::get_line_stringstream (locked_stringstream* str) { if (!str->good ()) { return optional<string> (); @@ -20,11 +20,13 @@ #include <boost/optional.hpp> #include <string> +class locked_stringstream; + namespace sub { extern bool empty_or_white_space (std::string s); extern void remove_unicode_bom (boost::optional<std::string>& line); -extern boost::optional<std::string> get_line_stringstream (std::stringstream* str); +extern boost::optional<std::string> get_line_stringstream (locked_stringstream* str); extern boost::optional<std::string> get_line_file (FILE* f); } |
