Solved

Identify unicode format

Posted on 2004-04-20
5
292 Views
Last Modified: 2010-04-15
I would like to know the encoding used for a given string in C. Means, I have a character buffer and like to know the data is in UTF-8 format or UTF-16 format. So that I can process my data accordingly.

Is there any standard function available for the same. If not, how will I do the same.

Thanks in Advance!
Deepak Kumar

0
Comment
Question by:deepakg76
5 Comments
 
LVL 12

Expert Comment

by:stefan73
ID: 10869660
Hi deepakg76,
> UTF-8 format or UTF-16
You need to check the BOM (byte order mark). It's at the beginning of a properly encoded unicode text file.

More details:
http://www.unicode.org/unicode/faq/utf_bom.html#BOM


Cheers,
Stefan
0
 

Author Comment

by:deepakg76
ID: 10887202
Thanks for the reply...

It is helpful only if i want to read the content from a file. If I have char buffer from another application or dll. I want to know from the string data that buffer is having utf-8 or utf-16 data. So that i can process accordingly.

Deepak
0
 
LVL 3

Accepted Solution

by:
mjzalewski earned 20 total points
ID: 10992297
It's not possible to do this directly. You have to know what encoding format is being used by the application which sends the character buffer.

Encoding marks such as the BOM are specifically not recommended when the text data is already typed. So for example, there would be no BOM mark stored in a database -- the type of the column and the database environment would determine whether the data was utf-8 or utf-16.

You could use a heuristic. Odd length is certainly utf-8. Embedded 0x00, especially in even positions would certainly be utf-16. But there are buffers, especially short ones, which have equally valid utf-8 and utf-16 interpretations.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question