Hi Axel,

Axel Simon <axel.si...@in.tum.de> writes:

> Hi Andy,
>
> I don't think this behaviour is always desirable for all applications. Some 
> applications might
> prefer to catch an error exception while  others might be happy to simply 
> ignore the error as your
> fix would do.
Yes, i was think that when i'm writing this patch.

Now i think throw error perhaps is better idea, user can catch
invalid utf-8 error, and traceShow can't since it just ignore
error.

>
> In which situations do these functions not work for you? Couldn't you use 
> some other utf8 Haskell
> package to check for the correctness of  strings?
I'm testing gio-branch APIs for merge (after 0.11.1), today i got
fromUTF crash when i call fileInfoGetName
(https://patch-tag.com/r/AndyStewart/gio-branch/snapshot/current/content/pretty/System/GIO/File/FileInfo.chs).

Now i realize it's my fault that binding readUTFString to
g_file_info_get_name since g_file_info_get_name just return "byte
string" and not return UTF8.

I should use g_file_info_get_name for real filename,
and g_file_info_get_display_name for UTF8 display name.

I will fix those binding problem in gio-branch, please ignore this patch.

BTW, i was thinking about how to provide a good interface to handle
*mix* encoding environment. 
Some plan like this:

  1) Develop some haskell "encoding detector" like python-chardet
  (http://chardet.feedparser.org/) Automatic detect input string encoding.

  2) Then use g_convert functoin convert input string to UTF8
  
