#ifndef STRING_COMPOSE_H
#define STRING_COMPOSE_H
-#include <sstream>
+#include <locked_sstream.h>
#include <string>
#include <list>
#include <map> // for multimap
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
case '8':
case '9':
return true;
-
+
default:
return false;
}
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;
}
: 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()) {
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;
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;
else
++i;
}
-
+
if (i - b > 0) // add the rest of the string
output.push_back(fmt.substr(b, i - b));
}
{
// 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
.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>
#ifndef LIBSUB_RAW_CONVERT_H
#define LIBSUB_RAW_CONVERT_H
-#include <sstream>
+#include <locked_sstream.h>
#include <iomanip>
namespace sub {
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;
using std::string;
using std::list;
-using std::stringstream;
using boost::shared_ptr;
using namespace sub;
#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;
/** @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));
}
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');
#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>
using std::list;
using std::cout;
using std::hex;
-using std::stringstream;
using boost::lexical_cast;
using boost::to_upper;
using boost::optional;
/** @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));
}
*/
#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;
}
optional<string>
-sub::get_line_stringstream (stringstream* str)
+sub::get_line_stringstream (locked_stringstream* str)
{
if (!str->good ()) {
return optional<string> ();
#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);
}
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE libsub_test
+#include <locked_sstream.h>
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
#include <fstream>
using std::hex;
using std::ifstream;
using std::getline;
-using std::stringstream;
boost::filesystem::path private_test;
BOOST_CHECK_EQUAL (r, this_time);
for (uintmax_t i = 0; i < this_time; ++i) {
- stringstream s;
+ locked_stringstream s;
s << "Files differ at offset " << (offset + i)
<< "; reference is " << hex << ((int) ref_buffer[i])
<< ", check is " << hex << ((int) check_buffer[i]);