Solved

Identify unicode format

Posted on 2004-04-20
5
290 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now