From 855600c4b8bac78bb9daa672320abca5a700fa6b Mon Sep 17 00:00:00 2001 From: Markus Ehrnsperger <> Date: Wed, 3 Jan 2024 18:29:18 +0100 Subject: [PATCH] edit_timer. cleanup --- Makefile | 2 +- epg_events.cpp | 20 +++--- epg_events.h | 2 +- epgsearch.cpp | 4 +- largeString.cpp | 88 ------------------------ largeString.h | 137 -------------------------------------- pages/edit_timer.ecpp | 36 +++++----- pages/get_recordings.ecpp | 3 +- pages/menu.ecpp | 6 -- pages/multischedule.ecpp | 9 ++- pages/pageelems.ecpp | 15 +---- pages/recordings.ecpp | 7 +- pages/remote.ecpp | 14 +--- pages/schedule.ecpp | 7 +- pages/searchresults.ecpp | 7 +- pages/stream.ecpp | 4 +- pages/timerconflicts.ecpp | 8 +-- pages/timers.ecpp | 20 +++--- pages/whats_on.ecpp | 12 ++-- recman.cpp | 42 ++++++------ recman.h | 9 ++- setup.h | 1 - stringhelpers.h | 60 +++++++++++++---- timers.cpp | 8 +-- tools.cpp | 71 ++------------------ tools.h | 8 +-- 26 files changed, 157 insertions(+), 443 deletions(-) delete mode 100644 largeString.cpp delete mode 100644 largeString.h diff --git a/Makefile b/Makefile index 3ddbd00c..be6cf789 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,7 @@ VERSIONSUFFIX = gen_version_suffix.h PLUGINOBJS := $(PLUGIN).o thread.o tntconfig.o setup.o i18n.o timers.o \ tools.o recman.o tasks.o status.o epg_events.o epgsearch.o \ grab.o md5.o filecache.o livefeatures.o preload.o timerconflict.o \ - users.o osd_status.o ffmpeg.o StringMatch.o largeString.o xxhash.o + users.o osd_status.o ffmpeg.o StringMatch.o xxhash.o PLUGINSRCS := $(patsubst %.o,%.cpp,$(PLUGINOBJS)) WEB_LIB_PAGES := libpages.a diff --git a/epg_events.cpp b/epg_events.cpp index 5f0ea386..b44b8e30 100644 --- a/epg_events.cpp +++ b/epg_events.cpp @@ -40,19 +40,19 @@ namespace vdrlive const std::string EpgInfo::CurrentTime(const char* format) const { - return FormatDateTime(format, time(0)); + return std::string(cToSvDateTime(format, time(0))); } const std::string EpgInfo::StartTime(const char* format) const { time_t start = GetStartTime(); - return start ? FormatDateTime(format, start) : ""; + return start ? std::string(cToSvDateTime(format, start)) : ""; } const std::string EpgInfo::EndTime(const char* format) const { time_t end = GetEndTime(); - return end ? FormatDateTime(format, end) : ""; + return end ? std::string(cToSvDateTime(format, end)) : ""; } int EpgInfo::Elapsed() const @@ -268,7 +268,7 @@ namespace vdrlive { std::string eventId("event_"); - eventId += vdrlive::EncodeDomId(cToSvChannel(chanId), ".-", "pm"); + eventId += vdrlive::EncodeDomId(cToSvConcat(chanId), ".-", "pm"); eventId += '_'; eventId += cSv(cToSvInt(eId)); return eventId; @@ -485,7 +485,7 @@ namespace vdrlive } // namespace EpgEvents -void AppendScraperData(cLargeString &target, cScraperVideo *scraperVideo) { +void AppendScraperData(cToSvConcat<0> &target, cScraperVideo *scraperVideo) { cTvMedia s_image; std::string s_title, s_episode_name, s_IMDB_ID, s_release_date; if (scraperVideo == NULL) { @@ -499,7 +499,7 @@ void AppendScraperData(cLargeString &target, cScraperVideo *scraperVideo) { cOrientations(eOrientation::landscape, eOrientation::portrait, eOrientation::banner), false); AppendScraperData(target, s_IMDB_ID, s_image, scraperVideo->getVideoType(), s_title, scraperVideo->getSeasonNumber(), scraperVideo->getEpisodeNumber(), s_episode_name, s_runtime, s_release_date); } -bool appendEpgItem(cLargeString &epg_item, RecordingsItemRecPtr &recItem, const cEvent *Event, const cChannel *Channel, bool withChannel) { +bool appendEpgItem(cToSvConcat<0> &epg_item, RecordingsItemRecPtr &recItem, const cEvent *Event, const cChannel *Channel, bool withChannel) { cGetScraperVideo getScraperVideo(Event, NULL); getScraperVideo.call(LiveSetup().GetPluginScraper()); @@ -509,7 +509,7 @@ bool appendEpgItem(cLargeString &epg_item, RecordingsItemRecPtr &recItem, const epg_item.append("[\""); // [0] : EPG ID (without event_) - epg_item.appendS(EpgEvents::EncodeDomId(Channel->GetChannelID(), Event->EventID()).c_str() + 6); + epg_item.append(EpgEvents::EncodeDomId(Channel->GetChannelID(), Event->EventID()).c_str() + 6); epg_item.append("\",\""); // [1] : Timer ID const cTimer* timer = LiveTimerManager().GetTimer(Event->EventID(), Channel->GetChannelID() ); @@ -520,7 +520,7 @@ bool appendEpgItem(cLargeString &epg_item, RecordingsItemRecPtr &recItem, const epg_item.append(","); // [9] : channelnr if (withChannel) { - epg_item.append(Channel->Number()); + epg_item.concat(Channel->Number()); epg_item.append(",\""); // [10] : channelname AppendHtmlEscapedAndCorrectNonUTF8(epg_item, Channel->Name() ); @@ -536,9 +536,9 @@ bool appendEpgItem(cLargeString &epg_item, RecordingsItemRecPtr &recItem, const AppendTextTruncateOnWord(epg_item, Event->Description(), LiveSetup().GetMaxTooltipChars(), true); epg_item.append("\",\""); // [14] : Day, time & duration of event - AppendDateTime(epg_item, tr("%I:%M %p"), Event->StartTime() ); + epg_item.appendDateTime(tr("%I:%M %p"), Event->StartTime() ); epg_item.append(" - "); - AppendDateTime(epg_item, tr("%I:%M %p"), Event->EndTime() ); + epg_item.appendDateTime(tr("%I:%M %p"), Event->EndTime() ); epg_item.append(" "); AppendDuration(epg_item, tr("(%d:%02d)"), Event->Duration()); epg_item.append("\"]"); diff --git a/epg_events.h b/epg_events.h index 04065661..83572bc7 100644 --- a/epg_events.h +++ b/epg_events.h @@ -254,7 +254,7 @@ namespace vdrlive mutable bool m_checkedArchived; mutable std::string m_archived; }; -bool appendEpgItem(cLargeString &epg_item, RecordingsItemRecPtr &recItem, const cEvent *Event, const cChannel *Channel, bool withChannel); +bool appendEpgItem(cToSvConcat<0> &epg_item, RecordingsItemRecPtr &recItem, const cEvent *Event, const cChannel *Channel, bool withChannel); }; // namespace vdrlive #endif // VDR_LIVE_EPG_EVENTS_H diff --git a/epgsearch.cpp b/epgsearch.cpp index 844b92b0..93d4c12a 100644 --- a/epgsearch.cpp +++ b/epgsearch.cpp @@ -315,13 +315,13 @@ void SearchTimer::ParseBlacklist( std::string const& data ) std::string SearchTimer::StartTimeFormatted() { time_t start = cTimer::SetTime(time(NULL), (((StartTime() / 100 ) % 100) * 60 * 60) + (StartTime() % 100 * 60)); - return FormatDateTime(tr("%I:%M %p"), start); + return std::string(cToSvDateTime(tr("%I:%M %p"), start)); } std::string SearchTimer::StopTimeFormatted() { time_t stop = cTimer::SetTime(time(NULL), (((StopTime() / 100 ) % 100) * 60 * 60) + (StopTime() % 100 * 60)); - return FormatDateTime(tr("%I:%M %p"), stop); + return std::string(cToSvDateTime(tr("%I:%M %p"), stop)); } std::string SearchTimer::UseAsSearchTimerFrom(std::string const& format) diff --git a/largeString.cpp b/largeString.cpp deleted file mode 100644 index 98730271..00000000 --- a/largeString.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "largeString.h" - -void cLargeString::init(size_t initialSize, size_t increaseSize, bool debugBufferSize) { - m_debugBufferSize = debugBufferSize; - if (increaseSize > 0) m_increaseSize = increaseSize; - else m_increaseSize = std::max((size_t)100, initialSize / 2); - if (initialSize == 0) return; - m_s = (char *) malloc(initialSize * sizeof(char)); - if (!m_s) { - esyslog("cLargeString::init, ERROR out of memory, name = %.*s, initialSize = %zu", nameLen(), nameData(), initialSize); - throw std::runtime_error("cLargeString::cLargeString, ERROR out of memory"); - return; - } - m_buffer_end = m_s + initialSize; - m_string_end = m_s; -} - -cLargeString::~cLargeString() { - if (m_s == m_s_initial) return; - free (m_s); - setMaxSize(); - size_t buffer_len = m_buffer_end - m_s; - if (m_debugBufferSize && buffer_len > m_maxSize * 2) esyslog("cLargeString::cLargeString WARNING too large buffer, name = %.*s, buffer %zu, len %zu", nameLen(), nameData(), buffer_len, m_maxSize); -} - -void cLargeString::clear() { - setMaxSize(); - m_string_end = m_s; - m_endBorrowed = false; -} - -char *cLargeString::borrowEnd(size_t len) { - appendLen(len); - m_endBorrowed = true; - return m_string_end; -} -bool cLargeString::finishBorrow(size_t len) { - if (!m_endBorrowed) return true; - m_endBorrowed = false; - if (m_string_end + len >= m_buffer_end) { - esyslog("cLargeString::finishBorrow(size_t len), ERROR name = %.*s, len %zu too large, available %zu", nameLen(), nameData(), len, m_buffer_end - m_string_end - 1); - m_string_end = m_buffer_end - 1; - return false; - } - m_string_end = m_string_end + len; - return true; -} - -bool cLargeString::finishBorrow() { - if (!m_endBorrowed) return true; - m_endBorrowed = false; - char *end = strchr(m_string_end, 0); - if (!end) return false; - if (end >= m_buffer_end) { - esyslog("cLargeString::finishBorrow(), ERROR name = %.*s, end >= m_buffer_end, available %zu", nameLen(), nameData(), m_buffer_end - m_string_end - 1); - m_string_end = m_buffer_end - 1; - return false; - } - m_string_end = end; - return true; -} - -void cLargeString::enlarge(size_t increaseSize) { - increaseSize = std::max(increaseSize, m_increaseSize); - increaseSize = std::max(increaseSize, (size_t)((m_buffer_end - m_s)/2) ); - size_t stringLength = m_string_end - m_s; - size_t newSize = m_buffer_end - m_s + increaseSize; - if (m_s == m_s_initial) - m_s = (char *) malloc(newSize * sizeof(char)); - else { - if (m_debugBufferSize) esyslog("cLargeString::cLargeString, WARNING realloc required!!!, name = %.*s, new Size = %zu", nameLen(), nameData(), newSize); - m_s = (char *)realloc(m_s, newSize * sizeof(char)); - } - if (!m_s) { - esyslog("cLargeString::cLargeString, ERROR out of memory, name = %.*s, new Size = %zu", nameLen(), nameData(), newSize); - throw std::runtime_error("cLargeString::cLargeString, ERROR out of memory (enlarge)"); - return; - } - m_buffer_end = m_s + newSize; - m_string_end = m_s + stringLength; -} diff --git a/largeString.h b/largeString.h deleted file mode 100644 index 83bc4129..00000000 --- a/largeString.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef __LARGE_STRING_H -#define __LARGE_STRING_H - -#include -#include -#include -#include -#include -#include "stringhelpers.h" - -class cLargeString { - private: - char m_s_initial[1] = ""; - char *m_s = m_s_initial; - char *m_string_end = m_s; // *m_string_end = 0; m_string_end must be < m_buffer_end, because m_buffer_end is excluded - char *m_buffer_end = m_s + 1; // buffer is between [m_s;m_buffer_end), i.e. m_buffer_end is excluded - size_t m_increaseSize = 0; - size_t m_maxSize = 0; - const char *m_nameData; - int m_nameLen; - bool m_debugBufferSize = false; - bool m_endBorrowed = false; - void enlarge(size_t increaseSize = 0); - inline void appendLen(size_t len) { // enure buffer is large enough to append len characters - if (m_string_end + len < m_buffer_end) return; - enlarge(m_string_end + len + 1 - m_buffer_end); - } - void setMaxSize() { m_maxSize = std::max(m_maxSize, (size_t)(m_string_end - m_s)); } - void init(size_t initialSize, size_t increaseSize, bool debugBufferSize); - cLargeString &append_int(const char *s, size_t len) { -// internal method, no checks (s!=0) - appendLen(len); - memcpy(m_string_end, s, len); - m_string_end += len; - return *this; - } - template cLargeString &appendHex_int(T u) { - appendLen(N); - stringhelpers_internal::addCharsHex(m_string_end, N, u); - m_string_end += N; - return *this; - } - public: - cLargeString(const cLargeString& o) = delete; - cLargeString &operator= (const cLargeString &) = delete; -// cLargeString(cLargeString&& o) = default; // default is wrong, explicit definition required -// cLargeString &operator= (cLargeString &&) = default; // default is wrong, explicit definition required - template - cLargeString(const char (&name)[N], size_t initialSize = 0, size_t increaseSize = 0, bool debugBufferSize = false) { - m_nameData = name; - m_nameLen = static_cast(N) - 1; - init(initialSize, increaseSize, debugBufferSize); - } - ~cLargeString(); - char *data() { *m_string_end = 0; return m_s; } - size_t length() const { return m_string_end - m_s; } - const char *c_str() const { *m_string_end = 0; return m_s; } - char operator[](size_t i) const { return *(m_s + i); } - operator cSv() const { return cSv(m_s, m_string_end - m_s); } - bool empty() const { return m_string_end == m_s; } - - cLargeString &append(char c) { - appendLen(1); - *(m_string_end++) = c; - return *this; - } - cLargeString &append(size_t count, char c) { - appendLen(count); - memset(m_string_end, c, count); - m_string_end += count; - return *this; - } - cLargeString &append(const char (&s)[1]) { -// note: every other specific implementation is too slow. memcpy is too fast :) - return *this; - } - template cLargeString &append(const char (&s)[N]) { -// std::cout << "append template!!!!\n"; - appendLen(N-1); - memcpy(m_string_end, s, N-1); - m_string_end += N-1; - return *this; - } - cLargeString &append(const char *s, size_t len) { - if (!s) return *this; - return append_int(s, len); - } - cLargeString &appendS(const char *s) { - if (!s || !*s) return *this; - return append_int(s, strlen(s)); - } - template::value, bool> = true> - cLargeString &append(T s) { return appendS(s); } - template::value, bool> = true> - cLargeString &append(T s) { return appendS(s); } - cLargeString &append(const std::string &s) { return append_int(s.c_str(), s.length()); } - cLargeString &append(cSv s) { return append_int(s.data(), s.length()); } -template, bool> = true> - cLargeString &append(T i) { - appendLen(20); - m_string_end = stringhelpers_internal::itoa(m_string_end, i); - return *this; - } - template cLargeString &appendHex(unsigned u) { return appendHex_int(u); } - template cLargeString &appendHex(unsigned long u) { return appendHex_int(u); } - template cLargeString &appendHex(unsigned long long u) { return appendHex_int(u); } - template cLargeString &appendFormated(const char *format, Args&&... args) { - size_t avail = m_buffer_end - m_string_end; - size_t numNeeded = snprintf(m_string_end, avail, format, std::forward(args)...); - if (numNeeded >= avail) { - appendLen(numNeeded + 1); - sprintf(m_string_end, format, std::forward(args)...); - } - m_string_end += numNeeded; - return *this; - } - char *borrowEnd(size_t len); // len: upper limit of characters that can be written - bool finishBorrow(size_t len); // len: number of actually written characters - bool finishBorrow(); // number of actually written characters: zero terminated - void clear(); -// cLargeString &erase(size_t index = 0) { setMaxSize(); m_string_end = std::min(m_string_end, m_s + index); return *this;} - const char *nameData() const { return m_nameData; } - int nameLen() const { return m_nameLen; } -}; -template, bool> = true> -void stringAppend(cLargeString &s, T i) { - s.append(i); -} - -inline void append_csv(cLargeString &str, cSv s1) { str.append(s1); } -template -inline void append_csv(cLargeString &str, cSv s1, Args&&... args) { - str.append(s1); - append_csv(str, std::forward(args)...); -} - -#endif // __LARGE_STRING_H diff --git a/pages/edit_timer.ecpp b/pages/edit_timer.ecpp index c00c1526..8da3f217 100644 --- a/pages/edit_timer.ecpp +++ b/pages/edit_timer.ecpp @@ -40,6 +40,7 @@ using namespace vdrlive; int lifetime = 0; std::string aux = ""; std::string directory = ""; + int nav_back = 1; <%session scope="global"> bool logged_in(false); @@ -79,41 +80,37 @@ const cTimer* timer; timerId = timer->Id(); } - if ( request.getMethod() == "POST" ) { + if ( request.getMethod() == "POST" && title.empty()) { ++nav_back; message = tr("Please set a title for the timer!"); } + if ( request.getMethod() == "POST" && !title.empty()) { const char* oldRemote = NULL; if ( timer != 0 ) { oldRemote = timer->Remote(); // dsyslog("live: found valid timer on server '%s'", oldRemote); - } - uint flags = ( active ? tfActive : 0 ) | ( vps ? tfVps : 0 ); - std::string weekdays = std::string( wday_mon ? "M" : "-" ) + ( wday_tue ? "T" : "-" ) + ( wday_wed ? "W" : "-" ) - + ( wday_thu ? "T" : "-" ) + ( wday_fri ? "F" : "-" ) + ( wday_sat ? "S" : "-" ) - + ( wday_sun ? "S" : "-" ); - int start = timeStringToInt(start_s); - int stop = timeStringToInt(stop_s); + } - if (!directory.empty()) - title = directory + "~" + title; + uint flags = ( active ? tfActive : 0 ) | ( vps ? tfVps : 0 ); + std::string weekdays = std::string( wday_mon ? "M" : "-" ) + ( wday_tue ? "T" : "-" ) + ( wday_wed ? "W" : "-" ) + + ( wday_thu ? "T" : "-" ) + ( wday_fri ? "F" : "-" ) + ( wday_sat ? "S" : "-" ) + + ( wday_sun ? "S" : "-" ); + int start = timeStringToInt(start_s); + int stop = timeStringToInt(stop_s); + + std::string file = directory.empty() ? title : directory + "~" + title; - if (title.empty()) - message = tr("Please set a title for the timer!"); - else - { const char* remote = ( remoteServerName == "") ? NULL : remoteServerName.c_str(); // dsyslog("live: remote '%s'", remote); - LiveTimerManager().UpdateTimer( timerId, remote, oldRemote, flags, channel, weekdays, date, start, stop, priority, lifetime, title, aux ); + LiveTimerManager().UpdateTimer( timerId, remote, oldRemote, flags, channel, weekdays, date, start, stop, priority, lifetime, file, aux ); timerNotifier.SetTimerModification(); <%cpp> // return reply.redirect("html/back.html"); // return reply.redirect(!edit_timerreferer.empty()?edit_timerreferer:"timers.html"); - } } else { if (message.empty()) @@ -148,7 +145,7 @@ const cTimer* timer; timer = eventTimer.get(); } - if ( timer != 0 ) { + if ( timer != 0 && request.getMethod() == "GET" ) { active = timer->Flags() & tfActive; channel = timer->Channel()->GetChannelID(); title = timer->File() ? timer->File() : ""; @@ -205,6 +202,7 @@ const cTimer* timer;
+ @@ -355,7 +353,7 @@ const cTimer* timer; diff --git a/pages/get_recordings.ecpp b/pages/get_recordings.ecpp index 6b59efff..837ffcce 100644 --- a/pages/get_recordings.ecpp +++ b/pages/get_recordings.ecpp @@ -43,7 +43,8 @@ recordings_tree_re_created = <$ recordings_tree_re_created?"true":"false"$>; */ - cLargeString recoring_item("recoring_item_get_recordings.ecpp", 5000); + cToSvConcat<0> recoring_item; + recoring_item.reserve(5000); for (int recording: r) { bool found = false; for (const RecordingsItemRecPtr &rPtr: *recordingsTree->allRecordings()) if (recording == rPtr->IdI() ) { diff --git a/pages/menu.ecpp b/pages/menu.ecpp index 4eca4869..e3327c8c 100644 --- a/pages/menu.ecpp +++ b/pages/menu.ecpp @@ -74,14 +74,8 @@ if (LiveSetup().UseAuth()) { <$ tr("Your attention is required") $>: <$ timerNotifier.Message() $><$ tr("React") $> -<%cpp> -if (LiveSetup().GetUseAjax()) { -">|<$ tr("Dismiss") $> -<%cpp> -} - diff --git a/pages/multischedule.ecpp b/pages/multischedule.ecpp index 858c8dcf..31279f81 100644 --- a/pages/multischedule.ecpp +++ b/pages/multischedule.ecpp @@ -263,8 +263,11 @@ std::vector times_start; for ( std::vector< time_t >::const_iterator start = times_start.begin(); start != times_start.end(); ++start ) { - times_names.push_back(FormatDateTime( tr("%A, %x"), *start) - +std::string(" ")+ FormatDateTime( tr("%I:%M %p"), *start) ); + cToSvConcat times_name; + times_name.appendDateTime(tr("%A, %x"), *start); + times_name.concat(' '); + times_name.appendDateTime(tr("%I:%M %p"), *start); + times_names.push_back(std::string(times_name)); } // the first time is now times_names[0]=tr("Now"); @@ -493,7 +496,7 @@ std::vector times_start; if ( minutes < MINUTES_PER_ROW ) { - <$ FormatDateTime( tr("%I:%M %p"), sched_start + row * 60 * MINUTES_PER_ROW ) $> + <$ cToSvDateTime( tr("%I:%M %p"), sched_start + row * 60 * MINUTES_PER_ROW ) $> <%cpp> } else diff --git a/pages/pageelems.ecpp b/pages/pageelems.ecpp index 37d5f607..ea4e9223 100644 --- a/pages/pageelems.ecpp +++ b/pages/pageelems.ecpp @@ -63,9 +63,7 @@ int update_status(1); <%def create_html_js> <%cpp> -const char *lf; -if (LiveSetup().GetUseAjax()) lf = "
"; -else lf = " "; +const char *lf = "
"; @@ -483,9 +477,6 @@ if (LiveSetup().GetUseStreamdev() && LiveFeatures(). <%cpp> } -<%cpp> - } - <# ---------------------------------------------------------------------- #> diff --git a/pages/recordings.ecpp b/pages/recordings.ecpp index 3f4ed167..1bf55863 100644 --- a/pages/recordings.ecpp +++ b/pages/recordings.ecpp @@ -10,7 +10,6 @@ #include #include #include -#include #ifdef HAVE_PCRE2 #include @@ -125,7 +124,9 @@ if (request.hasCookie("VDR-Live-Recordings-Tree-Open-Nodes")) { openTreeNodes = request.getCookie("VDR-Live-Recordings-Tree-Open-Nodes"); // isyslog("live: VDR-Live-Recordings-Tree-Open-Nodes = %s", openTreeNodes.c_str()); } -cLargeString recoring_item("recoring_item", 25000); +cToSvConcat<0> recoring_item; +recoring_item.reserve(25000); + <& pageelems.doc_type &> @@ -357,7 +358,7 @@ if (currentSort == "datedesc" || currentSort == "namedesc") reverse = true; // get rec item of this (current) dir RecordingsItemDirPtr recItemThisDir = *(static_cast((void *)iRecItem) ); RecordingsTreePtr recordingsTree = *(static_cast((void *)iRecordingsTree) ); -cLargeString *recoring_item = static_cast((void *)irecoring_item ); +cToSvConcat<0> *recoring_item = static_cast *>((void *)irecoring_item ); std::string openTreeNodes= *(static_cast((void *)iOpenTreeNodes) ); std::vector available_recs = *(static_cast *>((void *)iAvailable_recs) ); int level = recItemThisDir->Level(); diff --git a/pages/remote.ecpp b/pages/remote.ecpp index feac1684..044ec2ac 100644 --- a/pages/remote.ecpp +++ b/pages/remote.ecpp @@ -151,7 +151,6 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); imgsrc = document.images.vdrlive.src; FillIntervals(); changeScreenContent(); -<{ if (LiveSetup().GetUseAjax() ) { }> $('osd').addEvents({ 'click': function(ev){ $clear(clkTimer); @@ -164,7 +163,6 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); handleOSD(ev.target, true); } }); -<{ } }> } function ChangeInterval() @@ -227,17 +225,10 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); function KeyPress(keycode,DonotLoadOSD) { -// LiveSimpleAjaxRequest('keypress.xml', 'keycode', keycode); -<{ if (LiveSetup().GetUseAjax() ) { }> var req = new Ajax('keypress.xml', { method : 'post'}); if (!DonotLoadOSD && osdAjax) req.addEvent('onComplete', OSDLoad); req.request('keycode=' + keycode + '&async=1'); -<{ } else { }> - var req = new XMLHttpRequest(); - req.open('POST', encodeURI('keypress.xml?keycode=' + keycode)); - req.send(); -<{ } }> return false; } @@ -356,10 +347,9 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); <%def remote_actions> <$ tr("Selection") $>:  -<{ if ( LiveGrabImageManager().CanGrab()) { }> +% if ( LiveGrabImageManager().CanGrab()) {              - -<{ } if (LiveSetup().GetUseAjax() ) { }> +% }   - -<{ } }>   diff --git a/pages/schedule.ecpp b/pages/schedule.ecpp index 540b90aa..39f80195 100644 --- a/pages/schedule.ecpp +++ b/pages/schedule.ecpp @@ -112,7 +112,8 @@ bool display_pictures = !(LiveSetup().GetTvscraperImageDir().empty()); time_t now = time(NULL) - ::Setup.EPGLinger * 60; RecordingsItemRecPtr recItem; bool recItemFound; - cLargeString epg_item("epg_item", 1000); + cToSvConcat<0> epg_item; + epg_item.reserve(1000); for (const cEvent *Event = (cEvent *)Schedule->Events()->First(); Event; Event = (cEvent *)Schedule->Events()->Next(Event)) { if (Event->EndTime() <= now && Event != PresentEvent) continue; @@ -128,7 +129,7 @@ bool display_pictures = !(LiveSetup().GetTvscraperImageDir().empty()); lastEventCurrentDay = true; } else { - std::string nday(NextEvent->StartTime() ? FormatDateTime(tr("%A, %b %d %Y"), NextEvent->StartTime()) : ""); + std::string nday(NextEvent->StartTime() ? std::string(cToSvDateTime(tr("%A, %b %d %Y"), NextEvent->StartTime())) : ""); lastEventCurrentDay = (day != nday); } } @@ -179,7 +180,7 @@ if(recItemFound) { - <& channels_widget name=("channel") selected=(Channel ? cSv(cToSvChannel(Channel->GetChannelID())) : cSv() ) onchange=("document.forms.channels.submit()") &> + <& channels_widget name=("channel") selected=(Channel ? cSv(cToSvConcat(Channel->GetChannelID())) : cSv() ) onchange=("document.forms.channels.submit()") &> % if (cDevice::PrimaryDevice() && cDevice::PrimaryDevice()->HasDecoder() ) { <& pageelems.ajax_action_href action="switch_channel" tip=(tr("Switch to this channel.")) param=(Channel->GetChannelID()) image="zap.png" alt="" &> % } diff --git a/pages/searchresults.ecpp b/pages/searchresults.ecpp index 9243dc7b..89aaa4e8 100644 --- a/pages/searchresults.ecpp +++ b/pages/searchresults.ecpp @@ -69,7 +69,8 @@ bool logged_in(false); <%cpp> std::string current_day = ""; bool display_pictures = !(LiveSetup().GetTvscraperImageDir().empty()); - cLargeString epg_itemS("epg_itemS", 1000); + cToSvConcat<0> epg_itemS; + epg_itemS.reserve(1000); RecordingsItemRecPtr recItem; bool recItemFound; @@ -90,13 +91,13 @@ bool logged_in(false); continue; } const cEvent *event = result->GetEvent(channel); - std::string day(result->StartTime() ? FormatDateTime(tr("%A, %b %d %Y"), result->StartTime()) : ""); + std::string day(result->StartTime() ? std::string(cToSvDateTime(tr("%A, %b %d %Y"), result->StartTime())) : ""); bool bottom = false; SearchResults::iterator nextResult = result; ++nextResult; if (nextResult == results.end()) bottom = true; else { - std::string nextDay(nextResult->StartTime() ? FormatDateTime(tr("%A, %b %d %Y"), nextResult->StartTime()) : ""); + std::string nextDay(nextResult->StartTime() ? std::string(cToSvDateTime(tr("%A, %b %d %Y"), nextResult->StartTime())) : ""); bottom = (day != nextDay); } diff --git a/pages/stream.ecpp b/pages/stream.ecpp index 94a1ad00..8edf7edd 100644 --- a/pages/stream.ecpp +++ b/pages/stream.ecpp @@ -125,8 +125,8 @@ if (Event) { EpgEvents::DecodeDomId(epgEvent->Id(), chanId, eventId); char const * timeFormat = tr("%I:%M %p"); char const * dateFormat = tr("%A, %x"); - std::string headTime = FormatDateTime(timeFormat, time(0)); - std::string headDate = FormatDateTime(dateFormat, time(0)); + std::string headTime = std::string(cToSvDateTime(timeFormat, time(0))); + std::string headDate = std::string(cToSvDateTime(dateFormat, time(0))); std::string startTime(epgEvent->StartTime(tr("%I:%M %p"))); std::string endTime(epgEvent->EndTime(tr("%I:%M %p"))); std::string startDate(epgEvent->StartTime(tr("%a, %x"))); diff --git a/pages/timerconflicts.ecpp b/pages/timerconflicts.ecpp index d7cb822b..303cf576 100644 --- a/pages/timerconflicts.ecpp +++ b/pages/timerconflicts.ecpp @@ -50,7 +50,7 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html");
@@ -126,12 +126,12 @@ if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html"); - - + + - - + +
<$ timer ? tr("Edit timer") : tr("New timer") $>
- +
-
<$ concat(FormatDateTime(tr("%A, %x"), conflict->ConflictTime()), " ", FormatDateTime(tr("%I:%M %p"), conflict->ConflictTime()), " - ", cToSvInt(confltimer->percentage), "%") $><$ tr("Server")$>: <$ (confltimer->remote == "" ) ? tr("local") : confltimer->remote $>
+
<$ concat(cToSvDateTime(tr("%A, %x"), conflict->ConflictTime()), " ", cToSvDateTime(tr("%I:%M %p"), conflict->ConflictTime()), " - ", cToSvInt(confltimer->percentage), "%") $><$ tr("Server")$>: <$ (confltimer->remote == "" ) ? tr("local") : confltimer->remote $>
">" alt="" <%cpp> if (!timerStateHint.empty()) { <& tooltip.hint text=(timerStateHint) &><%cpp> } / > ">
- +
<$ FormatDateTime(tr("%I:%M %p"), timer->StartTime()) $> - <$ FormatDateTime(tr("%I:%M %p"), timer->StopTime()) $>
<$ cToSvDateTime(tr("%I:%M %p"), timer->StartTime()) $> - <$ cToSvDateTime(tr("%I:%M %p"), timer->StopTime()) $>
<$ timer->Channel()->Name() $>
"><$ timer->Priority() $>
td-hidden-xs"> td-hidden-xs"> td-hidden-xs"> td-hidden-xs"> td-hidden-xs"> td-hidden-xs"> ">">" alt="" <%cpp> if (!timerStateHint.empty()) { <& tooltip.hint text=(timerStateHint) &> <%cpp> } /> ">
- +
<$ FormatDateTime(tr("%I:%M %p"), timer->StartTime()) $> - <$ FormatDateTime(tr("%I:%M %p"), timer->StopTime()) $>
<$ cToSvDateTime(tr("%I:%M %p"), timer->StartTime()) $> - <$ cToSvDateTime(tr("%I:%M %p"), timer->StopTime()) $>
<$ timer->Channel()->Name() $>
td-hidden-xs"> td-hidden-xs"> td-hidden-xs"> td-hidden-xs"> td-hidden-xs"> td-hidden-xs"> ">
(std::string &s, const cRecording *rec); -template void StringAppendFrameParams(cLargeString &s, const cRecording *rec); template void StringAppendFrameParams>(cToSvConcat<0> &s, const cRecording *rec); template void StringAppendFrameParams>(cToSvConcat<255> &s, const cRecording *rec); @@ -867,7 +866,7 @@ bool searchNameDesc(RecordingsItemRecPtr &RecItem, const std::vector &target, cSv s_IMDB_ID, const cTvMedia &s_image, tvType s_videoType, cSv s_title, int s_season_number, int s_episode_number, cSv s_episode_name, int s_runtime, cSv s_release_date) { bool scraperDataAvailable = s_videoType == tMovie || s_videoType == tSeries; target.append("\""); // [2] IMDB ID @@ -884,10 +883,10 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im target.append("\",\""); if (s_videoType == tSeries && (s_episode_number != 0 || s_season_number != 0)) { // [6] : season/episode/episode name (scraper) - target.append(s_season_number); - target.append('E'); - target.append(s_episode_number); - target.append(' '); + target.concat(s_season_number); + target.concat('E'); + target.concat(s_episode_number); + target.concat(' '); AppendHtmlEscapedAndCorrectNonUTF8(target, s_episode_name.data(), s_episode_name.data() + s_episode_name.length() ); } target.append("\",\""); @@ -899,12 +898,11 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im target.append("\""); } - void RecordingsItemRec::AppendAsJSArray(cLargeString &target) const { + void RecordingsItemRec::AppendAsJSArray(cToSvConcat<0> &target) const { target.append("\""); // [0] : ID -// target.append(cToSvXxHash128(IdHash())); - target.appendHex<16>(IdHash().high64); - target.appendHex<16>(IdHash().low64); + target.appendHex(IdHash().high64, 16); + target.appendHex(IdHash().low64, 16); target.append("\",\""); // [1] : ArchiveDescr() if (IsArchived()) AppendHtmlEscapedAndCorrectNonUTF8(target, ArchiveDescr().c_str() ); @@ -913,16 +911,16 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im AppendScraperData(target, m_s_IMDB_ID, scraperImage(), m_s_videoType, m_s_title, m_s_season_number, m_s_episode_number, m_s_episode_name, m_s_runtime, m_s_release_date); // [9] : Day, time target.append(",\""); - AppendDateTime(target, tr("%a,"), StartTime()); // day of week - target.append(' '); - AppendDateTime(target, tr("%b %d %y"), StartTime()); // date - target.append(' '); - AppendDateTime(target, tr("%I:%M %p"), StartTime()); // time + target.appendDateTime(tr("%a,"), StartTime() ); // day of week + target.concat(' '); + target.appendDateTime(tr("%b %d %y"), StartTime()); // date + target.concat(' '); + target.appendDateTime(tr("%I:%M %p"), StartTime()); // time target.append("\", "); // RecordingErrors, Icon #if VDRVERSNUM >= 20505 // [10] : Number of recording errors - target.append(RecordingErrors() ); + target.concat(RecordingErrors() ); #else target.append("-100"); #endif @@ -956,7 +954,7 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im AppendHtmlEscapedAndCorrectNonUTF8(target, RecInfo()->ChannelName() ); target.append("\", \""); // [13] NewR() - target.appendS(NewR() ); + target.append(NewR() ); target.append("\", \""); // [14] Name AppendHtmlEscapedAndCorrectNonUTF8(target, Name() ); @@ -969,7 +967,7 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im AppendTextTruncateOnWord(target, RecInfo()->Description(), LiveSetup().GetMaxTooltipChars(), true); // [17] recording length deviation target.append("\","); - target.append(DurationDeviation()); + target.concat(DurationDeviation()); // [18] Path / folder target.append(",\""); AppendHtmlEscapedAndCorrectNonUTF8(target, (const char *)Recording()->Folder() ); @@ -992,14 +990,14 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im target.append(" "); target.append("\","); // [21] numTsFiles - target.append(NumberTsFiles() ); + target.concat(NumberTsFiles() ); // [22] frame parameter text target.append(",\""); StringAppendFrameParams(target, m_recording); target.append("\""); } - void RecordingsItemRec::AppendAsJSArray(cLargeString &target, std::vector::const_iterator recIterFirst, std::vector::const_iterator recIterLast, bool &first, cSv filter, bool reverse) { + void RecordingsItemRec::AppendAsJSArray(cToSvConcat<0> &target, std::vector::const_iterator recIterFirst, std::vector::const_iterator recIterLast, bool &first, cSv filter, bool reverse) { if (reverse) { for (; recIterFirst != recIterLast;) { --recIterLast; @@ -1007,7 +1005,7 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im if (!recItem->matchesFilter(filter)) continue; if (!first) target.append(","); else first = false; - target.append(recItem->IdI() ); + target.concat(recItem->IdI() ); } } else { for (; recIterFirst != recIterLast; ++recIterFirst) { @@ -1015,7 +1013,7 @@ void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_im if (!recItem->matchesFilter(filter)) continue; if (!first) target.append(","); else first = false; - target.append(recItem->IdI() ); + target.concat(recItem->IdI() ); } } } diff --git a/recman.h b/recman.h index 7629461a..661c1107 100644 --- a/recman.h +++ b/recman.h @@ -20,7 +20,6 @@ #include #include #include "stringhelpers.h" -#include "largeString.h" #include "tools.h" #include "services.h" @@ -317,8 +316,8 @@ template bool matchesFilter(cSv filter) const; virtual int SD_HD() const; - virtual void AppendAsJSArray(cLargeString &target) const; - static void AppendAsJSArray(cLargeString &target, std::vector::const_iterator recIterFirst, std::vector::const_iterator recIterLast, bool &first, cSv filter, bool reverse); + virtual void AppendAsJSArray(cToSvConcat<0> &target) const; + static void AppendAsJSArray(cToSvConcat<0> &target, std::vector::const_iterator recIterFirst, std::vector::const_iterator recIterLast, bool &first, cSv filter, bool reverse); mutable cMeasureTime *m_timeIdentify = nullptr; mutable cMeasureTime *m_timeOverview = nullptr; @@ -387,7 +386,7 @@ template const cTvMedia &scraperImage() const { return m_s_image; } virtual int SD_HD() const { return 0; } - virtual void AppendAsJSArray(cLargeString &target) const {} + virtual void AppendAsJSArray(cToSvConcat<0> &target) const {} private: const cEvent *m_event; }; @@ -464,7 +463,7 @@ template a.swap(b); } -void AppendScraperData(cLargeString &target, cSv s_IMDB_ID, const cTvMedia &s_image, tvType s_videoType, cSv s_title, int s_season_number, int s_episode_number, cSv s_episode_name, int s_runtime, cSv s_release_date); +void AppendScraperData(cToSvConcat<0> &target, cSv s_IMDB_ID, const cTvMedia &s_image, tvType s_videoType, cSv s_title, int s_season_number, int s_episode_number, cSv s_episode_name, int s_runtime, cSv s_release_date); std::string recordingErrorsHtml(int recordingErrors); diff --git a/setup.h b/setup.h index c43eabf6..a631463e 100644 --- a/setup.h +++ b/setup.h @@ -60,7 +60,6 @@ class Setup std::string const GetLastSortingMode() const { return m_lastsortingmode; } std::string const GetTntnetLogLevel() const { return m_tntnetloglevel; } bool GetShowLogo() const { return m_showLogo != 0; } - bool GetUseAjax() const { return true; } bool GetUseArchive() const { return false; } bool GetShowInfoBox() const { return m_showInfoBox != 0; } bool GetUseStreamdev() const { return m_useStreamdev != 0; } diff --git a/stringhelpers.h b/stringhelpers.h index 58ea7d4c..6d4ce414 100644 --- a/stringhelpers.h +++ b/stringhelpers.h @@ -637,7 +637,6 @@ class cToSv { cToSv &operator= (const cToSv &) = delete; virtual ~cToSv() {} virtual operator cSv() const = 0; - operator std::string_view() const { return (cSv)*this; } }; inline std::ostream& operator<<(std::ostream& os, cToSv const& sv ) { @@ -816,9 +815,9 @@ template cToSvConcat &operator<<(T sv) { return concat(sv); } // ======================= // ======================= -// append_int append integer (with some format options) +// appendInt append integer (with some format options) template, bool> = true> - cToSvConcat &append_int(T i, size_t desired_width, char fill_char = '0') { + cToSvConcat &appendInt(T i, size_t desired_width, char fill_char = '0') { size_t len = stringhelpers_internal::numChars(i); if (desired_width <= len) return concat(i); if (m_pos_for_append + desired_width > m_be_data) ensure_free(desired_width); @@ -831,25 +830,34 @@ template, bool> = true> m_pos_for_append = stringhelpers_internal::itoa(m_pos_for_append, i); return *this; } +template, bool> = true> + cToSvConcat &appendHex(T value, int width) { + if (m_pos_for_append + width > m_be_data) ensure_free(width); + stringhelpers_internal::addCharsHex(m_pos_for_append, width, value); + m_pos_for_append += width; + return *this; + } // ======================= -// append utf8 +// append_utf8 append utf8 codepoint cToSvConcat &append_utf8(wint_t codepoint) { if (m_pos_for_append + 4 > m_be_data) ensure_free(4); AppendUtfCodepoint(m_pos_for_append, codepoint); return *this; } +// ======================= +// appendToLower void appendToLower(cSv sv, const std::locale &loc) { for (auto it = sv.utf8_begin(); it != sv.utf8_end(); ++it) { append_utf8(std::tolower(*it, loc)); } } // ======================= -// append formated +// appendFormated append formated // __attribute__ ((format (printf, 2, 3))) can not be used, but should work starting with gcc 13.1 template cToSvConcat &appendFormated(const char *fmt, Args&&... args) { - int needed = snprintf (m_pos_for_append, m_be_data - m_pos_for_append, fmt, std::forward(args)...); + int needed = snprintf(m_pos_for_append, m_be_data - m_pos_for_append, fmt, std::forward(args)...); if (needed < 0) { - esyslog("live: ERROR, cToScCOncat::appendFormated needed = %d, fmt = %s", needed, fmt); + esyslog("live: ERROR, cToScConcat::appendFormated needed = %d, fmt = %s", needed, fmt); return *this; // error in snprintf } if (needed < m_be_data - m_pos_for_append) { @@ -857,15 +865,39 @@ template, bool> = true> return *this; } ensure_free(needed + 1); - needed = sprintf (m_pos_for_append, fmt, std::forward(args)...); + needed = sprintf(m_pos_for_append, fmt, std::forward(args)...); if (needed < 0) { - esyslog("live: ERROR, cToScCOncat::appendFormated needed (2) = %d, fmt = %s", needed, fmt); + esyslog("live: ERROR, cToScConcat::appendFormated needed (2) = %d, fmt = %s", needed, fmt); return *this; // error in sprintf } m_pos_for_append += needed; return *this; } // ======================= +// appendDateTime: append date/time formated with strftime + cToSvConcat &appendDateTime(const char *fmt, const std::tm *tp) { + size_t needed = std::strftime(m_pos_for_append, m_be_data - m_pos_for_append, fmt, tp); + if (needed == 0) { + ensure_free(1024); + needed = std::strftime(m_pos_for_append, m_be_data - m_pos_for_append, fmt, tp); + if (needed == 0) { + esyslog("live: ERROR, cToScConcat::appendDateTime needed = 0, fmt = %s", fmt); + return *this; // we did not expect to need more than 1024 chars for the formated time ... + } + } + m_pos_for_append += needed; + return *this; + } + cToSvConcat &appendDateTime(const char *fmt, time_t time) { + if (!time) return *this; + struct std::tm tm_r; + if (localtime_r( &time, &tm_r ) == 0 ) { + esyslog("live: ERROR, cToScConcat::appendDateTime localtime_r = 0, fmt = %s, time = %lld", fmt, (long long)time); + return *this; // we did not expect to need more than 1024 chars for the formated time ... + } + return appendDateTime(fmt, &tm_r); + } +// ======================= // #include // ========================================================= @@ -941,7 +973,7 @@ template, bool> = true> cToSvInt (T i): cToSvConcat(i) { } template, bool> = true> cToSvInt (T i, size_t desired_width, char fill_char = '0') { - append_int(i, desired_width, fill_char); + appendInt(i, desired_width, fill_char); } }; template @@ -961,11 +993,11 @@ class cToSvFormated: public cToSvConcat { this->appendFormated(fmt, std::forward(args)...); } }; - - -class cToSvChannel: public cToSvConcat<255> { +class cToSvDateTime: public cToSvConcat<255> { public: - cToSvChannel(const tChannelID &channelID): cToSvConcat(channelID) { } + cToSvDateTime(const char *fmt, time_t time) { + this->appendDateTime(fmt, time); + } }; // ========================================================= diff --git a/timers.cpp b/timers.cpp index 9321bbb6..7b5e8735 100644 --- a/timers.cpp +++ b/timers.cpp @@ -23,7 +23,7 @@ namespace vdrlive { std::string SortedTimers::GetTimerId( cTimer const& timer ) { std::stringstream builder; - builder << cSv(cToSvChannel(timer.Channel()->GetChannelID())) << ":" << timer.WeekDays() << ":" + builder << cSv(cToSvConcat(timer.Channel()->GetChannelID())) << ":" << timer.WeekDays() << ":" << timer.Day() << ":" << timer.Start() << ":" << timer.Stop(); return builder.str(); } @@ -90,7 +90,7 @@ namespace vdrlive { if (!timer) return ""; std::string currentDay = timer->WeekDays() > 0 ? *cTimer::PrintDay(0, timer->WeekDays(), true) : - FormatDateTime(tr("%A, %x"), timer->Day()); + std::string(cToSvDateTime(tr("%A, %x"), timer->Day())); return currentDay; } @@ -166,7 +166,7 @@ namespace vdrlive { std::stringstream builder; builder << flags << ":" - << cSv(cToSvChannel(channel)) << ":" + << cSv(cToSvConcat(channel)) << ":" << ( weekdays != "-------" ? weekdays : "" ) << ( weekdays == "-------" || day.empty() ? "" : "@" ) << day << ":" << start << ":" @@ -187,7 +187,7 @@ namespace vdrlive { dsyslog("live: UpdateTimer() remote '%s'", remote); dsyslog("live: UpdateTimer() oldRemote '%s'", oldRemote); dsyslog("live: UpdateTimer() channel '%s'", *(channel.ToString())); - dsyslog("live: UpdateTimer() channel '%s'", cToSvChannel(channel).c_str() ); + dsyslog("live: UpdateTimer() channel '%s'", cToSvConcat(channel).c_str() ); dsyslog("live: UpdateTimer() builder '%s'", builder.str().c_str()); timerStruct timerData = { .id = timerId, .remote=remote, .oldRemote=oldRemote, .builder=builder.str() }; diff --git a/tools.cpp b/tools.cpp index c3dcc169..4f2bcccb 100644 --- a/tools.cpp +++ b/tools.cpp @@ -39,27 +39,6 @@ std::istream& operator>>( std::istream& is, tChannelID& ret ) namespace vdrlive { - void AppendHtmlEscaped(std::string &target, const char* s){ -// append c-string s to target, html escape some chsracters - if(!s) return; - size_t i = 0; - const char* notAppended = s; -// moving forward, notAppended is the position of the first character which is not yet appended, in i the number of not yet appended chars - for (const char* current = s; *current; current++) { - switch(*current) { - case '&': target.append(notAppended, i); target.append("&"); notAppended = notAppended + i + 1; i = 0; break; - case '\"': target.append(notAppended, i); target.append("""); notAppended = notAppended + i + 1; i = 0; break; - case '\'': target.append(notAppended, i); target.append("'"); notAppended = notAppended + i + 1; i = 0; break; - case '<': target.append(notAppended, i); target.append("<"); notAppended = notAppended + i + 1; i = 0; break; - case '>': target.append(notAppended, i); target.append(">"); notAppended = notAppended + i + 1; i = 0; break; - case 10: - case 13: target.append(notAppended, i); target.append("<br/>"); notAppended = notAppended + i + 1; i = 0; break; - default: i++; break; - } - } - target.append(notAppended, i); - } - template void AppendHtmlEscapedAndCorrectNonUTF8(T &target, const char* s, const char *end, bool tooltip){ // append c-string s to target, html escape some characters @@ -81,11 +60,7 @@ template case '>': target.append(notAppended, i); target.append(">"); notAppended = notAppended + i + 1; i = 0; break; case 10: case 13: - if (LiveSetup().GetUseAjax() || !tooltip) { target.append(notAppended, i); target.append("<br/>"); notAppended = notAppended + i + 1; i = 0; break; - } else { - target.append(notAppended, i); target.append(*current==10?"\\n":"\\r"); notAppended = notAppended + i + 1; i = 0; break; - } default: i++; break; } break; @@ -106,7 +81,7 @@ template target.append(notAppended, i); } template void AppendHtmlEscapedAndCorrectNonUTF8(std::string &target, const char* s, const char *end, bool tooltip); -template void AppendHtmlEscapedAndCorrectNonUTF8(cLargeString &target, const char* s, const char *end, bool tooltip); +template void AppendHtmlEscapedAndCorrectNonUTF8>(cToSvConcat<0> &target, const char* s, const char *end, bool tooltip); template void AppendDuration(T &target, char const* format, int duration) @@ -117,7 +92,7 @@ template stringAppendFormated(target, format, hours, minutes); } template void AppendDuration(std::string &target, char const* format, int duration); -template void AppendDuration(cLargeString &target, char const* format, int duration); +template void AppendDuration>(cToSvConcat<0> &target, char const* format, int duration); std::string FormatDuration(char const* format, int duration) { @@ -126,42 +101,6 @@ template void AppendDuration(cLargeString &target, char const* for return result; } - size_t AppendDateTime(char *target, int target_size, char const* format, time_t time) -// writes data to target, make sure that sizeof(target) >= target_size, before calling - { - if (!time) return 0; - struct tm tm_r; - if ( localtime_r( &time, &tm_r ) == 0 ) { - std::stringstream builder; - builder << "cannot represent timestamp " << time << " as local time"; - throw std::runtime_error( builder.str() ); - } - size_t len = strftime(target, target_size, format, &tm_r); - if ( len == 0 ) { - std::stringstream builder; - builder << "representation of timestamp " << time << " exceeds " << (target_size - 1) << " bytes"; - throw std::runtime_error( builder.str() ); - } - return len; - } - void AppendDateTime(cLargeString &target, char const* format, time_t time) - { - int len = AppendDateTime(target.borrowEnd(80), 80, format, time); - target.finishBorrow(len); - } - void AppendDateTime(std::string &target, char const* format, time_t time ) - { - char result[80]; - AppendDateTime(result, sizeof( result ), format, time); - target.append(result); - } - std::string FormatDateTime( char const* format, time_t time ) - { - char result[80]; - AppendDateTime(result, sizeof( result ), format, time); - return result; - } - std::string StringReplace(cSv text, cSv substring, cSv replacement) { std::string result(text); @@ -248,7 +187,7 @@ template } } template void AppendTextMaxLen(std::string &target, const char *text); -template void AppendTextMaxLen(cLargeString &target, const char *text); +template void AppendTextMaxLen>(cToSvConcat<0> &target, const char *text); template void AppendTextTruncateOnWord(T &target, const char *text, int max_len, bool tooltip) { @@ -261,7 +200,7 @@ template if (*end) target.append("..."); } template void AppendTextTruncateOnWord(std::string &target, const char *text, int max_len, bool tooltip); -template void AppendTextTruncateOnWord(cLargeString &target, const char *text, int max_len, bool tooltip); +template void AppendTextTruncateOnWord>(cToSvConcat<0> &target, const char *text, int max_len, bool tooltip); std::string MD5Hash(std::string const& str) { @@ -411,7 +350,7 @@ template void AppendTextTruncateOnWord(cLargeString &target, const cformat = StringReplace(cformat, "mm", "%m"); cformat = StringReplace(cformat, "dd", "%d"); cformat = StringReplace(cformat, "yyyy", "%Y"); - return FormatDateTime(cformat.c_str(), date); + return std::string(cToSvDateTime(cformat.c_str(), date)); } int timeStringToInt(const char *t) { // input: t in xx:xx format diff --git a/tools.h b/tools.h index f13bcf56..175ec38c 100644 --- a/tools.h +++ b/tools.h @@ -22,7 +22,6 @@ #include "xxhash.h" #include #include "stringhelpers.h" -#include "largeString.h" std::istream& operator>>( std::istream& is, tChannelID& ret ); @@ -32,7 +31,7 @@ std::ostream& operator<<( std::ostream& os, tChannelID const& id ) return os << cToSvConcat(id); } -template void stringAppendFormated(cLargeString &target, const char *format, Args&&... args) { +template void stringAppendFormated(cToSvConcat<0> &target, const char *format, Args&&... args) { target.appendFormated(format, std::forward(args)...); } @@ -40,7 +39,6 @@ namespace vdrlive { extern const std::locale g_locale; extern const std::collate& g_collate_char; - void AppendHtmlEscaped(std::string &target, const char* s); template void AppendHtmlEscapedAndCorrectNonUTF8(T &target, const char* s, const char *end = NULL, bool tooltip = false); template @@ -54,10 +52,6 @@ template template void AppendDuration(T &target, char const* format, int duration); std::string FormatDuration( char const* format, int duration ); - void AppendDateTime(cLargeString &target, char const* format, time_t time ); - void AppendDateTime(std::string &target, char const* format, time_t time ); - std::string FormatDateTime( char const* format, time_t time ); - std::string StringReplace(cSv text, cSv substring, cSv replacement ); std::vector StringSplit(cSv text, char delimiter );