@ -11,6 +11,8 @@
# include "nfc_sets.hh"
# include <pEp/pEp_string.h>
namespace
{
// unicode to hex string
@ -628,6 +630,39 @@ std::basic_string<CharT> toNFC(basic_string_view<CharT> s)
}
// convenience function to avoid ::strdup(pEp::toNFC<char>(text).c_str());
// and unecessary temporary std::string etc.
char * strdup_NFC ( string_view s )
{
if ( isNFC_quick_check ( s ) = = IsNFC : : Yes )
return : : new_string ( s . data ( ) , s . size ( ) ) ;
// implement the hard way more efficient
/********** FIXME: need more re-work, so I'll do the dumb way first
const std : : u32string & u32 = createNFC ( fromUtf_decompose ( s ) ) ;
const size_t out_len = utf8len ( u32 ) ;
char * ret = : : new_string ( nullptr , out_len ) ;
char * iter { ret } ;
for ( const char32_t c : u32 )
{
toUtf < char , char * > ( c , iter ) ;
}
if ( iter > ret + out_len ) // should never happen. ;)
{
throw std : : logic_error ( " internal error: strdup_NFC() exceeded output string size " ) ;
}
return ret ;
* * * * * * * * * * * * * * * * * * * */
// Correct but inefficient:
const std : : string ret = toNFC < char > ( s ) ;
return : : new_string ( ret . data ( ) , 0 ) ;
}
// used only to initialize the NFC Compose mapping:
std : : map < std : : pair < unsigned , unsigned > , unsigned > generate_nfc_compose ( )
{