At the end I have tried to use hb_LangSelect() function when codepage was "ITWIN"
a) hb_LangSelect( "it" )
b) hb_LangSelect( hb_UserLang() )
but always I get RTE --> Error BASE/1303 Argument error: __HB_LANGSELECT
Hi guys, can someone help me to understand code page handling? I read a lot on this forum, but...
I'm Italian and I need to use symbols like these �����
Here a little code as reference
1� PROCEDURE Main()
2��� LOCAL cFileName := hb_FnameMerge( hb_DirBase(), "prova", "txt" )
3��� LOCAL cText
4��� CLS
5��� ? "current is " + hb_cdpSelect()
6��� IF !hb_FileExists( cFileName )
7������ cText := "I'm Italian so I need � �"� (utf8 latin_e_grave and Euro_Sign)
8������ hb_MemoWrit( cFileName, cText )
9��� ENDIF
10�� cText := hb_MemoRead( cFileName )
11�� ? "text is :" + cText
12�� INKEY( 0 )
13
14 RETURN
OUTPUT: file is right, on video is wrong: OK because current language is EN (as I can see on line 5)
To solve my problem I have modified the source code like this
1� REQUEST HB_CODEPAGE_ITWIN
2� PROCEDURE Main()
3��� LOCAL cFileName := hb_FnameMerge( hb_DirBase(), "prova", "txt" )
4��� LOCAL cText
5��� hb_CdpSelect( "ITWIN" )
6��� hb_SetTermCP( "ITWIN", .T. )
7��� CLS
8��� ? "current is " + hb_cdpSelect()
9��� IF !hb_FileExists( cFileName )
10����� cText := "I'm Italian so I need � �"
11����� hb_MemoWrit( cFileName, cText )
12��� ENDIF
13�� cText := hb_MemoRead( cFileName )
14�� ? "text is :" + cText
15�� INKEY( 0 )
16
17 RETURN
OUTPUT: file is right, on video is wrong: WHY? Current language is IT (as I can see on line 8)
I have modified my code at line 10
10����� cText := "I'm Italian so I need "+ hb_Uchar( 0xE8 ) + "::" + hb_Uchar( 0x20AC )
OUTPUT: file is right, on video I can see latin_e_grave (OK) but I can't see Euro_sign: WHY? Current language is IT (as I can see on line 8)
I have modified my code at line 13 using different functions
13�� cText := hb_Utf8ToStr( hb_MemoRead( cFileName ) )
13�� cText := hb_Translate( hb_MemoRead( cFileName ), "UTF8", hb_CdpSelect() )
with or without REQUEST HB_CODEPAGE_UTF8
OUTPUT: file is right, on video is wrong: WHY? Current language is IT (as I can see on line 8)
AFAIK from this point I can't use some CLIPPER functions and I need to use Harbour extensions (ie hb_utf8At or hb_utf8RAt)
I have modified code in this way:
1� REQUEST HB_CODEPAGE_UTF8
5��� hb_CdpSelect( "UTF8" )
6��� hb_SetTermCP( "UTF8", .T. )
13�� cText := hb_MemoRead( cFileName )
OUTPUT: file is right, on video is wrong: WHY? Current language is UTF8 (as I can see on line 8)
I have modified my code using UTF8EX
OUTPUT: file is right, on video is wrong: WHY? Current language is UTF8EX (as I can see on line 8)
Have you tried to use utf8tostr()
Il 29/11/2013 21.43, Alain Aupeix ha scritto:
Have you tried to use utf8tostr()Hi Alain, I'm doing some test but I think the problem can be related with OS code page (850 I'm on Windows Xp).
with these two functions I have no problem to display utf8 strings
You have also the function strtoutf8 wcich allos for example to save in utf8 text files.
As I understand 858 is descripted as "OEM - Multilanguage Latin I + Euro" (installed on my system), but Harbour it doesn't support this code.
I believe that for western Europa best choice is codepage CP1252, superset of latin1/iso8859-1.
It has almost all glyphs of cp850 but in other position. Conversion should be ok.
Klas, can you please recap how console, hvm and dbf codepages interact ? And how safely conver from cp850 to cp1252 source, runtime, dbf...
So far you have mentioned CP850, 858, ITWIN and UTF8. That is a lot :-). So I can't help wondering what your real goal is. Do you get UTF8 encoded files from external sources and have to convert them? Or is it the other way around? Or are you just building an application with normal keyboard input and want to save what the user types?
All the characters you mentioned in your original post exist in the "Windows Western" character set as far as I can see (You can check that in Accessories -> System Tools -> Character Set or some similar wording in the start menu� -� select Lucida Console and Windows Western for example). And Windows Western means a "WIN" or "ISO" codepage in Harbour. I can understand why the guys in Eastern Europe are so fond of UTF8, but IMHO the average user in Western Europe seldom needs it. So do you have any special needs in addition to the Euro sign and the accented characters (grave and acute) that you mentioned?
Also, as you are already aware of, using UTF8 requires a different approach to string handling with functions like the standard at() function not working properly and requiring special UTF8 versions instead. Saving UTF8 strings in dbfs is also a problem because you do not know exactly how much more room you are going to need in the character fields.
In most cases in Western Europe it should be enough to use the "xxWIN" codepage for the "xx" language used in the country. Like this:
set( _SET_CODEPAGE, "ITWIN" )
in your case.
Next question: Is this a new application you are writing or do you have a long history of CP850 coded dbf files that you must still support? You can convert automatically between "ITWIN" in the HVM and "IT850" or something like that in the dbf files with:
set( _SET_CODEPAGE, "ITWIN" )
set( _SET_DBCODEPAGE, "IT850" )
But I suspect that some of the accented characters will not convert correctly. If so, using "ITWIN" in the dbf files is preferable ... if it is possible to convert the old data.
Also, looking at this line:
cText := "I'm Italian so I need � �"� (utf8 latin_e_grave and Euro_Sign)
How is that text encoded? What is the codepage used by the editor? Is it UTF8? It should be the same as the set( _SET_CODEPAGE ) codepage used in the application.
|
Questa e-mail � priva di virus e malware perch� � attiva la protezione avast! Antivirus . |
|
Questa e-mail è priva di virus e malware perché è attiva la protezione avast! Antivirus . |