diff --git a/configure.in b/configure.in index 3ffabcda..122cc83f 100644 --- a/configure.in +++ b/configure.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 ============================= diff --git a/src/Makefile.am b/src/Makefile.am index 4b4fc919..35ede862 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/actions.cpp b/src/actions.cpp index 3a04a276..d385721b 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include @@ -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(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::apply(Config.locked_screen_width_part*100)); + std::string str_part = wFooter->getString(boost::lexical_cast(Config.locked_screen_width_part*100)); Statusbar::unlock(); if (str_part.empty()) return; - part = stringToInt(str_part); + part = boost::lexical_cast(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(position)*60 + + boost::lexical_cast(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(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(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(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(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(strprio); myPlaylist->main().filter(myPlaylist->main().begin(), myPlaylist->main().end(), [prio](const NC::Menu::Item &s) { return s.value().getPrio() > prio; diff --git a/src/bindings.cpp b/src/bindings.cpp index 3a9534b1..55e3e499 100644 --- a/src/bindings.cpp +++ b/src/bindings.cpp @@ -18,6 +18,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include #include #include #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); diff --git a/src/browser.cpp b/src/browser.cpp index e39f4f4e..f1754887 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #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(); } diff --git a/src/cmdargs.cpp b/src/cmdargs.cpp index 785f53b5..f9145df7 100644 --- a/src/cmdargs.cpp +++ b/src/cmdargs.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #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); } diff --git a/src/display.cpp b/src/display.cpp index cf3c330b..3c273e5f 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -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; diff --git a/src/help.cpp b/src/help.cpp index 47821150..fd65e448 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -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::apply(key.getChar()-264); + result += boost::lexical_cast(key.getChar()-264); } else if ((key == Key(KEY_BACKSPACE, Key::NCurses) || key == Key(KEY_BACKSPACE_2, Key::Standard))) { diff --git a/src/helpers.h b/src/helpers.h index b81721a7..6d7b5b01 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -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) diff --git a/src/lastfm.cpp b/src/lastfm.cpp index 4700be5e..a10fbe9e 100644 --- a/src/lastfm.cpp +++ b/src/lastfm.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -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; diff --git a/src/lastfm_service.cpp b/src/lastfm_service.cpp index c2e32516..40e62bad 100644 --- a/src/lastfm_service.cpp +++ b/src/lastfm_service.cpp @@ -22,9 +22,11 @@ #ifdef HAVE_CURL_CURL_H +#include #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); } /***********************************************************************/ diff --git a/src/lyrics.cpp b/src/lyrics.cpp index b14b5d0c..9ff6116f 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -36,6 +36,7 @@ #include "statusbar.h" #include "title.h" #include "screen_switcher.h" +#include "utility/string.h" using Global::MainHeight; using Global::MainStartY; diff --git a/src/lyrics_fetcher.cpp b/src/lyrics_fetcher.cpp index 94c8a19e..1bf94fad 100644 --- a/src/lyrics_fetcher.cpp +++ b/src/lyrics_fetcher.cpp @@ -24,6 +24,8 @@ #include #include +#include +#include #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, "
", "\n"); + boost::replace_all(data, "
", "\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
, 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, "
", "\n"); + boost::replace_all(data, " ", ""); + boost::replace_all(data, "
", "\n"); data = unescapeHtmlUtf8(data); LyricsFetcher::postProcess(data); } diff --git a/src/media_library.cpp b/src/media_library.cpp index 355f6b29..55a1ac4e 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -18,6 +18,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include #include #include #include @@ -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)) diff --git a/src/mutable_song.cpp b/src/mutable_song.cpp index 64b2b24e..761d41e4 100644 --- a/src/mutable_song.cpp +++ b/src/mutable_song.cpp @@ -18,8 +18,8 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include #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 tags; + boost::iter_split(tags, value, boost::first_finder(delimiter)); size_t i = 0; for (; i < tags.size(); ++i) (this->*set)(tags[i], i); diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index a54c50cc..91cb06c5 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -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; diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index 8ee45a7c..523af9b0 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -171,7 +171,7 @@ void PlaylistEditor::update() { title = "Playlist content"; title += " ("; - title += unsignedLongIntTo::apply(Content.size()); + title += boost::lexical_cast(Content.size()); title += " item"; if (Content.size() == 1) title += ")"; diff --git a/src/settings.cpp b/src/settings.cpp index c97f4327..692d0198 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -26,6 +26,7 @@ # include #endif // WIN32 #include +#include #include #include #include @@ -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(v)) + mpd_port = boost::lexical_cast(v); } else if (name == "mpd_connection_timeout") { - if (stringToInt(v)) - mpd_connection_timeout = stringToInt(v); + if (boost::lexical_cast(v)) + mpd_connection_timeout = boost::lexical_cast(v); } else if (name == "mpd_crossfade_time") { - if (stringToInt(v) > 0) - crossfade_time = stringToInt(v); + if (boost::lexical_cast(v) > 0) + crossfade_time = boost::lexical_cast(v); } else if (name == "seek_time") { - if (stringToInt(v) > 0) - seek_time = stringToInt(v); + if (boost::lexical_cast(v) > 0) + seek_time = boost::lexical_cast(v); } else if (name == "playlist_disable_highlight_delay") { - if (stringToInt(v) >= 0) - playlist_disable_highlight_delay = stringToInt(v); + if (boost::lexical_cast(v) >= 0) + playlist_disable_highlight_delay = boost::lexical_cast(v); } else if (name == "message_delay_time") { - if (stringToInt(v) > 0) - message_delay_time = stringToInt(v); + if (boost::lexical_cast(v) > 0) + message_delay_time = boost::lexical_cast(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(v); } else if (name == "search_engine_default_search_mode") { if (!v.empty()) { - unsigned mode = stringToInt(v); + unsigned mode = boost::lexical_cast(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(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(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(width); columns.push_back(col); } diff --git a/src/song.cpp b/src/song.cpp index 7894224d..cbbbd765 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -20,11 +20,12 @@ #include #include +#include +#include #include #include #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::apply(getPrio()); + return boost::lexical_cast(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::apply(i+1) << ": '" << fmt[i] << "'\n"; + std::cerr << type << ": invalid character at position " << boost::lexical_cast(i+1) << ": '" << fmt[i] << "'\n"; return false; } } diff --git a/src/status.cpp b/src/status.cpp index e11e50c4..144643e5 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -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::apply(Mpd.GetBitrate()); + tracklength += boost::lexical_cast(Mpd.GetBitrate()); tracklength += " kbps"; } @@ -359,7 +360,7 @@ void Status::Changes::elapsedTime() if (Config.display_bitrate && Mpd.GetBitrate()) { tracklength += " ["; - tracklength += intTo::apply(Mpd.GetBitrate()); + tracklength += boost::lexical_cast(Mpd.GetBitrate()); tracklength += " kbps]"; } tracklength += " ["; @@ -498,7 +499,7 @@ void Status::Changes::mixer() VolumeState += "n/a"; else { - VolumeState += intTo::apply(volume); + VolumeState += boost::lexical_cast(volume); VolumeState += "%"; } *wHeader << Config.volume_color; diff --git a/src/strbuffer.h b/src/strbuffer.h index daaf90a9..09c846d6 100644 --- a/src/strbuffer.h +++ b/src/strbuffer.h @@ -21,8 +21,8 @@ #ifndef NCMPCPP_STRBUFFER_H #define NCMPCPP_STRBUFFER_H +#include #include -#include "utility/numeric_conversions.h" #include "window.h" namespace NC {// @@ -130,25 +130,25 @@ public: BasicBuffer &operator<<(int n) { - m_string += intTo::apply(n); + m_string += boost::lexical_cast(n); return *this; } BasicBuffer &operator<<(long int n) { - m_string += longIntTo::apply(n); + m_string += boost::lexical_cast(n); return *this; } BasicBuffer &operator<<(unsigned int n) { - m_string += unsignedIntTo::apply(n); + m_string += boost::lexical_cast(n); return *this; } BasicBuffer &operator<<(unsigned long int n) { - m_string += unsignedLongIntTo::apply(n); + m_string += boost::lexical_cast(n); return *this; } diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 9a7d6ade..546f30a9 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -22,6 +22,7 @@ #ifdef HAVE_TAGLIB_H +#include #include #include #include @@ -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::apply(i) + "/" + unsignedIntTo::apply(EditedSongs.size())); + (*it)->setTrack(boost::lexical_cast(i) + "/" + boost::lexical_cast(EditedSongs.size())); else - (*it)->setTrack(unsignedIntTo::apply(i)); + (*it)->setTrack(boost::lexical_cast(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(); diff --git a/src/tags.cpp b/src/tags.cpp index 38d86c1d..8cc91ff1 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -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::apply(tag->year())); - s.setTrack(intTo::apply(tag->track())); + s.setDate(boost::lexical_cast(tag->year())); + s.setTrack(boost::lexical_cast(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(s.getDate())); + tag->setTrack(boost::lexical_cast(s.getTrack())); tag->setGenre(ToWString(s.getGenre())); tag->setComment(ToWString(s.getComment())); } diff --git a/src/tiny_tag_editor.cpp b/src/tiny_tag_editor.cpp index d06f314c..e99415fd 100644 --- a/src/tiny_tag_editor.cpp +++ b/src/tiny_tag_editor.cpp @@ -22,6 +22,8 @@ #ifdef HAVE_TAGLIB_H +#include + // taglib includes #include #include @@ -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(); diff --git a/src/utility/comparators.cpp b/src/utility/comparators.cpp index e6c8fd32..46289653 100644 --- a/src/utility/comparators.cpp +++ b/src/utility/comparators.cpp @@ -20,6 +20,7 @@ #include #include "comparators.h" +#include "utility/string.h" namespace {// diff --git a/src/utility/html.cpp b/src/utility/html.cpp index 73cefdb5..0872e13b 100644 --- a/src/utility/html.cpp +++ b/src/utility/html.cpp @@ -18,8 +18,9 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include #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) diff --git a/src/utility/numeric_conversions.h b/src/utility/numeric_conversions.h deleted file mode 100644 index 66f2856a..00000000 --- a/src/utility/numeric_conversions.h +++ /dev/null @@ -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 -#include "string.h" - -#ifndef NCMPCPP_UTILITY_NUMERIC_CONVERSIONS_H -#define NCMPCPP_UTILITY_NUMERIC_CONVERSIONS_H - -template struct intTo { }; -template <> struct intTo { - static std::string apply(int n) { - return print<32, std::string>::apply("%d", n); - } -}; -template <> struct intTo { - static std::wstring apply(int n) { - return print<32, std::wstring>::apply(L"%d", n); - } -}; - -template struct longIntTo { }; -template <> struct longIntTo { - static std::string apply(long int n) { - return print<32, std::string>::apply("%ld", n); - } -}; -template <> struct longIntTo { - static std::wstring apply(long int n) { - return print<32, std::wstring>::apply(L"%ld", n); - } -}; - -template struct unsignedIntTo { }; -template <> struct unsignedIntTo { - static std::string apply(unsigned int n) { - return print<32, std::string>::apply("%u", n); - } -}; -template <> struct unsignedIntTo { - static std::wstring apply(unsigned int n) { - return print<32, std::wstring>::apply(L"%u", n); - } -}; - -template struct unsignedLongIntTo { }; -template <> struct unsignedLongIntTo { - static std::string apply(unsigned long int n) { - return print<32, std::string>::apply("%lu", n); - } -}; -template <> struct unsignedLongIntTo { - static std::wstring apply(unsigned long int n) { - return print<32, std::wstring>::apply(L"%lu", n); - } -}; - -#endif // NCMPCPP_UTILITY_NUMERIC_CONVERSIONS_H diff --git a/src/utility/string.h b/src/utility/string.h index d784370c..e885229a 100644 --- a/src/utility/string.h +++ b/src/utility/string.h @@ -31,47 +31,8 @@ template size_t const_strlen(const char (&)[N]) { return N-1; } -template struct print { }; -template struct print { - 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 struct print { - 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 -std::basic_string lowercase(std::basic_string s) -{ - std::locale loc; - const std::ctype &ct = std::use_facet< std::ctype >(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 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);