-/* Defines String::compose(fmt, arg...) for easy, i18n-friendly
+/* -*- c-basic-offset: 2 -*-
+ * Defines String::compose(fmt, arg...) for easy, i18n-friendly
* composition of strings.
*
* Version 1.0.
#ifndef STRING_COMPOSE_H
#define STRING_COMPOSE_H
-#include <locked_sstream.h>
+#include "locale_convert.h"
+#include <boost/filesystem.hpp>
#include <string>
#include <list>
-#include <map> // for multimap
+#include <map>
+#include <inttypes.h>
+#include <cstdio>
namespace StringPrivate
{
std::string str() const;
private:
- locked_stringstream os;
+ std::string os;
int arg_no;
// we store the output as a list - when the output string is requested, the
}
}
-
// implementation of class Composition
template <typename T>
inline Composition &Composition::arg(const T &obj)
{
- os << obj;
-
- std::string rep = os.str();
+ os += sub::locale_convert<std::string>(obj);
- 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) {
+ if (!os.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);
+ output.insert(pos, os);
}
- os.str(std::string());
- //os.clear();
+ os = "";
++arg_no;
}
/*
- Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
P
raw_convert (Q v, int precision = 16)
{
- locked_stringstream s;
- s.imbue (std::locale::classic ());
- s << std::setprecision (precision);
- s << v;
- P r;
- s >> r;
- return r;
+ /* We can't write a generic version of raw_convert; all required
+ versions must be specialised.
+ */
+ BOOST_STATIC_ASSERT (sizeof (Q) == 0);
}
+template <>
+int
+raw_convert (std::string v, int);
+
+template <>
+float
+raw_convert (std::string v, int);
+
+template <>
+std::string
+raw_convert (unsigned long v, int);
+
};
#endif
/*
- Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2016-2019 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#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>
using namespace sub;
/** @param s Subtitle string encoded in UTF-8 */
-SSAReader::SSAReader (string const & s)
+SSAReader::SSAReader (string s)
{
- locked_stringstream str (s);
- this->read (boost::bind (&get_line_stringstream, &str));
+ this->read (boost::bind(&get_line_string, &s));
}
/** @param f Subtitle file encoded in UTF-8 */
{
public:
SSAReader (FILE* f);
- SSAReader (std::string const & subs);
+ SSAReader (std::string subs);
static std::list<RawSubtitle> parse_line (RawSubtitle base, std::string line, int play_res_x, int play_res_y);
#include "compose.hpp"
#include "sub_assert.h"
#include <boost/locale.hpp>
+#include <boost/algorithm/string.hpp>
#include <list>
#include <cmath>
#include <fstream>
memset (p + s.length(), ' ', n - s.length ());
}
+/** @param v Value
+ * @param n Width to zero-pad v to.
+ */
static void
put_int_as_string (char* p, int v, unsigned int n)
{
- locked_stringstream s;
- /* Be careful to ensure we get no thousands separators */
- s.imbue (std::locale::classic ());
- s << setw (n) << setfill ('0');
- s << v;
- SUB_ASSERT (s.str().length() == n);
- put_string (p, s.str ());
+ char buffer[64];
+
+ switch (n) {
+ case 2:
+ snprintf (buffer, sizeof(buffer), "%02d", v);
+ break;
+ case 5:
+ snprintf (buffer, sizeof(buffer), "%05d", v);
+ break;
+ default:
+ SUB_ASSERT (false);
+ }
+
+ string s = buffer;
+
+ struct lconv* lc = localeconv ();
+ boost::algorithm::replace_all (s, lc->thousands_sep, "");
+ boost::algorithm::replace_all (s, lc->decimal_point, ".");
+
+ put_string (p, s);
}
static void
#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 namespace sub;
/** @param s Subtitle string encoded in UTF-8 */
-SubripReader::SubripReader (string const & s)
+SubripReader::SubripReader (string s)
{
- locked_stringstream str (s);
- this->read (boost::bind (&get_line_stringstream, &str));
+ this->read (boost::bind(&get_line_string, &s));
}
/** @param f Subtitle file encoded in UTF-8 */
/*
- Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
{
public:
SubripReader (FILE* f);
- SubripReader (std::string const & subs);
+ SubripReader (std::string subs);
private:
/* For tests */
*/
#include "util.h"
-#include <locked_sstream.h>
#include <string>
#include <iostream>
#include <cstdio>
}
optional<string>
-sub::get_line_stringstream (locked_stringstream* str)
+sub::get_line_string (string* s)
{
- if (!str->good ()) {
- return optional<string> ();
+ if (s->length() == 0) {
+ return optional<string>();
+ }
+
+ size_t pos = s->find ("\n");
+ if (pos == string::npos) {
+ string const c = *s;
+ *s = "";
+ return c;
}
- string s;
- getline (*str, s);
- return s;
+ string const c = s->substr (0, pos);
+ s->erase (0, pos + 1);
+ return c;
}
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 (locked_stringstream* str);
extern boost::optional<std::string> get_line_file (FILE* f);
+extern boost::optional<std::string> get_line_string (std::string* s);
}
horizontal_position.cc
iso6937.cc
iso6937_tables.cc
+ locale_convert.cc
rational.cc
+ raw_convert.cc
raw_subtitle.cc
reader.cc
reader_factory.cc
/*
- Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE libsub_test
-#include <locked_sstream.h>
+#include "iso6937_tables.h"
+#include "compose.hpp"
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
#include <fstream>
#include <string>
#include <iostream>
-#include "iso6937_tables.h"
using std::string;
using std::cerr;
BOOST_CHECK_EQUAL (r, this_time);
for (uintmax_t i = 0; i < this_time; ++i) {
- locked_stringstream s;
- s << "Files differ at offset " << (offset + i)
- << "; reference is " << hex << ((int) ref_buffer[i])
- << ", check is " << hex << ((int) check_buffer[i]);
-
- BOOST_CHECK_MESSAGE (ref_buffer[i] == check_buffer[i], s.str ());
+ string const s = String::compose (
+ "Files differ at offset %1; reference is %2, check is %3", (offset + i), ((int) ref_buffer[i]), ((int) check_buffer[i])
+ );
+ BOOST_CHECK_MESSAGE (ref_buffer[i] == check_buffer[i], s);
}
offset += this_time;
conf.env.DISABLE_TESTS = conf.options.disable_tests
conf.env.API_VERSION = API_VERSION
+ if conf.options.target_windows:
+ conf.env.append_value('CXXFLAGS', '-DLIBSUB_WINDOWS')
+ else:
+ conf.env.append_value('CXXFLAGS', '-DLIBSUB_POSIX')
+
if conf.options.enable_debug:
conf.env.append_value('CXXFLAGS', '-g')
else: