hb_strToUTF8 en xHarbour con BUG

Post Reply
RSalazarU
Posts: 211
Joined: Wed Jul 16, 2008 12:59 pm
Location: Cochabamba-Bolivia
Contact:

hb_strToUTF8 en xHarbour con BUG

Post 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
User avatar
karinha
Posts: 7940
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: hb_strToUTF8 en xHarbour con BUG

Post by karinha »

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
RSalazarU
Posts: 211
Joined: Wed Jul 16, 2008 12:59 pm
Location: Cochabamba-Bolivia
Contact:

Re: hb_strToUTF8 en xHarbour con BUG

Post 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


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
RSalazarU
Posts: 211
Joined: Wed Jul 16, 2008 12:59 pm
Location: Cochabamba-Bolivia
Contact:

Re: hb_strToUTF8 en xHarbour con BUG

Post by RSalazarU »

mejorando el ejemplo:

Code: Select all | Expand


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
 
Last edited by RSalazarU on Fri Aug 05, 2022 6:20 pm, edited 1 time in total.
RSalazarU
Posts: 211
Joined: Wed Jul 16, 2008 12:59 pm
Location: Cochabamba-Bolivia
Contact:

Re: hb_strToUTF8 en xHarbour con BUG

Post by RSalazarU »

yo uso: . FWH 1606 + xHarbour 10194

agote todos mis recursos, use:

HB_SetCodePage( )
FW_SetUnicode( )

.. y nada
User avatar
karinha
Posts: 7940
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: hb_strToUTF8 en xHarbour con BUG

Post by karinha »

Intenta asi:

Code: Select all | Expand


#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
RSalazarU
Posts: 211
Joined: Wed Jul 16, 2008 12:59 pm
Location: Cochabamba-Bolivia
Contact:

Re: hb_strToUTF8 en xHarbour con BUG

Post 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


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.
RSalazarU
Posts: 211
Joined: Wed Jul 16, 2008 12:59 pm
Location: Cochabamba-Bolivia
Contact:

Re: hb_strToUTF8 en xHarbour con BUG

Post by RSalazarU »

+1
User avatar
karinha
Posts: 7940
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: hb_strToUTF8 en xHarbour con BUG

Post by karinha »

Intenta asi:


Code: Select all | Expand


#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
User avatar
Carles
Posts: 1149
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona
Been thanked: 7 times
Contact:

Re: hb_strToUTF8 en xHarbour con BUG

Post 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

#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
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Otto
Posts: 6404
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 24 times
Been thanked: 2 times
Contact:

Re: hb_strToUTF8 en xHarbour con BUG

Post 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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
Post Reply