From: Francis Dupont Date: Tue, 18 Sep 2018 16:21:44 +0000 (+0200) Subject: [67-expressions-hexa-strings] Addressed comments X-Git-Tag: 137-improve-kea-compilation-time-2_base~8^2~1^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25ccf8586093316d72ed830743de4465540030fb;p=thirdparty%2Fkea.git [67-expressions-hexa-strings] Addressed comments --- diff --git a/doc/guide/classify.xml b/doc/guide/classify.xml index 0be70b329b..626ac7c1bc 100644 --- a/doc/guide/classify.xml +++ b/doc/guide/classify.xml @@ -718,7 +718,7 @@ Concatconcat('foo','bar')Return the concatenation of the strings Ifelseifelse('foo' == 'bar','us','them')Return the branch value according to the condition -Hexstringhexstring('foo', '-')Return the binary value as an hexadecimal string +Hexstringhexstring('foo', '-')Converts the value to a hexadecimal string, e.g. 0a:1b:2c:3e @@ -777,8 +777,8 @@ concatenation of the strings Hexstring The hexstring function "hexstring(binary, separator)" returns the binary value as its hexadecimal string representation: - pairs of hexadecimal digits separated by '-' or ':' or not - separated (separator ''). + pairs of hexadecimal digits separated by the separator, e.g + ':', '-', '' (empty separator). hexstring(pkt4.mac, ':') diff --git a/src/lib/eval/tests/evaluate_unittest.cc b/src/lib/eval/tests/evaluate_unittest.cc index 144141166d..839981c29d 100644 --- a/src/lib/eval/tests/evaluate_unittest.cc +++ b/src/lib/eval/tests/evaluate_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -509,7 +509,7 @@ TEST_F(ExpressionsTest, evaluateString) { testExpressionString(Option::V4, "hexstring(0x1234,':')", "12:34"); testExpressionString(Option::V4, "hexstring(0x56789a,'-')", "56-78-9a"); testExpressionString(Option::V4, "hexstring(0xbcde,'')", "bcde"); - testExpressionString(Option::V4, "hexstring(0xf01234,'foo')", "f01234"); + testExpressionString(Option::V4, "hexstring(0xf01234,'..')", "f0..12..34"); } }; diff --git a/src/lib/eval/token.cc b/src/lib/eval/token.cc index 402782686d..1147fdfa3b 100644 --- a/src/lib/eval/token.cc +++ b/src/lib/eval/token.cc @@ -643,11 +643,6 @@ TokenToHexString::evaluate(Pkt& /*pkt*/, ValueStack& values) { string binary = values.top(); values.pop(); - // Unknown separator is interpreted as none. - if ((separator != ":") && (separator != "-") && !separator.empty()) { - separator.clear(); - } - bool first = true; stringstream tmp; tmp << hex; diff --git a/src/lib/eval/token.h b/src/lib/eval/token.h index bba3ab9917..0d9472e54d 100644 --- a/src/lib/eval/token.h +++ b/src/lib/eval/token.h @@ -745,13 +745,13 @@ public: /// two values on the stack as parameters and push the resulting /// hexadecimal string onto the stack. /// From the top it expects the values on the stack as: - /// - separator ('-', ':' or something else interpreted as '') + /// - separator /// - binary /// /// binary is the binary value (note it can be any value, i.e. /// it is not checked to really be not printable). - /// separator is litteral '-' or ':' or something else interpreted as '' - /// i.e. no separator. + /// separator is litteral for instance '-' or ':'. The empty separator + /// means no separator. /// /// The following example use a binary MAC address 06:ce:8f:55:b3:33: /// - , '-' => "06-ce-8f-55-b3-33"