Skip to content

Commit

Permalink
str::Format() => str::FormatTemp()
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Oct 23, 2023
1 parent adcc718 commit 71206fe
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/DisplayModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ bool DisplayModel::HasPageLabels() const {
return engine->HasPageLabels();
}

char* DisplayModel::GetPageLabel(int pageNo) const {
return engine->GetPageLabel(pageNo);
TempStr DisplayModel::GetPageLabeTemp(int pageNo) const {
return engine->GetPageLabeTemp(pageNo);
}

int DisplayModel::GetPageByLabel(const char* label) const {
Expand Down
2 changes: 1 addition & 1 deletion src/DisplayModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct DisplayModel : DocController {

// page labels (optional)
bool HasPageLabels() const override;
char* GetPageLabel(int pageNo) const override;
TempStr GetPageLabeTemp(int pageNo) const override;
int GetPageByLabel(const char* label) const override;

// common shortcuts
Expand Down
4 changes: 2 additions & 2 deletions src/DocController.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ struct DocController {
virtual bool HasPageLabels() const {
return false;
}
virtual char* GetPageLabel(int pageNo) const {
return str::Format("%d", pageNo);
virtual TempStr GetPageLabeTemp(int pageNo) const {
return str::FormatTemp("%d", pageNo);
}
virtual int GetPageByLabel(const char* label) const {
return atoi(label);
Expand Down
4 changes: 2 additions & 2 deletions src/EngineBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ bool EngineBase::HasPageLabels() const {
return hasPageLabels;
}

char* EngineBase::GetPageLabel(int pageNo) const {
return str::Format("%d", pageNo);
TempStr EngineBase::GetPageLabeTemp(int pageNo) const {
return str::FormatTemp("%d", pageNo);
}

int EngineBase::GetPageByLabel(const char* label) const {
Expand Down
2 changes: 1 addition & 1 deletion src/EngineBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class EngineBase {

// returns a label to be displayed instead of the page number
// caller must free() the result
virtual char* GetPageLabel(int pageNo) const;
virtual TempStr GetPageLabeTemp(int pageNo) const;

// reverts GetPageLabel by returning the first page number having the given label
virtual int GetPageByLabel(const char* label) const;
Expand Down
8 changes: 4 additions & 4 deletions src/EngineDjVu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class EngineDjVu : public EngineBase {
IPageDestination* GetNamedDest(const char* name) override;
TocTree* GetToc() override;

char* GetPageLabel(int pageNo) const override;
TempStr GetPageLabeTemp(int pageNo) const override;
int GetPageByLabel(const char* label) const override;

static EngineBase* CreateFromFile(const char* path);
Expand Down Expand Up @@ -1174,14 +1174,14 @@ TocTree* EngineDjVu::GetToc() {
return tocTree;
}

char* EngineDjVu::GetPageLabel(int pageNo) const {
TempStr EngineDjVu::GetPageLabeTemp(int pageNo) const {
for (size_t i = 0; i < fileInfos.size(); i++) {
ddjvu_fileinfo_t& info = fileInfos.at(i);
if (pageNo - 1 == info.pageno && !str::Eq(info.title, info.id)) {
return str::Dup(info.title);
return str::DupTemp(info.title);
}
}
return EngineBase::GetPageLabel(pageNo);
return EngineBase::GetPageLabeTemp(pageNo);
}

int EngineDjVu::GetPageByLabel(const char* label) const {
Expand Down
2 changes: 1 addition & 1 deletion src/EngineDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void DumpPageContent(EngineBase* engine, int pageNo, bool fullDump) {

Out("\t<Page Number=\"%d\"\n", pageNo);
if (engine->HasPageLabels()) {
AutoFreeStr label = Escape(engine->GetPageLabel(pageNo));
AutoFreeStr label = Escape(engine->GetPageLabeTemp(pageNo));
Out("\t\tLabel=\"%s\"\n", label.Get());
}
Rect bbox = engine->PageMediabox(pageNo).Round();
Expand Down
14 changes: 7 additions & 7 deletions src/EngineImages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ class EngineImageDir : public EngineImages {
return nullptr;
}

char* GetPageLabel(int pageNo) const override;
TempStr GetPageLabeTemp(int pageNo) const override;
int GetPageByLabel(const char* label) const override;

TocTree* GetToc() override;
Expand Down Expand Up @@ -861,20 +861,20 @@ static bool LoadImageDir(EngineImageDir* e, const char* dir) {
return true;
}

char* EngineImageDir::GetPageLabel(int pageNo) const {
TempStr EngineImageDir::GetPageLabeTemp(int pageNo) const {
if (pageNo < 1 || PageCount() < pageNo) {
return EngineBase::GetPageLabel(pageNo);
return EngineBase::GetPageLabeTemp(pageNo);
}

const char* path = pageFileNames.at(pageNo - 1);
const char* fileName = path::GetBaseNameTemp(path);
char* ext = path::GetExtTemp(fileName);
if (!ext) {
return str::Dup(fileName);
return str::DupTemp(fileName);
}
auto pos = str::Find(fileName, ext);
size_t n = pos - fileName;
return str::Dup(fileName, n);
return str::DupTemp(fileName, n);
}

int EngineImageDir::GetPageByLabel(const char* label) const {
Expand Down Expand Up @@ -903,11 +903,11 @@ TocTree* EngineImageDir::GetToc() {
if (tocTree) {
return tocTree;
}
char* label = GetPageLabel(1);
TempStr label = GetPageLabeTemp(1);
TocItem* root = newImageDirTocItem(nullptr, label, 1);
root->id = 1;
for (int i = 2; i <= PageCount(); i++) {
label = GetPageLabel(1);
label = GetPageLabeTemp(1);
TocItem* item = newImageDirTocItem(root, label, i);
item->id = i;
root->AddSiblingAtEnd(item);
Expand Down
6 changes: 3 additions & 3 deletions src/EngineMulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class EngineMulti : public EngineBase {
IPageDestination* GetNamedDest(const char* name) override;
TocTree* GetToc() override;

char* GetPageLabel(int pageNo) const override;
TempStr GetPageLabeTemp(int pageNo) const override;
int GetPageByLabel(const char* label) const override;

bool LoadFromFiles(const char* dir, StrVec& files);
Expand Down Expand Up @@ -219,13 +219,13 @@ TocTree* EngineMulti::GetToc() {
return tocTree;
}

char* EngineMulti::GetPageLabel(int pageNo) const {
TempStr EngineMulti::GetPageLabeTemp(int pageNo) const {
if (pageNo < 1 || pageNo >= pageCount) {
return nullptr;
}

EngineBase* e = PageToEngine(pageNo);
return e->GetPageLabel(pageNo);
return e->GetPageLabeTemp(pageNo);
}

int EngineMulti::GetPageByLabel(const char* label) const {
Expand Down
6 changes: 3 additions & 3 deletions src/EngineMupdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3362,13 +3362,13 @@ bool EngineMupdf::HasClipOptimizations(int pageNo) {
return true;
}

char* EngineMupdf::GetPageLabel(int pageNo) const {
TempStr EngineMupdf::GetPageLabeTemp(int pageNo) const {
if (!pageLabels || pageNo < 1 || PageCount() < pageNo) {
return EngineBase::GetPageLabel(pageNo);
return EngineBase::GetPageLabeTemp(pageNo);
}

char* res = pageLabels->at(pageNo - 1);
return str::Dup(res);
return res;
}

int EngineMupdf::GetPageByLabel(const char* label) const {
Expand Down
2 changes: 1 addition & 1 deletion src/EngineMupdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class EngineMupdf : public EngineBase {
IPageDestination* GetNamedDest(const char* name) override;
TocTree* GetToc() override;

char* GetPageLabel(int pageNo) const override;
TempStr GetPageLabeTemp(int pageNo) const override;
int GetPageByLabel(const char* label) const override;

// make sure to never ask for pagesAccess in an ctxAccess
Expand Down
10 changes: 5 additions & 5 deletions src/Favorites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,11 @@ void RebuildFavMenu(MainWindow* win, HMENU menu) {
MenuSetEnabled(menu, CmdFavoriteDel, false);
AppendFavMenus(menu, (const char*)nullptr);
} else {
AutoFreeStr label(win->ctrl->GetPageLabel(win->currPageNo));
TempStr label = win->ctrl->GetPageLabeTemp(win->currPageNo);
bool isBookmarked = gFavorites.IsPageInFavorites(win->ctrl->GetFilePath(), win->currPageNo);
if (isBookmarked) {
MenuSetEnabled(menu, CmdFavoriteAdd, false);
TempStr s = str::FormatTemp(_TRA("Remove page %s from favorites"), label.Get());
TempStr s = str::FormatTemp(_TRA("Remove page %s from favorites"), label);
MenuSetText(menu, CmdFavoriteDel, s);
} else {
MenuSetEnabled(menu, CmdFavoriteDel, false);
Expand All @@ -457,7 +457,7 @@ void RebuildFavMenu(MainWindow* win, HMENU menu) {
if (ok) {
AppendAccelKeyToMenuString(str, a);
}
TempStr s = str::FormatTemp(str.Get(), label.Get());
TempStr s = str::FormatTemp(str.Get(), label);
MenuSetText(menu, CmdFavoriteAdd, s);
}
AppendFavMenus(menu, win->ctrl->GetFilePath());
Expand Down Expand Up @@ -708,8 +708,8 @@ void AddFavoriteForCurrentPage(MainWindow* win, int pageNo) {
name = item->title;
}
}
AutoFreeStr pageLabel = ctrl->GetPageLabel(pageNo);
AddFavoriteWithLabelAndName(win, pageNo, pageLabel.Get(), name);
TempStr pageLabel = ctrl->GetPageLabeTemp(pageNo);
AddFavoriteWithLabelAndName(win, pageNo, pageLabel, name);
}

void AddFavoriteForCurrentPage(MainWindow* win) {
Expand Down
6 changes: 3 additions & 3 deletions src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,14 +1687,14 @@ void OnWindowContextMenu(MainWindow* win, int x, int y) {
bool favsSupported = HasPermission(Perm::SavePreferences) && HasPermission(Perm::DiskAccess);
if (favsSupported) {
if (pageNoUnderCursor > 0) {
AutoFreeStr pageLabel = win->ctrl->GetPageLabel(pageNoUnderCursor);
TempStr pageLabel = win->ctrl->GetPageLabeTemp(pageNoUnderCursor);
bool isBookmarked = gFavorites.IsPageInFavorites(filePath, pageNoUnderCursor);
if (isBookmarked) {
MenuRemove(popup, CmdFavoriteAdd);

// %s and not %d because re-using translation from RebuildFavMenu()
const char* tr = _TRA("Remove page %s from favorites");
TempStr s = str::FormatTemp(tr, pageLabel.Get());
TempStr s = str::FormatTemp(tr, pageLabel);
MenuSetText(popup, CmdFavoriteDel, s);
} else {
MenuRemove(popup, CmdFavoriteDel);
Expand All @@ -1706,7 +1706,7 @@ void OnWindowContextMenu(MainWindow* win, int x, int y) {
if (ok) {
AppendAccelKeyToMenuString(str, a);
}
TempStr s = str::FormatTemp(str.Get(), pageLabel.Get());
TempStr s = str::FormatTemp(str.Get(), pageLabel);
MenuSetText(popup, CmdFavoriteAdd, s);
}
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/SearchAndDDE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,11 @@ struct FindThreadData : public ProgressUpdateUI {
} else if (!success && loopedAround) {
NotificationUpdateMessage(wnd, _TRA("No matches were found"), kNotifDefaultTimeOut);
} else {
AutoFreeStr label = win->ctrl->GetPageLabel(win->AsFixed()->textSearch->GetSearchHitStartPageNo());
TempStr buf = str::FormatTemp(_TRA("Found text at page %s"), label.Get());
auto pageNo = win->AsFixed()->textSearch->GetSearchHitStartPageNo();
TempStr label = win->ctrl->GetPageLabeTemp(pageNo);
TempStr buf = str::FormatTemp(_TRA("Found text at page %s"), label);
if (loopedAround) {
buf = str::FormatTemp(_TRA("Found text at page %s (again)"), label.Get());
buf = str::FormatTemp(_TRA("Found text at page %s (again)"), label);
MessageBeep(MB_ICONINFORMATION);
}
NotificationUpdateMessage(wnd, buf, kNotifDefaultTimeOut, loopedAround);
Expand Down
16 changes: 8 additions & 8 deletions src/SumatraPDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,10 +827,11 @@ static void UpdatePageInfoHelper(DocController* ctrl, NotificationWnd* wnd, int
if (!ctrl->ValidPageNo(pageNo)) {
pageNo = ctrl->CurrentPageNo();
}
TempStr pageInfo = str::FormatTemp("%s %d / %d", _TRA("Page:"), pageNo, ctrl->PageCount());
int nPages = ctrl->PageCount();
TempStr pageInfo = str::FormatTemp("%s %d / %d", _TRA("Page:"), pageNo, nPages);
if (ctrl->HasPageLabels()) {
AutoFreeStr label = ctrl->GetPageLabel(pageNo);
pageInfo = str::FormatTemp("%s %s (%d / %d)", _TRA("Page:"), label.Get(), pageNo, ctrl->PageCount());
TempStr label = ctrl->GetPageLabeTemp(pageNo);
pageInfo = str::FormatTemp("%s %s (%d / %d)", _TRA("Page:"), label, pageNo, nPages);
}
NotificationUpdateMessage(wnd, pageInfo);
}
Expand Down Expand Up @@ -864,9 +865,8 @@ void ControllerCallbackHandler::PageNoChanged(DocController* ctrl, int pageNo) {
}

if (kInvalidPageNo != pageNo) {
char* label = win->ctrl->GetPageLabel(pageNo);
TempStr label = win->ctrl->GetPageLabeTemp(pageNo);
HwndSetText(win->hwndPageEdit, label);
str::Free(label);
ToolbarUpdateStateForWindow(win, false);
if (win->ctrl->HasPageLabels()) {
UpdateToolbarPageText(win, win->ctrl->PageCount(), true);
Expand Down Expand Up @@ -3007,8 +3007,8 @@ static void CreateLnkShortcut(MainWindow* win) {

TempStr args = str::FormatTemp("\"%s\" -page %d -view \"%s\" -zoom %s -scroll %d,%d", path, ss.page, viewMode,
zoomVirtual, (int)ss.x, (int)ss.y);
AutoFreeStr label = ctrl->GetPageLabel(ss.page);
TempStr desc = str::FormatTemp(_TRA("Bookmark shortcut to page %s of %s"), label.Get(), path);
TempStr label = ctrl->GetPageLabeTemp(ss.page);
TempStr desc = str::FormatTemp(_TRA("Bookmark shortcut to page %s of %s"), label, path);
auto exePath = GetExePathTemp();
CreateShortcut(fileName, exePath, args, desc, 1);
}
Expand Down Expand Up @@ -3654,7 +3654,7 @@ static void OnMenuGoToPage(MainWindow* win) {
}

auto* ctrl = win->ctrl;
AutoFreeStr label = ctrl->GetPageLabel(ctrl->CurrentPageNo());
TempStr label = ctrl->GetPageLabeTemp(ctrl->CurrentPageNo());
AutoFreeStr newPageLabel(Dialog_GoToPage(win->hwndFrame, label, ctrl->PageCount(), !ctrl->HasPageLabels()));
if (!newPageLabel) {
return;
Expand Down
14 changes: 7 additions & 7 deletions src/TableOfContents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ static void RelayoutTocItem(LPNMTVCUSTOMDRAW ntvcd) {
// Draw the page number right-aligned (if there is one)
MainWindow* win = FindMainWindowByHwnd(hTV);
TocItem* tocItem = (TocItem*)item.lParam;
AutoFreeWstr label;
TempStr label = nullptr;
if (tocItem->pageNo && win && win->IsDocLoaded()) {
label.Set(win->ctrl->GetPageLabel(tocItem->pageNo));
label.Set(str::Join(L" ", label));
label = win->ctrl->GetPageLabeTemp(tocItem->pageNo);
label = str::JoinTemp(" ", label);
}
if (label && str::EndsWith(item.pszText, label)) {
RECT rcPageNo = rcFullWidth;
Expand Down Expand Up @@ -413,7 +413,7 @@ static void AddFavoriteFromToc(MainWindow* win, TocItem* dti) {
pageNo = dti->dest->GetPageNo();
}
char* name = dti->title;
AutoFreeStr pageLabel = win->ctrl->GetPageLabel(pageNo);
TempStr pageLabel = win->ctrl->GetPageLabeTemp(pageNo);
AddFavoriteWithLabelAndName(win, pageNo, pageLabel, name);
}

Expand Down Expand Up @@ -586,14 +586,14 @@ static void TocContextMenu(ContextMenuEvent* ev) {
}

if (pageNo > 0) {
AutoFreeStr pageLabel = win->ctrl->GetPageLabel(pageNo);
TempStr pageLabel = win->ctrl->GetPageLabeTemp(pageNo);
bool isBookmarked = gFavorites.IsPageInFavorites(filePath, pageNo);
if (isBookmarked) {
MenuRemove(popup, CmdFavoriteAdd);

// %s and not %d because re-using translation from RebuildFavMenu()
const char* tr = _TRA("Remove page %s from favorites");
TempStr s = str::FormatTemp(tr, pageLabel.Get());
TempStr s = str::FormatTemp(tr, pageLabel);
MenuSetText(popup, CmdFavoriteDel, s);
} else {
MenuRemove(popup, CmdFavoriteDel);
Expand All @@ -604,7 +604,7 @@ static void TocContextMenu(ContextMenuEvent* ev) {
if (ok) {
AppendAccelKeyToMenuString(str, a);
}
TempStr s = str::FormatTemp(str.Get(), pageLabel.Get());
TempStr s = str::FormatTemp(str.Get(), pageLabel);
MenuSetText(popup, CmdFavoriteAdd, s);
}
} else {
Expand Down

0 comments on commit 71206fe

Please sign in to comment.