Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   C++ and Unicode support (http://www.programmingforums.org/showthread.php?t=15197)

whizzkid Feb 16th, 2008 9:04 AM

C++ and Unicode support
 
First of all - hello everybody :)

I am currently working on program that conjugates and words in various languages. Everything goes ok, but my problems started with diacritics (national letters).

I am using CPP Builder 6.0 for designing window interface, but problems began also when programming command line program. Of course the problem concerns Unicode coding. I need some to way to read Unicode characters from file, then perform actions on them and finally, display.

I must admit I am not hard-science mind, my experiences are quite modest in this field, as well as in programming in general. I have been looking for weeks for comprehensive sources for Unicode issue, but they provide only theoretical or complicated practical guides, which are beyond my understanding.

What I would like to ask you, Great Community: can you explain me in very easy way (example would be nicely seen) how to deal with the problem? I mean a several-line program that reads various characters and displays them? Telling me to use libiconv or stdstring etc. woulb be a total abstraction for me.

Any help would be greatly appreciated :)

Thanks in forward :)

PS. Since there are various Unicode formats: I need to use only latin-extended, cyrylic and greek alphabets, all in left-to-right format.

Narue Feb 16th, 2008 7:44 PM

Re: C++ and Unicode support
 
>can you explain me in very easy way (example would
>be nicely seen) how to deal with the problem?
Given your restrictions, you can do this relatively easily depending on what you mean by "then perform actions on them". Here's a simple program that reads a Windows file with the default Unicode encoding (UTF-16 little endian) and copies it character by character. Provided your standard library correctly converts between UTF-16LE and C++ wide characters, you're good:
:

  1. #include <stdio.h>
  2. #include <wchar.h>
  3.  
  4. int main ( void )
  5. {
  6.     FILE *in = fopen ( "test.txt", "r,ccs=UNICODE" );
  7.     FILE *out = fopen ( "output.txt", "r,ccs=UNICODE" );
  8.     wchar_t ch;
  9.  
  10.     while ( ( ch = fgetwc ( in ) ) != WEOF ) {
  11.         /* Process a UTF-16LE character */
  12.         fputwc ( ch, out );
  13.     }
  14.  
  15.     return 0;
  16. }

I say this because Latin Extended, Cyrillic, and Greek are all supported by Windows' Unicode fonts. This program will copy the Unicode file (be sure to save the input file as Unicode first). Each wide character will be a 16-bit entity with the code point for your character because Latin Extended, Cyrillic, and Greek are all in the Basic Multilingual Plane.

However, don't waste your time with the console. The Windows console is notoriously bad at correctly handling Unicode characters, even if you use the Lucida Console font. You'll just spend countless hours trying to troubleshoot code that works perfectly with a suitable display application.

whizzkid Feb 17th, 2008 4:20 AM

Re: C++ and Unicode support
 
Quote:

Originally Posted by Narue (Post 141149)
be sure to save the input file as Unicode first

Hmm, so the only thing I need is text editor that is able to save text in UTF-16, yup? It's a pity Notepad++ does not support it, but that's a minor problem. Thank you very much for your help :)

But I would like to ask about one more small thing. I am coding in CPP Builder 6.0 and I cannot make buttons with certain characters, as well as fill text fields or generally paste them into code. Is there an external program I shall use to "update" my sourcecode?

Ancient Dragon Feb 17th, 2008 7:04 AM

Re: C++ and Unicode support
 
>>It's a pity Notepad++ does not support it
It probably does if you have the language(s) installed on your computer.

>>I am coding in CPP Builder 6.0
Why don't you get a newer compiler that allows you to do that ?

whizzkid Feb 17th, 2008 7:05 AM

Re: C++ and Unicode support
 
I thought is is the newest version of BCB. Is whole Borland CPP Builder out of date? So which one do you recommend? :)

Ancient Dragon Feb 17th, 2008 7:07 AM

Re: C++ and Unicode support
 
I don't use it myself, but here's the Link

whizzkid Feb 17th, 2008 9:14 AM

Re: C++ and Unicode support
 
Quote:

Originally Posted by Ancient Dragon (Post 141156)
I don't use it myself, but here's the Link

I got free 6.0. I cannot afford BCB 2007. I don't want to steal...

Narue Feb 17th, 2008 9:30 AM

Re: C++ and Unicode support
 
>I cannot afford BCB 2007.
Try something free and modern then.

whizzkid Feb 17th, 2008 12:36 PM

Re: C++ and Unicode support
 
Ok thaks, I will try then :)

Ancient Dragon Feb 17th, 2008 8:34 PM

Re: C++ and Unicode support
 
There are at least two other free modern compilers too, like Dev-C++ and VC++ 2008 Express


All times are GMT -5. The time now is 4:22 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC