FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour hb_strToUTF8 en xHarbour con BUG
Posts: 211
Joined: Wed Jul 16, 2008 12:59 PM
hb_strToUTF8 en xHarbour con BUG
Posted: Fri Aug 05, 2022 04:46 PM
Amigos del foro:

Tengo problemas con la funcion hb_strToUTF8() en xHarbour
. Los carateres 谩,茅,铆,贸,煤 los transforma corrrectamente
. EL caratere lo transforma corrrectamente
. Los carateres 脕,脥,脫,脷 NO los transforma bien, los transorma a otros caracteres

Alguien a tenido este problema

Como podria solucionarlo?

De antemano, gracias por su ayuda

Rolando
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: hb_strToUTF8 en xHarbour con BUG
Posted: Fri Aug 05, 2022 05:42 PM
Jo茫o Santos - S茫o Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 211
Joined: Wed Jul 16, 2008 12:59 PM
Re: hb_strToUTF8 en xHarbour con BUG
Posted: Fri Aug 05, 2022 06:10 PM
karinha :

Gracias por responder:

El siguiente ejemplo crea un archivo TXT, el cual al verlo con TOTALCOMANDER (F3|OPCIONES|UTF8) muestra el problema mencionado

Code (fw): Select all Collapse
Function z()
聽 聽local cStr
聽 聽cStr :="谩茅铆贸煤 脕脡脥脫脷"

聽 聽memowrit(".\ejemploUTF8.txt", hb_strtoutf8(cStr) +CRLF+ hb_strtoutf8(HB_AnsiToOem(cStr)))
return nil


De antemano, gracias por la ayuda


Rolando
Posts: 211
Joined: Wed Jul 16, 2008 12:59 PM
Re: hb_strToUTF8 en xHarbour con BUG
Posted: Fri Aug 05, 2022 06:17 PM
mejorando el ejemplo:

Code (fw): Select all Collapse
Function z()
聽 聽local cStr
聽 聽cStr :="谩茅铆贸煤 脕脡脥脫脷"

聽 聽memowrit(".\ejemploUTF8.txt", ;
聽 聽 聽 聽 聽 聽 hb_strtoutf8(cStr) +CRLF+; 聽 聽 聽 聽 聽 聽 聽 //<-esto tranforma todo mal
聽 聽 聽 聽 聽 聽 hb_strtoutf8(HB_AnsiToOem(cStr)) +CRLF+; //<-esto tranforma bien solo "谩茅铆贸煤  脡"
聽 聽 聽 聽 聽 聽 HB_StrToUTF8( cStr,"ESWIN" ) ) 聽 聽 聽 聽 聽 //<-esto tranforma a vacio
return nil
Posts: 211
Joined: Wed Jul 16, 2008 12:59 PM
Re: hb_strToUTF8 en xHarbour con BUG
Posted: Fri Aug 05, 2022 06:18 PM

yo uso: . FWH 1606 + xHarbour 10194

agote todos mis recursos, use:

HB_SetCodePage( )
FW_SetUnicode( )

.. y nada

Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: hb_strToUTF8 en xHarbour con BUG
Posted: Fri Aug 05, 2022 07:14 PM
Intenta asi:

Code (fw): Select all Collapse
#include "FiveWin.ch"

/* #translate SET CODEPAGE TO SPANISH           =>  REQUEST HB_CODEPAGE_ESWIN ; hb_setcodepage("ESWIN") */
// #translate SET CODEPAGE TO SPANISH              =>  REQUEST HB_CODEPAGE_ESWIN ; hb_cdpSelect("ESWIN")

REQUEST HB_CODEPAGE_ESWIN
REQUEST HB_LANG_ES
REQUEST HB_CODEPAGE_ES850C
REQUEST HB_CODEPAGE_ESISO

FUNCTION SALAZAR_UTF8()

   LOCAL cString, cStr

   //hb_setcodepage("ESWIN")
   //hb_cdpSelect("ESWIN")

   // O:

   HB_SETCODEPAGE('ES850C')
   HB_LANGSELECT('ES')
   
   HB_SETCODEPAGE( "UTF8" )

   cString := "脿猫茅矛霉莽"

   ? "cString: " + cString

   cStr :="谩茅铆贸煤 脕脡脥脫脷"

   ? "cStr: " + cStr

   ? HB_StrToUTF8( cStr,"ESWIN" )

