From 1c850b12ec686ec819ca89c4b3dbfe0803cd3a6d Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 28 Apr 2024 16:14:57 +0200 Subject: [PATCH] add a q_encode(...) method to misc --- winixd/core/misc.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/winixd/core/misc.h b/winixd/core/misc.h index d0f7246..ad70e8f 100644 --- a/winixd/core/misc.h +++ b/winixd/core/misc.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2008-2023, Tomasz Sowa + * Copyright (c) 2008-2024, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -1074,6 +1074,26 @@ void prepare_cookie_string( bool secure = false); +template +void q_encode( + const pt::TextStreamBase & in, + pt::TextStreamBase & out, + bool clear = true) +{ + if( clear ) + out.clear(); + + out << "=?UTF-8?Q?"; + + // do not use QEncode(in.c_str()) as 'in' can have a null-terminating byte + typename pt::TextStreamBase::const_iterator i = in.begin(); + + for( ; i != in.end() ; ++i) + QEncodeAddChar(*i, out); + + out << "?="; +} + } // namespace Winix