diff options
-rw-r--r-- | logd/src/logd/proto_converter.cpp | 5 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/text/utf8.cpp | 8 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/text/utf8.h | 5 |
3 files changed, 11 insertions, 7 deletions
diff --git a/logd/src/logd/proto_converter.cpp b/logd/src/logd/proto_converter.cpp index e72e58fba70..075fbe4bd50 100644 --- a/logd/src/logd/proto_converter.cpp +++ b/logd/src/logd/proto_converter.cpp @@ -62,13 +62,12 @@ ProtoConverter::log_message_to_proto(const LogMessage& message, ProtoLogMessage& proto.set_level(convert_level(message.level())); const std::string &payload = message.payload(); vespalib::Utf8Reader reader(payload.c_str(), payload.size()); - vespalib::string tmp; - vespalib::Utf8Writer writer(tmp); + std::string filtered_payload; + vespalib::Utf8Writer writer(filtered_payload); while (reader.hasMore()) { uint32_t ch = reader.getChar(); writer.putChar(ch); } - std::string filtered_payload(tmp.c_str(), tmp.size()); proto.set_payload(filtered_payload); } diff --git a/vespalib/src/vespa/vespalib/text/utf8.cpp b/vespalib/src/vespa/vespalib/text/utf8.cpp index 660178aaaa1..8f73479f10f 100644 --- a/vespalib/src/vespa/vespalib/text/utf8.cpp +++ b/vespalib/src/vespa/vespalib/text/utf8.cpp @@ -175,8 +175,9 @@ Utf8ReaderForZTS::getComplexChar(unsigned char firstbyte, uint32_t fallback) } -Utf8Writer& -Utf8Writer::putChar(uint32_t codepoint) +template <typename Target> +Utf8Writer<Target>& +Utf8Writer<Target>::putChar(uint32_t codepoint) { if (codepoint < 0x80) { _target.push_back((char)codepoint); @@ -229,5 +230,8 @@ Utf8Writer::putChar(uint32_t codepoint) return *this; } +template class Utf8Writer<vespalib::string>; +template class Utf8Writer<std::string>; + } // namespace vespalib diff --git a/vespalib/src/vespa/vespalib/text/utf8.h b/vespalib/src/vespa/vespalib/text/utf8.h index 5a8786707e5..d2b8204ce08 100644 --- a/vespalib/src/vespa/vespalib/text/utf8.h +++ b/vespalib/src/vespa/vespalib/text/utf8.h @@ -321,9 +321,10 @@ public: /** * @brief Writer class that appends UTF-8 characters to a string **/ +template <typename Target> class Utf8Writer : public Utf8 { - string &_target; + Target &_target; public: /** * construct a writer appending to the given string @@ -331,7 +332,7 @@ public: * that the writer will append to. Must be writable * and must be kept alive while the writer is active. **/ - Utf8Writer(string &target) : _target(target) {} + Utf8Writer(Target &target) : _target(target) {} /** * append the given character to the target string. |