From e78510aef1182b39b22b03a54cbc2e91c641d4f0 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Mon, 16 Dec 2024 11:34:53 +0100 Subject: [PATCH] Move implementation of `Bytes::[lower|upper]` to cc file. --- hilti/runtime/include/types/bytes.h | 11 ++--------- hilti/runtime/src/tests/integer.cc | 1 + hilti/runtime/src/tests/union.cc | 1 + hilti/runtime/src/types/bytes.cc | 8 ++++++++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/hilti/runtime/include/types/bytes.h b/hilti/runtime/include/types/bytes.h index 77d34a0a7..58594f1fa 100644 --- a/hilti/runtime/include/types/bytes.h +++ b/hilti/runtime/include/types/bytes.h @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -445,10 +444,7 @@ class Bytes : protected std::string { * @param errors how to handle errors when decoding/encoding the data * @return an upper case version of the instance */ - Bytes upper(unicode::Charset cs, - unicode::DecodeErrorStrategy errors = unicode::DecodeErrorStrategy::REPLACE) const { - return hilti::rt::string::encode(hilti::rt::string::upper(decode(cs, errors), errors), cs, errors); - } + Bytes upper(unicode::Charset cs, unicode::DecodeErrorStrategy errors = unicode::DecodeErrorStrategy::REPLACE) const; /** * Returns an upper-case version of the instance. @@ -457,10 +453,7 @@ class Bytes : protected std::string { * @param errors how to handle errors when decoding/encoding the data * @return a lower case version of the instance */ - Bytes lower(unicode::Charset cs, - unicode::DecodeErrorStrategy errors = unicode::DecodeErrorStrategy::REPLACE) const { - return hilti::rt::string::encode(hilti::rt::string::lower(decode(cs, errors), errors), cs, errors); - } + Bytes lower(unicode::Charset cs, unicode::DecodeErrorStrategy errors = unicode::DecodeErrorStrategy::REPLACE) const; /** * Removes leading and/or trailing sequences of all characters of a set diff --git a/hilti/runtime/src/tests/integer.cc b/hilti/runtime/src/tests/integer.cc index c186b25be..a1885adb4 100644 --- a/hilti/runtime/src/tests/integer.cc +++ b/hilti/runtime/src/tests/integer.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include using namespace hilti::rt; diff --git a/hilti/runtime/src/tests/union.cc b/hilti/runtime/src/tests/union.cc index 7b76a134b..d21a953c1 100644 --- a/hilti/runtime/src/tests/union.cc +++ b/hilti/runtime/src/tests/union.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include using namespace hilti::rt; diff --git a/hilti/runtime/src/types/bytes.cc b/hilti/runtime/src/types/bytes.cc index 359a42072..1b1bd84c8 100644 --- a/hilti/runtime/src/types/bytes.cc +++ b/hilti/runtime/src/types/bytes.cc @@ -176,6 +176,10 @@ Bytes Bytes::strip(bytes::Side side) const { cannot_be_reached(); } +Bytes Bytes::upper(unicode::Charset cs, unicode::DecodeErrorStrategy errors) const { + return string::encode(string::upper(decode(cs, errors), errors), cs, errors); +} + integer::safe Bytes::toInt(uint64_t base) const { int64_t x = 0; if ( hilti::rt::atoi_n(str().begin(), str().end(), base, &x) == str().end() ) @@ -250,6 +254,10 @@ double Bytes::toReal() const { return d; } +Bytes Bytes::lower(unicode::Charset cs, unicode::DecodeErrorStrategy errors) const { + return string::encode(string::lower(decode(cs, errors), errors), cs, errors); +} + Result Bytes::match(const RegExp& re, unsigned int group) const { auto groups = re.matchGroups(*this);