RETURN NIL


Regards, saludos.
Jo茫o Santos - S茫o Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 211
Joined: Wed Jul 16, 2008 12:59 PM
Re: hb_strToUTF8 en xHarbour con BUG
Posted: Fri Aug 05, 2022 08:11 PM
Karinha:

Gracias por responder, pero no me funciona.

Este codigo tengo que aplicarlo en la FACTURACION EN LINEA para Bolivia, donde tengo que enviar un archivo XML.

Todo esta OK, salvo los acentos de mayusculas: 脕,脥,脫,脷

Aplique lo que me dijiste al codigo de ejemplo y no funciona.

Code (fw): Select all Collapse
Function z()
聽 聽local cStr

聽 聽HB_SETCODEPAGE('ES850C')
聽 聽HB_LANGSELECT('ES')
聽 聽HB_SETCODEPAGE( "UTF8" )

聽 聽cStr :="谩茅铆贸煤 脕脡脥脫脷"

聽 聽memowrit(".\ejemploUTF8.txt",;
聽 聽 聽 聽 聽 聽 hb_strtoutf8(cStr) +CRLF+;
聽 聽 聽 聽 hb_strtoutf8(HB_AnsiToOem(cStr)) +CRLF+;
聽 聽 聽 聽 HB_StrToUTF8( cStr,"ESWIN" ) )
return nil


Este codigo genera un archivo ejemploUTF8.txt, mira como se generado, por favor.

Gracias

Rolando.
Posts: 211
Joined: Wed Jul 16, 2008 12:59 PM
Re: hb_strToUTF8 en xHarbour con BUG
Posted: Mon Aug 08, 2022 03:17 PM

+1

Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: hb_strToUTF8 en xHarbour con BUG
Posted: Mon Aug 08, 2022 04:04 PM
Intenta asi:


Code (fw): Select all Collapse
#include "FiveWin.ch"

/* #translate SET CODEPAGE TO SPANISH           =>  REQUEST HB_CODEPAGE_ESWIN ; hb_setcodepage("ESWIN") */
// #translate SET CODEPAGE TO SPANISH              =>  REQUEST HB_CODEPAGE_ESWIN ; hb_cdpSelect("ESWIN")

REQUEST HB_CODEPAGE_ESWIN
REQUEST HB_LANG_ES
REQUEST HB_CODEPAGE_ES850C
REQUEST HB_CODEPAGE_ESISO

FUNCTION SALAZAR_UTF8()

   LOCAL cString, cStr

   //hb_setcodepage("ESWIN")
   //hb_cdpSelect("ESWIN")

   // O:

   HB_SETCODEPAGE('ES850C')
   HB_LANGSELECT('ES')
   
   HB_SETCODEPAGE( "UTF8" )

   cStr :="谩茅铆贸煤 脕脡脥脫脷"

   cStr  := UPPER( TiraAcento( cStr ) )

   MEMOWRIT( ".\UTF8.txt",                           ;
             hb_strtoutf8(cStr)               +CRLF+ ;
             hb_strtoutf8(HB_AnsiToOem(cStr)) +CRLF+ ;
             HB_StrToUTF8( cStr,"ESWIN" ) )

RETURN NIL

