From 987e0ef942baeab764797c405601f5d397244e2e Mon Sep 17 00:00:00 2001 From: Pavel Shramov Date: Sat, 21 Dec 2024 14:08:15 +0300 Subject: [PATCH] bits: Allow both | and , separatos when parsing --- python/test/test_yaml.py | 2 ++ src/tll/conv/bits.h | 2 +- src/tll/scheme/encoder.h | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/python/test/test_yaml.py b/python/test/test_yaml.py index ee5eb2b9..ce17a14a 100644 --- a/python/test/test_yaml.py +++ b/python/test/test_yaml.py @@ -107,6 +107,8 @@ def test_enum(): ('uint16', 'A', 0x3), ('int32', 'A |B', 0x3), ('int64', 'A | 0x2', 0x3), + ('int32', 'A ,B', 0x3), + ('int32', 'A | C , B', 0x7), ]) def test_bits(t, s, v): scheme = f'''yamls:// diff --git a/src/tll/conv/bits.h b/src/tll/conv/bits.h index 9d9e12c3..acbcf504 100644 --- a/src/tll/conv/bits.h +++ b/src/tll/conv/bits.h @@ -32,7 +32,7 @@ struct parse(s)) { + for (auto v : tll::split<'|', ','>(s)) { v = tll::util::strip(v); auto r = tll::conv::select(v, desc); if (r) { diff --git a/src/tll/scheme/encoder.h b/src/tll/scheme/encoder.h index 6e79efd0..12310d6c 100644 --- a/src/tll/scheme/encoder.h +++ b/src/tll/scheme/encoder.h @@ -179,7 +179,7 @@ int ConfigEncoder::_fill_numeric(T * ptr, const tll::scheme::Field * field, std: if constexpr (!std::is_same_v) { if (field->sub_type == field->Bits) { *ptr = 0; - for (auto v : tll::split<'|'>(s)) { + for (auto v : tll::split<'|', ','>(s)) { v = tll::util::strip(v); auto b = field->type_bits->values;