[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 3f1d437 088/156: Add add_abbreviated_variable
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 3f1d437 088/156: Add add_abbreviated_variable() helper |
Date: |
Tue, 30 Jan 2018 17:22:19 -0500 (EST) |
branch: master
commit 3f1d437ac36b4cce8da49b8303ff5ba80d70992f
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>
Add add_abbreviated_variable() helper
Move "CorpNameAbbrev50" and "Insured1Abbrev50" variables out of common
code as they are specific to regular illustrations only.
Define add_abbreviated_variable() to allow consistently defining other
variables with similar names in the future.
No real changes, this is a pure refactoring.
---
ledger_pdf_generator_wx.cpp | 36 +++++++++++++++++++++++++++---------
1 file changed, 27 insertions(+), 9 deletions(-)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index aacd259..bee5646 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -686,6 +686,30 @@ class pdf_illustration : protected html_interpolator
}
}
+ protected:
+ // Helper for abbreviating a string to at most the given length (in bytes).
+ static std::string abbreviate_if_necessary(std::string s, size_t len)
+ {
+ if(s.length() > len && len > 3)
+ {
+ s.replace(len - 3, std::string::npos, "...");
+ }
+
+ return s;
+ }
+
+ // Helper for creating abbreviated variables in the derived classes: such
+ // variables have the name based on the name of the original variable with
+ // "Abbrev" and "len" appended to it and their value is at most "len" bytes
+ // long.
+ void add_abbreviated_variable(std::string const& var, size_t len)
+ {
+ add_variable
+ (var + "Abbrev" + std::to_string(len)
+ ,abbreviate_if_necessary(evaluate(var), len)
+ );
+ }
+
private:
// Initialize the variables that can be interpolated later.
void init_variables()
@@ -729,15 +753,6 @@ class pdf_illustration : protected html_interpolator
return s;
};
- add_variable
- ("CorpNameAbbrev50"
- ,abbreviate_if_necessary(evaluate("CorpName"), 50)
- );
-
- add_variable
- ("Insured1Abbrev50"
- ,abbreviate_if_necessary(evaluate("Insured1"), 50)
- );
}
// Use non-default font sizes to make it simpler to replicate the existing
@@ -1641,6 +1656,9 @@ class pdf_illustration_regular : public pdf_illustration
auto const& state_abbrev = invar.GetStatePostalAbbrev();
// Define variables specific to this illustration.
+ add_abbreviated_variable("CorpName", 50);
+ add_abbreviated_variable("Insured1", 50);
+
add_variable
("ModifiedSinglePremium"
,starts_with(policy_name, "Single") && state_abbrev == "MA"
- [lmi-commits] [lmi] master cb5cb7b 021/156: Add more contents to the narrative summary page, (continued)
- [lmi-commits] [lmi] master cb5cb7b 021/156: Add more contents to the narrative summary page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 173cc28 022/156: Change interpolated strings syntax to be Mustache-like, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 2e4850c 023/156: Implement the rest of "Narrative Summary" page body text, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master c341dbb 108/156: Factor out compliance_tracking template from the footer one, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 76881d8 019/156: Refactor: extra add_body_paragraph() helper, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 08127f1 028/156: Add symbolic constant for the "valign" HTML attribute, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 0d6c7f0 062/156: Get rid of separate wxDC parameter in the code, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master bbada54 084/156: Add image to the columns headings page too, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 3cf5a1c 056/156: Add wx_table_generator::output_super_header(), Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 95e616e 105/156: Add wx_table_generator::columns_count() accessor, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 3f1d437 088/156: Add add_abbreviated_variable() helper,
Greg Chicares <=
- [lmi-commits] [lmi] master 118a249 097/156: Add "Column Definitions and Key Terms" page to NASD illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 1ab47c0 063/156: Fix definition of integer-valued variable in PDF illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master bb21f4d 077/156: Fix header for composite illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master d2b2cae 038/156: Change column_headings page to use external template, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 2bb1c91 041/156: Remove unnecessary outer html and body tags, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 1afd45c 040/156: Avoid spurious coding style violation, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 9695e9e 112/156: Create InitAnnLoanDueRate vector in addition to the scalar, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 5f6dc89 131/156: Use string objects for illustration_table_column fields, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master fb01571 035/156: Pass what is being expanded to interpolation function, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master fc6d8b7 034/156: Implement the "Columns Headings" page, Greg Chicares, 2018/01/30