Description
Overview
Update createHeaderFooter() (util function of output()) to no longer use ${#var} for getting the number of characters in var.
Details
Currently, createHeaderFooter() uses ${#var} when counting the number of characters in var, however, some versions of some shells, like older versions of dash, count bytes not characters. Characters from the extended ASCII table, like €, are three bytes. This means that if var is €€, then dash will say the "length" is 6.
The most POSIX complaint way of determining the length of a set of characters is by using wc -m. So to get the length of var, you would do something like:
varLen=$(printf '%s' "$var" | wc -m)
# Then strip out leading spaces that are added by some `wc` implementations.
varLen=$((varLen))
Note that the unit tests that caught this are being skipped, so you'll want to re-enable them once this is fixed.
Justification
Increases the flexibility of output() by increasing the number of characters that can be used for formatting across shells.
External References
Artifact(s)
- PR
- Update how
createHeaderFooter()determines the number of characters in a variable. - Re-enable unit tests.
- Update how
Scope
Update createHeaderFooter() as described and re-enable unit tests. That's it.
Open a PR for This Issue
Relationship(s)
Found By
Found while working #3.
Related To
Completing this will impact the results found by #7.
Both this and #27 must be worked before output() will be able to take full advantage of this change.
Blocked By
#3 must be complete because that's the issue that created the unit tests that found it.t
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity
output- Change How String Length is Found #27