configuration: --parser-option bit-string-symbol-0 bit-string-symbol-1 – custom symbols e.g. .:, -+, \/
--- a/bash-completion.sh Thu Jul 22 20:01:03 2021 +0200
+++ b/bash-completion.sh Wed Jul 28 01:40:05 2021 +0200
@@ -67,6 +67,8 @@
"tree-style"
"tree-with-namespaces"
"root-name"
+ "bit-string-symbol-0"
+ "bit-string-symbol-1"
);
ENCODINGS=(
@@ -107,6 +109,8 @@
elif [[ "$w2" == "--parser-option" && "$w1" == "tree-style" ]]; then COMPREPLY=($(compgen -W "${TREE_STYLES[*]}" -- "$w0"))
elif [[ "$w2" == "--parser-option" && "$w1" == "tree-with-namespaces" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
elif [[ "$w2" == "--parser-option" && "$w1" == "root-name" && "x$w0" == "x" ]]; then COMPREPLY=("'asn1'")
+ elif [[ "$w2" == "--parser-option" && "$w1" == "bit-string-symbol-0" && "x$w0" == "x" ]]; then COMPREPLY=("'0'")
+ elif [[ "$w2" == "--parser-option" && "$w1" == "bit-string-symbol-1" && "x$w0" == "x" ]]; then COMPREPLY=("'1'")
else
OPTIONS=(
--- a/src/lib/GenericASN1ContentHandler.h Thu Jul 22 20:01:03 2021 +0200
+++ b/src/lib/GenericASN1ContentHandler.h Wed Jul 28 01:40:05 2021 +0200
@@ -39,6 +39,8 @@
XMLContentHandlerProxy handlers;
std::string rootName = "asn1";
+ std::string bitStringSymbol0 = "0";
+ std::string bitStringSymbol1 = "1";
bool treeWithNamespaces = false;
/**
@@ -98,6 +100,8 @@
else if (uri == xml::TreeWithNamespaces) treeWithNamespaces = parseBoolean(value);
else if (uri == xml::TreeStyle && value == "standard"); // the only style currently supported
else if (uri == xml::TreeStyle && value == "literal") throw std::invalid_argument("Tree style 'literal' is not yet supported"); // will require ASN.1 schema, might be implemented in another class
+ else if (uri == xml::BitStringSymbol0) bitStringSymbol0 = value;
+ else if (uri == xml::BitStringSymbol1) bitStringSymbol1 = value;
else if (uri == xml::TreeStyle) throw std::invalid_argument("Unsupported tree-style: " + value);
else return false;
@@ -165,8 +169,7 @@
void writeBitString(const Header& header, std::vector<bool> value) override {
std::stringstream bits;
- for (bool b : value) bits << (int) b;
- // for (bool b : value) bits << (b ? ':' : '.'); // TODO: configurable true/false symbols?
+ for (bool b : value) bits << (b ? bitStringSymbol1 : bitStringSymbol0);
handlers.writeStartElement("bit-string", getCommonAttributes(header,{"length", std::to_string(value.size())}));
handlers.writeCharacters(bits.str());
handlers.writeEndElement();
--- a/src/lib/uri.h Thu Jul 22 20:01:03 2021 +0200
+++ b/src/lib/uri.h Wed Jul 28 01:40:05 2021 +0200
@@ -43,6 +43,8 @@
static const char* TreeWithNamespaces = "tree-with-namespaces";
static const char* TreeStyle = "tree-style";
static const char* RootName = "root-name";
+static const char* BitStringSymbol0 = "bit-string-symbol-0";
+static const char* BitStringSymbol1 = "bit-string-symbol-1";
static const char* XMLNS = "tag:globalcode.info,2018:alt2xml:TEMPORARY:asn1"; // not an option and might change, just preliminary namespace
}