[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 416ab02 030/156: Add support for vector varia
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 416ab02 030/156: Add support for vector variables to PDF generating code |
Date: |
Tue, 30 Jan 2018 17:22:01 -0500 (EST) |
branch: master
commit 416ab02fb8b8ea4da036fa86d27fdf19772f6a69
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>
Add support for vector variables to PDF generating code
Recognize anything of the form "name[index]" as a vector.
---
ledger_pdf_generator_wx.cpp | 42 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index ca68fa7..c7bf5f3 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -39,6 +39,7 @@
#include <wx/pdfdc.h>
+#include <cstdint> // SIZE_MAX
#include <map>
#include <memory>
#include <sstream>
@@ -140,6 +141,11 @@ class html_interpolator
return evaluator_(name);
}
+ std::string evaluate(std::string const& name, std::size_t index) const
+ {
+ return evaluator_(name, index);
+ }
+
private:
// The expansion function used with interpolate_string().
text expand_html(std::string const& s) const
@@ -151,7 +157,41 @@ class html_interpolator
return it->second;
}
- // Then look in the ledger.
+ // Then look in the ledger, either as a scalar or a vector depending on
+ // whether it has "[index]" part or not.
+ if(!s.empty() && *s.rbegin() == ']')
+ {
+ auto const open_pos = s.find('[');
+ if(open_pos == std::string::npos)
+ {
+ throw std::runtime_error
+ ("Variable '" + s + "' doesn't have the expected '['"
+ );
+ }
+
+ char* stop = nullptr;
+ auto const index = std::strtoul(s.c_str() + open_pos + 1, &stop,
10);
+
+ // Conversion must have stopped at the closing bracket character
+ // and also check for overflow (notice that index == SIZE_MAX
+ // doesn't, in theory, need to indicate overflow, but in practice
+ // we're never going to have valid indices close to this number).
+ if(stop != s.c_str() + s.length() - 1 || index >= SIZE_MAX)
+ {
+ throw std::runtime_error
+ ("Index of vector variable '" + s + "' is not a valid
number"
+ );
+ }
+
+ // Cast below is valid because of the check for overflow above.
+ return text::from
+ (evaluator_
+ (s.substr(0, open_pos)
+ ,static_cast<std::size_t>(index)
+ )
+ );
+ }
+
return text::from(evaluator_(s));
}
- [lmi-commits] [lmi] master 940198c 059/156: Add numeric summary attachment page, (continued)
- [lmi-commits] [lmi] master 940198c 059/156: Add numeric summary attachment page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master b341a2a 061/156: Factor out using_illustration_table helper class, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 1b46585 076/156: Use MarketingNameFootnote & StateMarketingImprimatur on cover page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 234cd39 012/156: Use custom font sizes to be closer to the existing illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 956fcca 071/156: Change the second narrative summary page to use a template too, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master dbe5955 015/156: Factor out html_interpolator from pdf_illustration, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 9665573 070/156: Change narrative summary page to use an external template, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master a629602 083/156: Use custom <scaled_image> HTML tag for the embedded images, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master b425030 082/156: Factor out html_cell_for_pdf_output from numeric_summary_table_cell, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master d99576a 069/156: Change cover page to use an external template, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 416ab02 030/156: Add support for vector variables to PDF generating code,
Greg Chicares <=
- [lmi-commits] [lmi] master d4dfaa9 075/156: Also use data directory for image files referenced from HTML, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 4f98db5 081/156: Don't show "Age 70" row in numeric summary for composites, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master f8853b9 090/156: Add "contract numbers" fragment to the header, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 61430d2 092/156: Move some variable definitions to the base illustration class, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 7ccd207 087/156: Rename "footer_contents" to more precise "page_number", Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 3a64b87 094/156: Correct misleading comment for page class dtor, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 4e76bba 098/156: Add support for comments to the string interpolation function, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master b5fe850 102/156: Add NASD basic illustration page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 4250de9 104/156: Add first variant of NASD supplemental page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 7a1e1e8 025/156: Include the missing <cstring> header, Greg Chicares, 2018/01/30