replace a few string algorithms with boost utilities
This commit is contained in:
@@ -88,6 +88,14 @@ dnl =============================
|
||||
AS_IF([test -z "${BOOST_LIB_SUFFIX+x}"], [BOOST_LIB_SUFFIX=-mt])
|
||||
AC_ARG_VAR([BOOST_LIB_SUFFIX], [Boost library name suffix [default=-mt]])
|
||||
|
||||
dnl ======================================
|
||||
dnl = checking for various boost headers =
|
||||
dnl ======================================
|
||||
AC_CHECK_HEADERS([boost/lexical_cast.hpp], ,
|
||||
AC_MSG_ERROR(boost/lexical_cast.hpp is missing))
|
||||
AC_CHECK_HEADERS([boost/algorithm/string.hpp], ,
|
||||
AC_MSG_ERROR(boost/algorithm/string.hpp is missing))
|
||||
|
||||
dnl =============================
|
||||
dnl = checking for boost.locale =
|
||||
dnl =============================
|
||||
|
||||
@@ -58,7 +58,6 @@ noinst_HEADERS = \
|
||||
utility/comparators.h \
|
||||
utility/html.h \
|
||||
utility/string.h \
|
||||
utility/numeric_conversions.h \
|
||||
utility/type_conversions.h \
|
||||
utility/wide_string.h \
|
||||
bindings.h \
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include <cassert>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <boost/locale/conversion.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
@@ -1192,7 +1194,7 @@ void SetCrossfade::run()
|
||||
Statusbar::put() << "Set crossfade to: ";
|
||||
std::string crossfade = wFooter->getString(3);
|
||||
Statusbar::unlock();
|
||||
int cf = stringToInt(crossfade);
|
||||
int cf = boost::lexical_cast<int>(crossfade);
|
||||
if (cf > 0)
|
||||
{
|
||||
Config.crossfade_time = cf;
|
||||
@@ -1503,11 +1505,11 @@ void ToggleScreenLock::run()
|
||||
{
|
||||
Statusbar::lock();
|
||||
Statusbar::put() << "% of the locked screen's width to be reserved (20-80): ";
|
||||
std::string str_part = wFooter->getString(intTo<std::string>::apply(Config.locked_screen_width_part*100));
|
||||
std::string str_part = wFooter->getString(boost::lexical_cast<std::string>(Config.locked_screen_width_part*100));
|
||||
Statusbar::unlock();
|
||||
if (str_part.empty())
|
||||
return;
|
||||
part = stringToInt(str_part);
|
||||
part = boost::lexical_cast<int>(str_part);
|
||||
}
|
||||
if (part < 20 || part > 80)
|
||||
{
|
||||
@@ -1562,7 +1564,8 @@ void JumpToPositionInSong::run()
|
||||
int newpos = 0;
|
||||
if (position.find(':') != std::string::npos) // probably time in mm:ss
|
||||
{
|
||||
newpos = stringToInt(position)*60 + stringToInt(position.substr(position.find(':')+1));
|
||||
newpos = boost::lexical_cast<int>(position)*60
|
||||
+ boost::lexical_cast<int>(position.substr(position.find(':')+1));
|
||||
if (newpos >= 0 && newpos <= Mpd.GetTotalTime())
|
||||
Mpd.Seek(newpos);
|
||||
else
|
||||
@@ -1570,7 +1573,7 @@ void JumpToPositionInSong::run()
|
||||
}
|
||||
else if (position.find('s') != std::string::npos) // probably position in seconds
|
||||
{
|
||||
newpos = stringToInt(position);
|
||||
newpos = boost::lexical_cast<int>(position);
|
||||
if (newpos >= 0 && newpos <= Mpd.GetTotalTime())
|
||||
Mpd.Seek(newpos);
|
||||
else
|
||||
@@ -1578,7 +1581,7 @@ void JumpToPositionInSong::run()
|
||||
}
|
||||
else
|
||||
{
|
||||
newpos = stringToInt(position);
|
||||
newpos = boost::lexical_cast<int>(position);
|
||||
if (newpos >= 0 && newpos <= 100)
|
||||
Mpd.Seek(Mpd.GetTotalTime()*newpos/100.0);
|
||||
else
|
||||
@@ -1934,14 +1937,14 @@ void AddRandomItems::run()
|
||||
if (answer != 's')
|
||||
{
|
||||
tag_type = charToTagType(answer);
|
||||
tag_type_str = lowercase(tagTypeToString(tag_type));
|
||||
tag_type_str = boost::locale::to_lower(tagTypeToString(tag_type));
|
||||
}
|
||||
else
|
||||
tag_type_str = "song";
|
||||
|
||||
Statusbar::lock();
|
||||
Statusbar::put() << "Number of random " << tag_type_str << "s: ";
|
||||
size_t number = stringToLongInt(wFooter->getString());
|
||||
size_t number = boost::lexical_cast<size_t>(wFooter->getString());
|
||||
Statusbar::unlock();
|
||||
if (number && (answer == 's' ? Mpd.AddRandomSongs(number) : Mpd.AddRandomTag(tag_type, number)))
|
||||
Statusbar::msg("%zu random %s%s added to playlist", number, tag_type_str.c_str(), number == 1 ? "" : "s");
|
||||
@@ -2005,7 +2008,7 @@ void ToggleLibraryTagType::run()
|
||||
std::string item_type = tagTypeToString(Config.media_lib_primary_tag);
|
||||
myLibrary->Tags.setTitle(Config.titles_visibility ? item_type + "s" : "");
|
||||
myLibrary->Tags.reset();
|
||||
item_type = lowercase(item_type);
|
||||
item_type = boost::locale::to_lower(item_type);
|
||||
std::string and_mtime = Config.media_library_sort_by_mtime ?
|
||||
" and mtime" :
|
||||
"";
|
||||
@@ -2088,7 +2091,7 @@ void SetSelectedItemsPriority::run()
|
||||
Statusbar::unlock();
|
||||
if (!isInteger(strprio.c_str(), true))
|
||||
return;
|
||||
int prio = stringToInt(strprio);
|
||||
int prio = boost::lexical_cast<int>(strprio);
|
||||
if (prio < 0 || prio > 255)
|
||||
{
|
||||
Statusbar::msg("Number is out of range");
|
||||
@@ -2112,7 +2115,7 @@ void FilterPlaylistOnPriorities::run()
|
||||
Statusbar::unlock();
|
||||
if (!isInteger(strprio.c_str(), false))
|
||||
return;
|
||||
unsigned prio = stringToInt(strprio);
|
||||
unsigned prio = boost::lexical_cast<unsigned>(strprio);
|
||||
myPlaylist->main().filter(myPlaylist->main().begin(), myPlaylist->main().end(),
|
||||
[prio](const NC::Menu<MPD::Song>::Item &s) {
|
||||
return s.value().getPrio() > prio;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "global.h"
|
||||
@@ -312,7 +313,7 @@ bool BindingsConfiguration::read(const std::string &file)
|
||||
}
|
||||
else if (isspace(line[0])) // name of action to be bound
|
||||
{
|
||||
trim(line);
|
||||
boost::trim(line);
|
||||
auto action = parseActionLine(line, error);
|
||||
if (action)
|
||||
actions.push_back(action);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <boost/locale/conversion.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
#include "browser.h"
|
||||
@@ -32,14 +33,15 @@
|
||||
#include "helpers.h"
|
||||
#include "playlist.h"
|
||||
#include "regex_filter.h"
|
||||
#include "screen_switcher.h"
|
||||
#include "settings.h"
|
||||
#include "status.h"
|
||||
#include "statusbar.h"
|
||||
#include "tag_editor.h"
|
||||
#include "utility/comparators.h"
|
||||
#include "title.h"
|
||||
#include "tags.h"
|
||||
#include "screen_switcher.h"
|
||||
#include "utility/comparators.h"
|
||||
#include "utility/string.h"
|
||||
|
||||
using namespace std::placeholders;
|
||||
|
||||
@@ -587,7 +589,7 @@ bool hasSupportedExtension(const std::string &file)
|
||||
if (last_dot > file.length())
|
||||
return false;
|
||||
|
||||
std::string ext = lowercase(file.substr(last_dot+1));
|
||||
std::string ext = boost::locale::to_lower(file.substr(last_dot+1));
|
||||
return SupportedExtensions.find(ext) != SupportedExtensions.end();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include "actions.h"
|
||||
@@ -181,12 +182,13 @@ void ParseArgv(int argc, char **argv)
|
||||
now_playing_format = "{";
|
||||
now_playing_format += argv[i];
|
||||
now_playing_format += "}";
|
||||
replace(now_playing_format, "\\n", "\n");
|
||||
replace(now_playing_format, "\\t", "\t");
|
||||
boost::replace_all(now_playing_format, "\\n", "\n");
|
||||
boost::replace_all(now_playing_format, "\\t", "\t");
|
||||
}
|
||||
}
|
||||
std::cout << Charset::utf8ToLocale(
|
||||
Mpd.GetCurrentlyPlayingSong().toString(now_playing_format, Config.tags_separator)) << "\n";
|
||||
std::string np = Mpd.GetCurrentlyPlayingSong().toString(
|
||||
now_playing_format, Config.tags_separator);
|
||||
std::cout << Charset::utf8ToLocale(np) << "\n";
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "playlist.h"
|
||||
#include "global.h"
|
||||
#include "tag_editor.h"
|
||||
#include "utility/string.h"
|
||||
#include "utility/type_conversions.h"
|
||||
|
||||
using Global::myScreen;
|
||||
|
||||
@@ -75,7 +75,7 @@ std::string keyToString(const Key &key, bool *print_backspace)
|
||||
else if (key >= Key(KEY_F1, Key::NCurses) && key <= Key(KEY_F12, Key::NCurses))
|
||||
{
|
||||
result += "F";
|
||||
result += intTo<std::string>::apply(key.getChar()-264);
|
||||
result += boost::lexical_cast<std::string>(key.getChar()-264);
|
||||
}
|
||||
else if ((key == Key(KEY_BACKSPACE, Key::NCurses) || key == Key(KEY_BACKSPACE_2, Key::Standard)))
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "screen.h"
|
||||
#include "settings.h"
|
||||
#include "status.h"
|
||||
#include "utility/string.h"
|
||||
#include "utility/wide_string.h"
|
||||
|
||||
inline HasColumns *hasColumns(BaseScreen *screen)
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <cassert>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <boost/locale/conversion.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
@@ -41,6 +42,7 @@
|
||||
#include "statusbar.h"
|
||||
#include "title.h"
|
||||
#include "screen_switcher.h"
|
||||
#include "utility/string.h"
|
||||
|
||||
using Global::MainHeight;
|
||||
using Global::MainStartY;
|
||||
@@ -112,7 +114,7 @@ void Lastfm::Load()
|
||||
w.reset();
|
||||
|
||||
std::string artist = itsArgs.find("artist")->second;
|
||||
std::string file = lowercase(artist + ".txt");
|
||||
std::string file = boost::locale::to_lower(artist + ".txt");
|
||||
removeInvalidCharsFromFilename(file);
|
||||
|
||||
itsFilename = itsFolder + "/" + file;
|
||||
|
||||
@@ -22,9 +22,11 @@
|
||||
|
||||
#ifdef HAVE_CURL_CURL_H
|
||||
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include "curl_handle.h"
|
||||
#include "settings.h"
|
||||
#include "utility/html.h"
|
||||
#include "utility/string.h"
|
||||
|
||||
const char *LastfmService::baseURL = "http://ws.audioscrobbler.com/2.0/?api_key=d94e5b6e26469a2d1ffae8ef20131b79&method=";
|
||||
|
||||
@@ -92,7 +94,7 @@ bool LastfmService::actionFailed(const std::string &data)
|
||||
void LastfmService::postProcess(std::string &data)
|
||||
{
|
||||
stripHtmlTags(data);
|
||||
trim(data);
|
||||
boost::trim(data);
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "statusbar.h"
|
||||
#include "title.h"
|
||||
#include "screen_switcher.h"
|
||||
#include "utility/string.h"
|
||||
|
||||
using Global::MainHeight;
|
||||
using Global::MainStartY;
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
|
||||
#include "charset.h"
|
||||
#include "lyrics_fetcher.h"
|
||||
@@ -55,8 +57,8 @@ LyricsFetcher::Result LyricsFetcher::fetch(const std::string &artist, const std:
|
||||
result.first = false;
|
||||
|
||||
std::string url = getURL();
|
||||
replace(url, "%artist%", artist.c_str());
|
||||
replace(url, "%title%", title.c_str());
|
||||
boost::replace_all(url, "%artist%", artist.c_str());
|
||||
boost::replace_all(url, "%title%", title.c_str());
|
||||
|
||||
std::string data;
|
||||
CURLcode code = Curl::perform(data, url);
|
||||
@@ -101,7 +103,7 @@ bool LyricsFetcher::getContent(const char *open_tag, const char *close_tag, std:
|
||||
void LyricsFetcher::postProcess(std::string &data)
|
||||
{
|
||||
stripHtmlTags(data);
|
||||
trim(data);
|
||||
boost::trim(data);
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -136,9 +138,9 @@ LyricsFetcher::Result LyricwikiFetcher::fetch(const std::string &artist, const s
|
||||
return result;
|
||||
}
|
||||
|
||||
replace(data, "<br />", "\n");
|
||||
boost::replace_all(data, "<br />", "\n");
|
||||
stripHtmlTags(data);
|
||||
trim(data);
|
||||
boost::trim(data);
|
||||
|
||||
result.second = data;
|
||||
result.first = true;
|
||||
@@ -227,8 +229,8 @@ void MetrolyricsFetcher::postProcess(std::string &data)
|
||||
// some of lyrics have both \n chars and <br />, html tags
|
||||
// are always present whereas \n chars are not, so we need to
|
||||
// throw them away to avoid having line breaks doubled.
|
||||
replace(data, " ", "");
|
||||
replace(data, "<br />", "\n");
|
||||
boost::replace_all(data, " ", "");
|
||||
boost::replace_all(data, "<br />", "\n");
|
||||
data = unescapeHtmlUtf8(data);
|
||||
LyricsFetcher::postProcess(data);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <boost/locale/conversion.hpp>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
@@ -809,7 +810,8 @@ void MediaLibrary::toggleColumnsMode()
|
||||
nextColumn();
|
||||
if (Config.titles_visibility)
|
||||
{
|
||||
std::string item_type = lowercase(tagTypeToString(Config.media_lib_primary_tag));
|
||||
std::string item_type = boost::locale::to_lower(
|
||||
tagTypeToString(Config.media_lib_primary_tag));
|
||||
std::string and_mtime = Config.media_library_sort_by_mtime ? " and mtime" : "";
|
||||
Albums.setTitle("Albums (sorted by " + item_type + and_mtime + ")");
|
||||
}
|
||||
@@ -846,7 +848,8 @@ void MediaLibrary::toggleSortMode()
|
||||
Songs.clear();
|
||||
if (Config.titles_visibility)
|
||||
{
|
||||
std::string item_type = lowercase(tagTypeToString(Config.media_lib_primary_tag));
|
||||
std::string item_type = boost::locale::to_lower(
|
||||
tagTypeToString(Config.media_lib_primary_tag));
|
||||
std::string and_mtime = Config.media_library_sort_by_mtime ? " and mtime" : "";
|
||||
Albums.setTitle("Albums (sorted by " + item_type + and_mtime + ")");
|
||||
}
|
||||
@@ -887,7 +890,8 @@ void MediaLibrary::LocateSong(const MPD::Song &s)
|
||||
}
|
||||
if (primary_tag.empty())
|
||||
{
|
||||
std::string item_type = lowercase(tagTypeToString(Config.media_lib_primary_tag));
|
||||
std::string item_type = boost::locale::to_lower(
|
||||
tagTypeToString(Config.media_lib_primary_tag));
|
||||
Statusbar::msg("Can't use this function because the song has no %s tag set", item_type.c_str());
|
||||
return;
|
||||
}
|
||||
@@ -975,7 +979,8 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
|
||||
if ((!Tags.empty() && isActiveWindow(Tags))
|
||||
|| (isActiveWindow(Albums) && Albums.current().value().isAllTracksEntry()))
|
||||
{
|
||||
std::string tag_type = lowercase(tagTypeToString(Config.media_lib_primary_tag));
|
||||
std::string tag_type = boost::locale::to_lower(
|
||||
tagTypeToString(Config.media_lib_primary_tag));
|
||||
Statusbar::msg("Songs with %s = \"%s\" added", tag_type.c_str(), Tags.current().value().tag().c_str());
|
||||
}
|
||||
else if (isActiveWindow(Albums))
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include "mutable_song.h"
|
||||
#include "utility/string.h"
|
||||
|
||||
namespace MPD {//
|
||||
|
||||
@@ -168,7 +168,8 @@ void MutableSong::setDuration(unsigned int duration)
|
||||
|
||||
void MutableSong::setTags(SetFunction set, const std::string &value, const std::string &delimiter)
|
||||
{
|
||||
auto tags = split(value, delimiter);
|
||||
std::vector<std::string> tags;
|
||||
boost::iter_split(tags, value, boost::first_finder(delimiter));
|
||||
size_t i = 0;
|
||||
for (; i < tags.size(); ++i)
|
||||
(this->*set)(tags[i], i);
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "charset.h"
|
||||
#include "cmdargs.h"
|
||||
#include "global.h"
|
||||
#include "error.h"
|
||||
#include "helpers.h"
|
||||
#include "lyrics.h"
|
||||
#include "playlist.h"
|
||||
@@ -46,6 +47,15 @@
|
||||
#include "visualizer.h"
|
||||
#include "title.h"
|
||||
|
||||
namespace boost {//
|
||||
|
||||
void throw_exception(const std::exception &e)
|
||||
{
|
||||
FatalError(std::string("Exception thrown: ") + e.what());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
std::ofstream errorlog;
|
||||
|
||||
@@ -171,7 +171,7 @@ void PlaylistEditor::update()
|
||||
{
|
||||
title = "Playlist content";
|
||||
title += " (";
|
||||
title += unsignedLongIntTo<std::string>::apply(Content.size());
|
||||
title += boost::lexical_cast<std::string>(Content.size());
|
||||
title += " item";
|
||||
if (Content.size() == 1)
|
||||
title += ")";
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
# include <sys/stat.h>
|
||||
#endif // WIN32
|
||||
#include <algorithm>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
@@ -101,7 +102,7 @@ namespace
|
||||
if (equal == std::string::npos)
|
||||
return "";
|
||||
std::string result = s.substr(0, equal);
|
||||
trim(result);
|
||||
boost::trim(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -346,33 +347,33 @@ void Configuration::Read()
|
||||
}
|
||||
else if (name == "mpd_port")
|
||||
{
|
||||
if (stringToInt(v))
|
||||
mpd_port = stringToInt(v);
|
||||
if (boost::lexical_cast<int>(v))
|
||||
mpd_port = boost::lexical_cast<int>(v);
|
||||
}
|
||||
else if (name == "mpd_connection_timeout")
|
||||
{
|
||||
if (stringToInt(v))
|
||||
mpd_connection_timeout = stringToInt(v);
|
||||
if (boost::lexical_cast<int>(v))
|
||||
mpd_connection_timeout = boost::lexical_cast<int>(v);
|
||||
}
|
||||
else if (name == "mpd_crossfade_time")
|
||||
{
|
||||
if (stringToInt(v) > 0)
|
||||
crossfade_time = stringToInt(v);
|
||||
if (boost::lexical_cast<int>(v) > 0)
|
||||
crossfade_time = boost::lexical_cast<int>(v);
|
||||
}
|
||||
else if (name == "seek_time")
|
||||
{
|
||||
if (stringToInt(v) > 0)
|
||||
seek_time = stringToInt(v);
|
||||
if (boost::lexical_cast<int>(v) > 0)
|
||||
seek_time = boost::lexical_cast<int>(v);
|
||||
}
|
||||
else if (name == "playlist_disable_highlight_delay")
|
||||
{
|
||||
if (stringToInt(v) >= 0)
|
||||
playlist_disable_highlight_delay = stringToInt(v);
|
||||
if (boost::lexical_cast<int>(v) >= 0)
|
||||
playlist_disable_highlight_delay = boost::lexical_cast<int>(v);
|
||||
}
|
||||
else if (name == "message_delay_time")
|
||||
{
|
||||
if (stringToInt(v) > 0)
|
||||
message_delay_time = stringToInt(v);
|
||||
if (boost::lexical_cast<int>(v) > 0)
|
||||
message_delay_time = boost::lexical_cast<int>(v);
|
||||
}
|
||||
else if (name == "song_list_format")
|
||||
{
|
||||
@@ -775,20 +776,20 @@ void Configuration::Read()
|
||||
else if (name == "lines_scrolled")
|
||||
{
|
||||
if (!v.empty())
|
||||
lines_scrolled = stringToInt(v);
|
||||
lines_scrolled = boost::lexical_cast<int>(v);
|
||||
}
|
||||
else if (name == "search_engine_default_search_mode")
|
||||
{
|
||||
if (!v.empty())
|
||||
{
|
||||
unsigned mode = stringToInt(v);
|
||||
unsigned mode = boost::lexical_cast<unsigned>(v);
|
||||
if (--mode < 3)
|
||||
search_engine_default_search_mode = mode;
|
||||
}
|
||||
}
|
||||
else if (name == "visualizer_sync_interval")
|
||||
{
|
||||
unsigned interval = stringToInt(v);
|
||||
unsigned interval = boost::lexical_cast<unsigned>(v);
|
||||
if (interval)
|
||||
visualizer_sync_interval = interval;
|
||||
}
|
||||
@@ -803,7 +804,7 @@ void Configuration::Read()
|
||||
}
|
||||
else if (name == "locked_screen_width_part")
|
||||
{
|
||||
int part = stringToInt(v);
|
||||
int part = boost::lexical_cast<int>(v);
|
||||
if (part)
|
||||
locked_screen_width_part = part/100.0;
|
||||
}
|
||||
@@ -937,7 +938,13 @@ void Configuration::GenerateColumns()
|
||||
col.color = stringToColor(getEnclosedString(song_list_columns_format, '[', ']', &pos));
|
||||
std::string tag_type = getEnclosedString(song_list_columns_format, '{', '}', &pos);
|
||||
|
||||
col.fixed = *width.rbegin() == 'f';
|
||||
if (*width.rbegin() == 'f')
|
||||
{
|
||||
col.fixed = true;
|
||||
width.resize(width.size()-1);
|
||||
}
|
||||
else
|
||||
col.fixed = false;
|
||||
|
||||
// alternative name
|
||||
size_t tag_type_colon_pos = tag_type.find(':');
|
||||
@@ -973,7 +980,7 @@ void Configuration::GenerateColumns()
|
||||
else // empty column
|
||||
col.display_empty_tag = 0;
|
||||
|
||||
col.width = stringToInt(width);
|
||||
col.width = boost::lexical_cast<int>(width);
|
||||
columns.push_back(col);
|
||||
}
|
||||
|
||||
|
||||
11
src/song.cpp
11
src/song.cpp
@@ -20,11 +20,12 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "song.h"
|
||||
#include "utility/numeric_conversions.h"
|
||||
#include "utility/type_conversions.h"
|
||||
#include "utility/wide_string.h"
|
||||
#include "window.h"
|
||||
@@ -193,7 +194,7 @@ std::string Song::getPriority(unsigned idx) const
|
||||
assert(m_song);
|
||||
if (idx > 0)
|
||||
return "";
|
||||
return unsignedIntTo<std::string>::apply(getPrio());
|
||||
return boost::lexical_cast<std::string>(getPrio());
|
||||
}
|
||||
|
||||
std::string MPD::Song::getTags(GetFunction f, const std::string &tags_separator) const
|
||||
@@ -281,9 +282,9 @@ std::string Song::ShowTime(unsigned length)
|
||||
|
||||
std::string result;
|
||||
if (hours > 0)
|
||||
result = print<32, std::string>::apply("%d:%02d:%02d", hours, minutes, seconds);
|
||||
result = (boost::format("%d:%02d:%02d") % hours % minutes % seconds).str();
|
||||
else
|
||||
result = print<32, std::string>::apply("%d:%02d", minutes, seconds);
|
||||
result = (boost::format("%d:%02d") % minutes % seconds).str();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -309,7 +310,7 @@ bool MPD::Song::isFormatOk(const std::string &type, const std::string &fmt)
|
||||
while (isdigit(fmt[++i])) { }
|
||||
if (!charToGetFunction(fmt[i]))
|
||||
{
|
||||
std::cerr << type << ": invalid character at position " << unsignedLongIntTo<std::string>::apply(i+1) << ": '" << fmt[i] << "'\n";
|
||||
std::cerr << type << ": invalid character at position " << boost::lexical_cast<std::string>(i+1) << ": '" << fmt[i] << "'\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "tag_editor.h"
|
||||
#include "visualizer.h"
|
||||
#include "title.h"
|
||||
#include "utility/string.h"
|
||||
|
||||
using Global::myScreen;
|
||||
|
||||
@@ -325,7 +326,7 @@ void Status::Changes::elapsedTime()
|
||||
if (Config.display_bitrate && Mpd.GetBitrate())
|
||||
{
|
||||
tracklength += " ";
|
||||
tracklength += intTo<std::string>::apply(Mpd.GetBitrate());
|
||||
tracklength += boost::lexical_cast<std::string>(Mpd.GetBitrate());
|
||||
tracklength += " kbps";
|
||||
}
|
||||
|
||||
@@ -359,7 +360,7 @@ void Status::Changes::elapsedTime()
|
||||
if (Config.display_bitrate && Mpd.GetBitrate())
|
||||
{
|
||||
tracklength += " [";
|
||||
tracklength += intTo<std::string>::apply(Mpd.GetBitrate());
|
||||
tracklength += boost::lexical_cast<std::string>(Mpd.GetBitrate());
|
||||
tracklength += " kbps]";
|
||||
}
|
||||
tracklength += " [";
|
||||
@@ -498,7 +499,7 @@ void Status::Changes::mixer()
|
||||
VolumeState += "n/a";
|
||||
else
|
||||
{
|
||||
VolumeState += intTo<std::string>::apply(volume);
|
||||
VolumeState += boost::lexical_cast<std::string>(volume);
|
||||
VolumeState += "%";
|
||||
}
|
||||
*wHeader << Config.volume_color;
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#ifndef NCMPCPP_STRBUFFER_H
|
||||
#define NCMPCPP_STRBUFFER_H
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <set>
|
||||
#include "utility/numeric_conversions.h"
|
||||
#include "window.h"
|
||||
|
||||
namespace NC {//
|
||||
@@ -130,25 +130,25 @@ public:
|
||||
|
||||
BasicBuffer<CharT> &operator<<(int n)
|
||||
{
|
||||
m_string += intTo<StringType>::apply(n);
|
||||
m_string += boost::lexical_cast<StringType>(n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
BasicBuffer<CharT> &operator<<(long int n)
|
||||
{
|
||||
m_string += longIntTo<StringType>::apply(n);
|
||||
m_string += boost::lexical_cast<StringType>(n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
BasicBuffer<CharT> &operator<<(unsigned int n)
|
||||
{
|
||||
m_string += unsignedIntTo<StringType>::apply(n);
|
||||
m_string += boost::lexical_cast<StringType>(n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
BasicBuffer<CharT> &operator<<(unsigned long int n)
|
||||
{
|
||||
m_string += unsignedLongIntTo<StringType>::apply(n);
|
||||
m_string += boost::lexical_cast<StringType>(n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#ifdef HAVE_TAGLIB_H
|
||||
|
||||
#include <boost/locale/conversion.hpp>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
@@ -475,9 +476,9 @@ void TagEditor::enterPressed()
|
||||
for (unsigned i = 1; i <= EditedSongs.size(); ++i, ++it)
|
||||
{
|
||||
if (Config.tag_editor_extended_numeration)
|
||||
(*it)->setTrack(unsignedIntTo<std::string>::apply(i) + "/" + unsignedIntTo<std::string>::apply(EditedSongs.size()));
|
||||
(*it)->setTrack(boost::lexical_cast<std::string>(i) + "/" + boost::lexical_cast<std::string>(EditedSongs.size()));
|
||||
else
|
||||
(*it)->setTrack(unsignedIntTo<std::string>::apply(i));
|
||||
(*it)->setTrack(boost::lexical_cast<std::string>(i));
|
||||
}
|
||||
Statusbar::msg("Tracks numbered");
|
||||
}
|
||||
@@ -1034,7 +1035,7 @@ void LowerAllLetters(MPD::MutableSong &s)
|
||||
{
|
||||
unsigned i = 0;
|
||||
for (std::string tag; !(tag = (s.*m->Get)(i)).empty(); ++i)
|
||||
(s.*m->Set)(ToString(lowercase(ToWString(tag))), i);
|
||||
(s.*m->Set)(boost::locale::to_lower(tag), i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1046,7 +1047,7 @@ void GetPatternList()
|
||||
if (input.is_open())
|
||||
{
|
||||
std::string line;
|
||||
while (getline(input, line))
|
||||
while (std::getline(input, line))
|
||||
if (!line.empty())
|
||||
Patterns.push_back(line);
|
||||
input.close();
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
|
||||
#include "global.h"
|
||||
#include "settings.h"
|
||||
#include "utility/numeric_conversions.h"
|
||||
#include "utility/wide_string.h"
|
||||
|
||||
namespace {//
|
||||
@@ -54,8 +53,8 @@ void readCommonTags(MPD::MutableSong &s, TagLib::Tag *tag)
|
||||
s.setTitle(tag->title().to8Bit(true));
|
||||
s.setArtist(tag->artist().to8Bit(true));
|
||||
s.setAlbum(tag->album().to8Bit(true));
|
||||
s.setDate(intTo<std::string>::apply(tag->year()));
|
||||
s.setTrack(intTo<std::string>::apply(tag->track()));
|
||||
s.setDate(boost::lexical_cast<std::string>(tag->year()));
|
||||
s.setTrack(boost::lexical_cast<std::string>(tag->track()));
|
||||
s.setGenre(tag->genre().to8Bit(true));
|
||||
s.setComment(tag->comment().to8Bit(true));
|
||||
}
|
||||
@@ -132,8 +131,8 @@ void writeCommonTags(const MPD::MutableSong &s, TagLib::Tag *tag)
|
||||
tag->setTitle(ToWString(s.getTitle()));
|
||||
tag->setArtist(ToWString(s.getArtist()));
|
||||
tag->setAlbum(ToWString(s.getAlbum()));
|
||||
tag->setYear(stringToInt(s.getDate()));
|
||||
tag->setTrack(stringToInt(s.getTrack()));
|
||||
tag->setYear(boost::lexical_cast<TagLib::uint>(s.getDate()));
|
||||
tag->setTrack(boost::lexical_cast<TagLib::uint>(s.getTrack()));
|
||||
tag->setGenre(ToWString(s.getGenre()));
|
||||
tag->setComment(ToWString(s.getComment()));
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
#ifdef HAVE_TAGLIB_H
|
||||
|
||||
#include <boost/locale/conversion.hpp>
|
||||
|
||||
// taglib includes
|
||||
#include <fileref.h>
|
||||
#include <tag.h>
|
||||
@@ -39,6 +41,7 @@
|
||||
#include "title.h"
|
||||
#include "tags.h"
|
||||
#include "screen_switcher.h"
|
||||
#include "utility/string.h"
|
||||
|
||||
using Global::MainHeight;
|
||||
using Global::MainStartY;
|
||||
@@ -181,7 +184,7 @@ bool TinyTagEditor::getTags()
|
||||
return false;
|
||||
|
||||
std::string ext = itsEdited.getURI();
|
||||
ext = lowercase(ext.substr(ext.rfind(".")+1));
|
||||
ext = boost::locale::to_lower(ext.substr(ext.rfind(".")+1));
|
||||
|
||||
w.clear();
|
||||
w.reset();
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <locale>
|
||||
#include "comparators.h"
|
||||
#include "utility/string.h"
|
||||
|
||||
namespace {//
|
||||
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include "utility/html.h"
|
||||
#include "utility/string.h"
|
||||
//#include "utility/string.h"
|
||||
|
||||
std::string unescapeHtmlUtf8(const std::string &data)
|
||||
{
|
||||
@@ -58,10 +59,10 @@ void stripHtmlTags(std::string &s)
|
||||
size_t j = s.find(">", i)+1;
|
||||
s.replace(i, j-i, "");
|
||||
}
|
||||
replace(s, "'", "'");
|
||||
replace(s, "&", "&");
|
||||
replace(s, """, "\"");
|
||||
replace(s, " ", " ");
|
||||
boost::replace_all(s, "'", "'");
|
||||
boost::replace_all(s, "&", "&");
|
||||
boost::replace_all(s, """, "\"");
|
||||
boost::replace_all(s, " ", " ");
|
||||
for (size_t i = 0; i < s.length(); ++i)
|
||||
{
|
||||
if (erase)
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2008-2012 by Andrzej Rybczak *
|
||||
* electricityispower@gmail.com *
|
||||
* *
|
||||
* 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 *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <string>
|
||||
#include "string.h"
|
||||
|
||||
#ifndef NCMPCPP_UTILITY_NUMERIC_CONVERSIONS_H
|
||||
#define NCMPCPP_UTILITY_NUMERIC_CONVERSIONS_H
|
||||
|
||||
template <typename R> struct intTo { };
|
||||
template <> struct intTo<std::string> {
|
||||
static std::string apply(int n) {
|
||||
return print<32, std::string>::apply("%d", n);
|
||||
}
|
||||
};
|
||||
template <> struct intTo<std::wstring> {
|
||||
static std::wstring apply(int n) {
|
||||
return print<32, std::wstring>::apply(L"%d", n);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename R> struct longIntTo { };
|
||||
template <> struct longIntTo<std::string> {
|
||||
static std::string apply(long int n) {
|
||||
return print<32, std::string>::apply("%ld", n);
|
||||
}
|
||||
};
|
||||
template <> struct longIntTo<std::wstring> {
|
||||
static std::wstring apply(long int n) {
|
||||
return print<32, std::wstring>::apply(L"%ld", n);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename R> struct unsignedIntTo { };
|
||||
template <> struct unsignedIntTo<std::string> {
|
||||
static std::string apply(unsigned int n) {
|
||||
return print<32, std::string>::apply("%u", n);
|
||||
}
|
||||
};
|
||||
template <> struct unsignedIntTo<std::wstring> {
|
||||
static std::wstring apply(unsigned int n) {
|
||||
return print<32, std::wstring>::apply(L"%u", n);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename R> struct unsignedLongIntTo { };
|
||||
template <> struct unsignedLongIntTo<std::string> {
|
||||
static std::string apply(unsigned long int n) {
|
||||
return print<32, std::string>::apply("%lu", n);
|
||||
}
|
||||
};
|
||||
template <> struct unsignedLongIntTo<std::wstring> {
|
||||
static std::wstring apply(unsigned long int n) {
|
||||
return print<32, std::wstring>::apply(L"%lu", n);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // NCMPCPP_UTILITY_NUMERIC_CONVERSIONS_H
|
||||
@@ -31,47 +31,8 @@ template <size_t N> size_t const_strlen(const char (&)[N]) {
|
||||
return N-1;
|
||||
}
|
||||
|
||||
template <size_t N, typename T> struct print { };
|
||||
template <size_t N> struct print<N, std::string> {
|
||||
static std::string apply(const char *format, ...) GNUC_PRINTF(1, 2) {
|
||||
char buf[N];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf(buf, sizeof(buf)/sizeof(char), format, args);
|
||||
va_end(args);
|
||||
return buf;
|
||||
}
|
||||
};
|
||||
template <size_t N> struct print<N, std::wstring> {
|
||||
static std::wstring apply(const wchar_t *format, ...) {
|
||||
wchar_t buf[N];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vswprintf(buf, sizeof(buf)/sizeof(wchar_t), format, args);
|
||||
va_end(args);
|
||||
return buf;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename CharT>
|
||||
std::basic_string<CharT> lowercase(std::basic_string<CharT> s)
|
||||
{
|
||||
std::locale loc;
|
||||
const std::ctype<CharT> &ct = std::use_facet< std::ctype<CharT> >(loc);
|
||||
for (auto it = s.begin(); it != s.end(); ++it)
|
||||
*it = ct.tolower(*it);
|
||||
return s;
|
||||
}
|
||||
|
||||
int stringToInt(const std::string &s);
|
||||
long stringToLongInt(const std::string &s);
|
||||
bool isInteger(const char *s, bool accept_signed);
|
||||
|
||||
std::vector<std::string> split(const std::string &s, const std::string &delimiter);
|
||||
void replace(std::string &s, const std::string &from, const std::string &to);
|
||||
|
||||
void trim(std::string &s);
|
||||
|
||||
std::string getBasename(const std::string &path);
|
||||
std::string getParentDirectory(const std::string &path);
|
||||
std::string getSharedDirectory(const std::string &dir1, const std::string &dir2);
|
||||
|
||||
Reference in New Issue
Block a user