1

Is there any equivalent function to strstr and sprintf for char16_t type?

Also, where could I find the remaining functions of char16_t?

doptimusprime
  • 8,715
  • 6
  • 49
  • 86
  • 1
    The UTF-16 equivalent of strstr is [wcsstr](http://www.cplusplus.com/reference/cwchar/wcsstr/). Here is the complete list: http://www.cplusplus.com/reference/cwchar/wcsstr/. And here is a Must-Read link: http://www.joelonsoftware.com/articles/Unicode.html – paulsm4 May 23 '13 at 05:37
  • 2
    Beware: wide char are not UTF-16 on every systems. AFAIK, on Linux `wchar_t` is a 32 bits integral type. – Basile Starynkevitch May 23 '13 at 05:39
  • @Basile Starynkevitch - good point. The link I cited tries to make clear that Unicode != UTF-16 != UCS-2 != char16_t (like 1990's era Windows NT or Java programming might have you believe). – paulsm4 May 23 '13 at 05:41
  • One additional link: http://stackoverflow.com/questions/4588302/why-isnt-wchar-t-widely-used-in-code-for-linux-related-platforms – paulsm4 May 23 '13 at 05:45

1 Answers1

3

I don't think there are such functions.

If sizeof(char16_t) == sizeof(wchar_t) you could use the wide string functions like wsprintf

Caveat: sizeof(wchar_t) == sizeof(int32_t) on Linux!

And you can always use (in C++11) the std::u16string

Perhaps you might consider using Qt5 QChar (almost like a char16_t in UTF16) and QString. You'll only need to link QtCore for that. Then QString::arg is similar (but not equivalent) to what sprintf can offer.

As I commented, float to string conversion is tricky. Perhaps some code from MUSL libc (free software, MIT license) could inspire you, and you might borrow some of it.

Basile Starynkevitch
  • 216,767
  • 17
  • 275
  • 509