Page 1 of 1

hb_strToUTF8 en xHarbour con BUG

PostPosted: Fri Aug 05, 2022 4:46 pm
by RSalazarU
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

Re: hb_strToUTF8 en xHarbour con BUG

PostPosted: Fri Aug 05, 2022 5:42 pm
by karinha

Re: hb_strToUTF8 en xHarbour con BUG

PostPosted: Fri Aug 05, 2022 6:10 pm
by RSalazarU
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: Select all  Expand view

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

Re: hb_strToUTF8 en xHarbour con BUG

PostPosted: Fri Aug 05, 2022 6:17 pm
by RSalazarU
mejorando el ejemplo:

Code: Select all  Expand view

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
 

Re: hb_strToUTF8 en xHarbour con BUG

PostPosted: Fri Aug 05, 2022 6:18 pm
by RSalazarU
yo uso: . FWH 1606 + xHarbour 10194

agote todos mis recursos, use:

HB_SetCodePage( )
FW_SetUnicode( )

.. y nada

Re: hb_strToUTF8 en xHarbour con BUG

PostPosted: Fri Aug 05, 2022 7:14 pm
by karinha
Intenta asi:

Code: Select all  Expand view

#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.

Re: hb_strToUTF8 en xHarbour con BUG

PostPosted: Fri Aug 05, 2022 8:11 pm
by RSalazarU
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: Select all  Expand view

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.

Re: hb_strToUTF8 en xHarbour con BUG

PostPosted: Mon Aug 08, 2022 3:17 pm
by RSalazarU
+1

Re: hb_strToUTF8 en xHarbour con BUG

PostPosted: Mon Aug 08, 2022 4:04 pm
by karinha
Intenta asi:


Code: Select all  Expand view

#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.

Re: hb_strToUTF8 en xHarbour con BUG

PostPosted: Tue Aug 09, 2022 8:48 am
by Carles
Hola,

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

Code: Select all  Expand view
#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.

Image

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 :D

Re: hb_strToUTF8 en xHarbour con BUG

PostPosted: Tue Aug 09, 2022 9:40 am
by Otto
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