(http://library.gnome.org/devel/glib/stable/glib-Character-Set-Conversion.html)
  
Then we can convert all character-set to UTF8, it's very useful for gtk2hs 
editor/file-manager. 

Cheers,

  -- Andy

>
> Cheers,
> Axel
>
> On 29.06.2010, at 08:34, Andy Stewart wrote:
>
>> 1 patch for repository andystew...@code.haskell.org:/srv/code/gtk2hs:
>>
>> Tue Jun 29 14:32:43 CST 2010  Andy Stewart <lazycat.mana...@gmail.com>
>>  * Use traceShow replace error provide safer fromUTF.
>>
>> New patches:
>>
>> [Use traceShow replace error provide safer fromUTF.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100629063243
>> Ignore-this: 4ccec77e1d2b1405b979e14ec1818077
>> ] {
>> hunk ./glib/System/Glib/UTFString.hs 50
>>
>> import Control.Monad (liftM)
>> import Data.Char (ord, chr)
>> +import Debug.Trace
>>
>> import System.Glib.FFI
>>
>> hunk ./glib/System/Glib/UTFString.hs 170
>> fromUTF :: String -> String
>> fromUTF [] = []
>> fromUTF (all@(x:xs)) | ord x<=0x7F = x:fromUTF xs
>> -                 | ord x<=0xBF = err
>> +                 | ord x<=0xBF = noconvert all
>>                   | ord x<=0xDF = twoBytes all
>>                   | ord x<=0xEF = threeBytes all
>> hunk ./glib/System/Glib/UTFString.hs 173
>> -                 | otherwise   = err
>> +                 | otherwise   = noconvert all
>>   where
>>     twoBytes (x1:x2:xs) = chr (((ord x1 .&. 0x1F) `shift` 6) .|.
>>                             (ord x2 .&. 0x3F)):fromUTF xs
>> hunk ./glib/System/Glib/UTFString.hs 177
>> -    twoBytes _ = error "fromUTF: illegal two byte sequence"
>> +    twoBytes str = traceShow ("fromUTF Warning: " ++ str ++ " has illegal 
>> two byte sequence, no
>> convert!") str
>>
>>     threeBytes (x1:x2:x3:xs) = chr (((ord x1 .&. 0x0F) `shift` 12) .|.
>>                                  ((ord x2 .&. 0x3F) `shift` 6) .|.
>> hunk ./glib/System/Glib/UTFString.hs 182
>>                                  (ord x3 .&. 0x3F)):fromUTF xs
>> -    threeBytes _ = error "fromUTF: illegal three byte sequence"
>> +    threeBytes str = traceShow ("fromUTF Warning: " ++ str ++ " has illegal 
>> three byte sequence,
>> no convert!") str
>>
>> hunk ./glib/System/Glib/UTFString.hs 184
>> -    err = error "fromUTF: illegal UTF-8 character"
>> +    noconvert str = traceShow ("fromUTF Warning: " ++ str ++ " has illegal 
>> UTF-8 character, no
>> convert!") str
>>
>> -- Offset correction for String to UTF8 mapping.
>> --
>> }
>>
>> Context:
>>
>> [Update Embedded demos.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100628072541
>> Ignore-this: 1792a53558175309e474755b2fd170ab
>> ]
>> [Add function drawableGetID.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100628071306
>> Ignore-this: 66f80a911f63867209160d53e51c8498
>> ]
>> [Fix freeHaskellFunPtr problem in Clipboard.chs
>> Andy Stewart <lazycat.mana...@gmail.com>**20100627113550
>> Ignore-this: efa86a719456d15b01eaaed62393f78f
>> ]
>> [Apply Oleg's patch to fix clipboardRequestTargets segfault.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100627103336
>> Ignore-this: 5602ff1727f889cdccc5bc2cb0f7353c
>> ]
>> [Add MPlayer client demo.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100617090640
>> Ignore-this: 5a8ab681c148ca07f27f768f9f62b1b7
>> ]
>> [Move hierarchy.list to gtk package (Don't need reinstall gtk2hs-
>> buildtools after add new type)
>> Andy Stewart <lazycat.mana...@gmail.com>**20100604131309
>> Ignore-this: d3f52ea66e784a2ecd66d764571f58a9
>> ]
>> [Move hierarchy.list to gio package (Don't need reinstall gtk2hs-
>> buildtools after add new type)
>> Andy Stewart <lazycat.mana...@gmail.com>**20100604130442
>> Ignore-this: 7539a9c035e4f25ac54d619c92021f49
>> ]
>> [Move hierarchy.list to pango package (Don't need reinstall gtk2hs-
>> buildtools after add new type)
>> Andy Stewart <lazycat.mana...@gmail.com>**20100604130210
>> Ignore-this: b2ebce6749cf1083f3810e6175ceb1a2
>> ]
>> [Fix INSTALL
>> Andy Stewart <lazycat.mana...@gmail.com>**20100604095408
>> Ignore-this: 832b7cff47d7200ee89ee797981febee
>> ]
>> [Create Gtk specific versions of functions that add something to the main 
>> loop. These specific
>> functions acquire the Gtk lock before  executing the action which the 
>> documentation promised
>> but...
>> axel.si...@in.tum.de**20100603153700]
>> [Improve signal `queryTooltip`
>> Andy Stewart <lazycat.mana...@gmail.com>**20100602070555
>> Ignore-this: 4b625d69ebb779f22ec57ae0cc5223aa
>> ]
>> [Add MenuToolButton support functions for Tooltip.chs
>> Andy Stewart <lazycat.mana...@gmail.com>**20100601165857
>> Ignore-this: 9e153056f052f09f3bf7bd5569ce347c
>> ]
>> [Fix `widgetTooltipMarkup` and docs.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100601144701
>> Ignore-this: 3fc33fd561f18f221d8b7b0215c71826
>> ]
>> [Fix function `tooltipSetMarkup`
>> Andy Stewart <lazycat.mana...@gmail.com>**20100601143948
>> Ignore-this: b4af7ecca1bc74b22e20727f33729a8b
>> ]
>> [Add Widget support functions for Tooltip.chs
>> Andy Stewart <lazycat.mana...@gmail.com>**20100601140304
>> Ignore-this: 6b10098119f7a416d763c834bd892cae
>> ]
>> [Add Tooltip.chs (The new module to replace Tooltips.chs)
>> Andy Stewart <lazycat.mana...@gmail.com>**20100601131828
>> Ignore-this: ca64d1d45d3c526494a41fb537d16c6c
>> ]
>> [Clean bootstrap.sh
>> Andy Stewart <lazycat.mana...@gmail.com>**20100601122113
>> Ignore-this: f59b5f9bf21945c39258a39432621a03
>> ]
>> [Note that Cabal 1.8 is required for ghci support under Windows.
>> axel.si...@in.tum.de**20100527181310
>> Ignore-this: 1c5fc3bb7ad83f5d1094e0083ddd9913
>> ]
>> [Do not query g_object_get_type as it only exists in newer Gtk+ versions.
>> axel.si...@in.tum.de**20100527163435
>> Ignore-this: 70d62f66a2eb159c7fd3e23079c5debf
>> ]
>> [Remove gnomevfs sourceview mozembed since those packages has deprecated.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100527124728
>> Ignore-this: a1dfda3669b7417a7b09c3b4acfaa2d
>>
>> Below are backup repositories for those deprecated packages:
>>
>>  * gnomevfs          : http://www2.in.tum.de/~simona/gnomevfs/
>>  * sourceview        : http://www2.in.tum.de/~simona/sourceview/
>>  * mozembed          : http://www2.in.tum.de/~simona/mozembed/
>>
>> ]
>> [Fix IconTheme.chs docs.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100527102140
>> Ignore-this: 2f2b7ab508c688cc73f1b59012966d13
>> ]
>> [Fix Gtk2HsSetup.hs bug.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100527095530
>> Ignore-this: 1b65945da174e05d0ad2a1f01e2ee651
>> ]
>> [Add gnomevfs demo directory.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100527061234
>> Ignore-this: 40c6dd74b460d7546937212dacf1f9e1
>> ]
>> [Add gtk demo directory.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100527061041
>> Ignore-this: 876a827c6f1bac1a8b26a99cd68c6005
>> ]
>> [Add cairo demo directory.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100527051924
>> Ignore-this: b1a70c2a24812fb84c899e4e8ce3ca6c
>> ]
>> [Add pango demo directory.
>> Andy Stewart <lazycat.mana...@gmail.com>**20100527051205
>> Ignore-this: af1ff611ab459ee2b6c5bc09a3f63c11
>> ]
>> [Fix the license of gnomevfs
>> Andy Stewart <lazycat.mana...@gmail.com>**20100527035350
>> Ignore-this: 9ac7c768af168d6f0c7af8c8790e8643
>> ]
>> [Fix the license of gio.
>> axel.si...@in.tum.de**20100526152125
>> Ignore-this: 42fe27de2030e0395227f889ba5345d8
>> ]
>> [Fix Trac #1164. toGSList was reversing lists.
>> m.ni...@gmail.com**20090514122933
>> Ignore-this: c466eadbc5ae61ba71721fe15b44735a
>> ]
>> [Remove gconf glade gstreamer gtkglext gtksourceview2 soegtk svgcairo vte 
>> webkit since these all
>> now have their own repos.
>> axel.si...@in.tum.de**20100525211947]
>> [Documentation fix for EventM.
>> axel.si...@in.tum.de**20100525131428
>> Ignore-this: 25c3bf3513ec6467cbd0febe397ab53e
>> ]
>> [Put upper bounds on base version.
>> axel.si...@in.tum.de**20100525082101
>> Ignore-this: f92b2d9970c436c9fcbcf141fc988e8
>> ]
>> [Make documentation parsable.
>> axel.si...@in.tum.de**20100525080209
>> Ignore-this: 60f44b8251a9f3e933c874f72d8e8801
>> ]
>> [Make the version test in pango less complex as Cabal 1.6 doesn't parse it 
>> otherwise.
>> axel.si...@in.tum.de**20100525075706
>> Ignore-this: f3446237cf66abf49e81bd4ba8ef9744
>> ]
>> [Fix an incorrect pattern in windowSetIcon.
>> axel.si...@in.tum.de**20100525075639
>> Ignore-this: eb596c778897b4ae4fd7f9a8dde59726
>> ]
>> [Get rid of stock images under ./docs/reference/images
>> Andy Stewart <lazycat.mana...@gmail.com>**20100524235315
>> Ignore-this: 1094aaf32c73ba189937e1beee24ee49
>> ]
>> [Redirect image link to library.gnome.org and update image items to GTK+ 2.20
>> Andy Stewart <lazycat.mana...@gmail.com>**20100524233947
>> Ignore-this: f33362d57605d16365e4dfac59c01122
>> ]
>> [Add an upper version to the requirement on base.
>> axel.si...@in.tum.de**20100524211158]
>> [Be more specific as to the prerequisites of packages.
>> axel.si...@in.tum.de**20100524210210]
>> [Fix docu.
>> axel.si...@in.tum.de**20100524210157]
>> [Make soegtk compile by fixing dependency on old-time and by not relying on 
>> Gtk 2.18.
>> axel.si...@in.tum.de**20100524210032]
>> [don't mention tools in the docs for unregistering.
>> axel.si...@in.tum.de**20100524201401]
>> [TAG 0.11.0
>> axel.si...@in.tum.de**20100524200857]
>> Patch bundle hash:
>> c1ef6d98be90249f1c95f9e9b3213e9ebcd20393
>> ------------------------------------------------------------------------------
>> This SF.net email is sponsored by Sprint
>> What will you do first with EVO, the first 4G phone?
>> Visit sprint.com/first --
> http://p.sf.net/sfu/sprint-com-first_______________________________________________
>> Gtk2hs-devel mailing list
>> Gtk2hs-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Gtk2hs-devel mailing list
Gtk2hs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel

Reply via email to