FUNCTION TiraAcento( cText )

   LOCAL ARINICIO, ARFIM, XRETTEXT, ICTEXT, LETRACTEXT

   cText := StrTran(cText,"\","/")
   cText := StrTran(cText,"脙","A")
   cText := StrTran(cText,"脗","A")
   cText := StrTran(cText,"脕","A")
   cText := StrTran(cText,"脛","A")
   cText := StrTran(cText,"脌","A")
   cText := StrTran(cText,"茫","a")
   cText := StrTran(cText,"芒","a")
   cText := StrTran(cText,"谩","a")
   cText := StrTran(cText,"盲","a")
   cText := StrTran(cText,"脿","a")
   cText := StrTran(cText,"脡","E")
   cText := StrTran(cText,"脢","E")
   cText := StrTran(cText,"脣","E")
   cText := StrTran(cText,"脠","E")
   cText := StrTran(cText,"茅","e")
   cText := StrTran(cText,"锚","e")
   cText := StrTran(cText,"毛","e")
   cText := StrTran(cText,"猫","e")
   cText := StrTran(cText,"脥","I")
   cText := StrTran(cText,"脦","I")
   cText := StrTran(cText,"脧","I")
   cText := StrTran(cText,"脤","I")
   cText := StrTran(cText,"铆","i")
   cText := StrTran(cText,"卯","i")
   cText := StrTran(cText,"茂","i")
   cText := StrTran(cText,"矛","i")
   cText := StrTran(cText,"脫","O")
   cText := StrTran(cText,"脮","O")
   cText := StrTran(cText,"脭","O")
   cText := StrTran(cText,"贸","o")
   cText := StrTran(cText,"脰","O")
   cText := StrTran(cText,"脪","O")
   cText := StrTran(cText,"玫","o")
   cText := StrTran(cText,"么","o")
   cText := StrTran(cText,"贸","o")
   cText := StrTran(cText,"枚","o")
   cText := StrTran(cText,"貌","o")
   cText := StrTran(cText,"脹","U")
   cText := StrTran(cText,"脷","U")
   cText := StrTran(cText,"脺","U")
   cText := StrTran(cText,"脵","U")
   cText := StrTran(cText,"没","u")
   cText := StrTran(cText,"煤","u")
   cText := StrTran(cText,"眉","u")
   cText := StrTran(cText,"霉","u")
   cText := StrTran(cText,"脟","C")
   cText := StrTran(cText,"莽","c")
   cText := StrTran(cText,"拢","E")
   cText := StrTran(cText,"&","E")
   cText := StrTran(cText,"<",".")
   cText := StrTran(cText,">",".")
   cText := StrTran(cText,"陋","a")
   cText := StrTran(cText,"潞","o")
   cText := StrTran(cText,"麓"," ")
   cText := StrTran(cText,"虏","2")
   cText := StrTran(cText,"鲁"," ")
   cText := StrTran(cText,"鹿","1")

   arINICIO := 32
   arFIM    := 126
   xRetText := ""

   For IcText=1 to len(cText)

      LetracText := subs( cText, IcText, 1 )

      if asc(LetracText)<arINICIO .or. asc(LetracText)>arFIM

         LetracText := " "

      end

      xRetText += LetracText

   next

RETURN(xRetText)


Regards, saludos.
Jo茫o Santos - S茫o Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: hb_strToUTF8 en xHarbour con BUG
Posted: Tue Aug 09, 2022 08:48 AM
Hola,

Siempre comento que es muy importante comprobar en que codificas tu c贸digo. Si tenemos este simple codigo:

Code (fw): Select all Collapse
#include 'fivewin.ch'

Function main()
聽 聽local cStr :="脿谩茅猫铆貌贸煤 脌脕脠脡脥脪脫脷 帽脩莽C"
聽
聽 聽memowrit( "z1.txt", cStr ) 
聽 
retu nil


Y lo codificamos en ANSI, el fichero resultante est脿 en ANSI, seguramente si le das un previsualizar al fichero lo veas bien, mientras que si lo codificamos con el editor en UTF8 el fichero resultante est脿 en utf8. Cuando digo codificar, hablo de como tienes configurado tu editor.

Es mas si pruebas de coger el fichero que esta en utf8 y lo lees con tu editor en ansi veras un carajo. Y asi un monton de combinaciones. 脡s muy importante tener claro todo el tipo de codificaciones.



Es mas, en entorno web hay como una mania de usar el utf8 si usamos dbfs, la mayoria codifcadas en ansi, con lo que te obligas a realizar conversiones continuamente,...

Un mundo :-)
Salutacions, saludos, regards

"...programar es f谩cil, hacer programas es dif铆cil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: hb_strToUTF8 en xHarbour con BUG
Posted: Tue Aug 09, 2022 09:40 AM

Hello Carles,
Thanks for your info.
I have been looking for so long for a display where you can see the different codings.
Thanks to your screenshot I have now found out that it is possible with

The internal file lister (F3) of TotalComander

The integrated file lister allows to view files of almost any size (now up to 2^63 bytes) in text, Unicode, HTML, binary or hex format, bitmap graphics (bmp, jpg, gif, png), multimedia files, and now also RTF files. It keeps only a small part of the file in memory (except for bitmaps), the rest is automatically loaded when scrolling through the text.

Best regards,
Otto

Continue the discussion