MJMRL
MJMRL

Reputation: 31

C++ Conversion UTF-8 to String

I have a web server developed in C++. In this web server, the data is received from the client side and stored in the database. Some of this data is in Persian, which is converted to Unicode UTF-8 format.
as example:

data string is "سلام" in client side
when i get data, in webserver
"D8%B3%D9%84%D8%A7%D9%85"

I want to convert UTF-8 Code to c++ string, How can I do this conversion?

Upvotes: 0

Views: 375

Answers (1)

Sebastian Hoffmann
Sebastian Hoffmann

Reputation: 2914

Your string is not UTF-8 encoded but uses a custom encoding similiar to HTTP url query params.

% indicates that the next two characters encode a single byte in hex. You will need to parse for % and if you encounter such a character, interpret the next two characters as a hexadecimal encoded byte. Otherwise you just copy the characters/bytes over.

Upvotes: 3

Related Questions