sketchucation logo sketchucation
    • 登入
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [Code] file_found?(path) and to_ascii+to_unicode.rb

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    42 貼文 5 Posters 5.9k 瀏覽 5 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • thomthomT 離線
      thomthom
      最後由 編輯

      http://blog.grayproductions.net/categories/character_encodings <- looks like some interesting reading.

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 條回覆 最後回覆 回覆 引用 0
      • thomthomT 離線
        thomthom
        最後由 編輯

        Not sure if .to_ansi is correct name any more since Ruby have no encoding. Maybe it's an co-incidence that it works on my system (Windows) which uses the Windows-1252 encoding. I expect that return str_utf8.unpack('U*').pack('C*') returns correct ASCII for the first 128 byte set, but it's the rest that has me puzzled. On my system it maps fine to ANSI, but maybe a different system might behave differently when it comes to the accented characters....

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 條回覆 最後回覆 回覆 引用 0
        • thomthomT 離線
          thomthom
          最後由 編輯

          Redmine 404 error

          favicon

          (redmine.ruby-lang.org)

          @unknownuser said:

          I noticed issues with other things, like puts, print and such.

          **Most of the File and IO functions for Windows are ANSI, not Wide, which limits the options to process properly paths, filenames and even output of strings using UTF/Unicode characters.

          Also, the console page affects ruby. By default is 437, but 1252 is needed to get accented strings to work.**

          Further review of the used Windows API is needed to find these issues.

          @unknownuser said:

          There are no plan to resolve the original problem on 1.8.
          You must pass the path with Win32 file API's encoding to ruby.

          I know it's VERY inconvenient for users in Europe, but we cannot break compatibility of commandline/path handling in 1.8 branch.

          This is in the lines of what I thought. The file / OI classes under windows appear to demand ANSI (1252) to operate. Question is; what happens on Mac systems? I need to poke around on my Mac when I get home.

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 條回覆 最後回覆 回覆 引用 0
          • thomthomT 離線
            thomthom
            最後由 編輯

            This is also interesting comment:

            @unknownuser said:

            ...
            This method applies to output routines only, and it is useless here.
            Actually problem is in the Windows-specific implementation of some Ruby
            libraries. Ruby reads the environment variable in awful wrong encoding, and
            works with file system objects in awful wrong encoding, too.
            ...

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 條回覆 最後回覆 回覆 引用 0
            • thomthomT 離線
              thomthom
              最後由 編輯

              Ok, I know I'm going back and forth here, but at the moment .to_ansi might be wrong. .to_ascii might not be complete indication of what's returned, but we know that we get the ASCII characters. .to_single_byte_characters or .to_unsigned_chars is more accurate, but a bit long names.

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 條回覆 最後回覆 回覆 引用 0
              • TIGT 線上
                TIG Moderator
                最後由 編輯

                Why don't we call the script "friendlytext.rb" and call them
                ruby_friendly(text)
                and
                sup_friendly(text)

                That way
                FileTest.exist?(ruby_friendly(model.path))
                returns true

                and you can turn Ruby made text back to suit SUp using the other form ? ...

                This also doesn't enter into this ansi/ascii/unicode/utf8 territory which looks like a quicksand... It also doesn't apportion blame !!!

                thomthom, you seem to be spending more time on this than me... why don't you take it over and decide what to call the methods ? I'd be happy to hand it over...

                TIG

                1 條回覆 最後回覆 回覆 引用 0
                • thomthomT 離線
                  thomthom
                  最後由 編輯

                  @tig said:

                  Why don't we call the script "friendlytext.rb" and call them
                  ruby_friendly(text)
                  and
                  sup_friendly(text)

                  That's a very pragmatic solution to it. I like it!

                  @tig said:

                  thomthom, you seem to be spending more time on this than me... why don't you take it over and decide what to call the methods ?

                  Since I use Norwegian characters that fall into this encoding trap it's rather important to me to know what's going on. I might look into some extra set of helper functions that I'll add to the SKX project. But I'd need some time to work out what's really going on.
                  For now these snippets will provide enough functionalities for most western languages.

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 條回覆 最後回覆 回覆 引用 0
                  • TIGT 線上
                    TIG Moderator
                    最後由 編輯

                    thomthom

                    She's all yours...

                    If you want me to remove any early stuff let me know [PM etc]...

                    TIG

                    1 條回覆 最後回覆 回覆 引用 0
                    • thomthomT 離線
                      thomthom
                      最後由 編輯

                      I think it can stick with the friendly names you suggested.
                      I'm doing more research. Just signed up for a Ruby forum to work out how Ruby behaves. Once I've gathered the info I need I'll make a thread describing the findings.

                      Thomas Thomassen — SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 條回覆 最後回覆 回覆 引用 0
                      • thomthomT 離線
                        thomthom
                        最後由 編輯

                        FYI, for anyone that (most unlikely) might be following on my ramblings - I've initiated a new thread over at a Ruby forum for further investigations: http://www.ruby-forum.com/topic/191016#833043

                        Thomas Thomassen — SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 條回覆 最後回覆 回覆 引用 0
                        • thomthomT 離線
                          thomthom
                          最後由 編輯

                          I'm fairly confident that it's ISO 8859-1 which .pack('C*') generates. As long as the characters fits into ISO 8859-1 the UTF-8 can be converted with the pack/unpack methods. If they fall outside, other solutions are needed.

                          One annoying finding with this is that the Euro symbol seem to be impossible to use. When ruby comes across this in a UTF-8 string it chokes and throws an error.

                          I'll begin writing up this to something more readable than today's ramblings.

                          Thomas Thomassen — SketchUp Monkey & Coding addict
                          List of my plugins and link to the CookieWare fund

                          1 條回覆 最後回覆 回覆 引用 0
                          • thomthomT 離線
                            thomthom
                            最後由 編輯

                            sigh
                            Euro can be used - just not typed into the Console. You might get it passed via SU's ruby method if it's used in a material name or component name. though .unpack('U') will return 8364 for it. Way outside the code point for ISO 8859-1. However, if you type in the octal value "\200" you get the Euro in a 1byte length string. So it should be mappable. But pack and unpack doesn't map the Unicode points between 128-160 well. So I'll be looking for a better conversion.

                            I've heard of Iconv, but that's an Win API call I think - not a solution for Mac.

                            Thomas Thomassen — SketchUp Monkey & Coding addict
                            List of my plugins and link to the CookieWare fund

                            1 條回覆 最後回覆 回覆 引用 0
                            • TIGT 線上
                              TIG Moderator
                              最後由 編輯

                              I am glad you have taken such a complicated thing over .... 😄

                              TIG

                              1 條回覆 最後回覆 回覆 引用 0
                              • thomthomT 離線
                                thomthom
                                最後由 編輯

                                @tig said:

                                I am glad you have taken such a complicated thing over .... 😄

                                I'm not... 🤢 This makes my head hurt.
                                But I need to know.

                                But at least it beats sudoko puzzles... 😉

                                Thomas Thomassen — SketchUp Monkey & Coding addict
                                List of my plugins and link to the CookieWare fund

                                1 條回覆 最後回覆 回覆 引用 0
                                • TIGT 線上
                                  TIG Moderator
                                  最後由 編輯

                                  @thomthom said:

                                  But at least it beats sudoko puzzles... 😉

                                  I can do those !!! 😉

                                  TIG

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • thomthomT 離線
                                    thomthom
                                    最後由 編輯

                                    😄

                                    Thomas Thomassen — SketchUp Monkey & Coding addict
                                    List of my plugins and link to the CookieWare fund

                                    1 條回覆 最後回覆 回覆 引用 0
                                    • daikuD 離線
                                      daiku
                                      最後由 編輯

                                      @tig said:

                                      @thomthom said:

                                      But at least it beats sudoko puzzles... 😉

                                      I can do those !!! 😉

                                      But can you generate a puzzle using ruby code? Sounds like an idea for a ruby challenge.

                                      Clark Bremer
                                      http://www.northernlightstimberframing.com

                                      1 條回覆 最後回覆 回覆 引用 0
                                      • T 離線
                                        tomasz
                                        最後由 編輯

                                        I am looking into this issue right now. I haven't found anything more then TIG and Thomas has figured out. I have even started to code a C extension to return proper string converted from Ruby UTF-8, but my poor C knowledge doesn't let me progress fast.
                                        As far as I understand Win uses UTF-16 format, but the whole encoding thing hurts my head badly.
                                        Have someone made any progress on this issue?

                                        Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                                        1 條回覆 最後回覆 回覆 引用 0
                                        • thomthomT 離線
                                          thomthom
                                          最後由 編輯

                                          What are you trying to do? String conversion? Or deal with files with unicode characters?

                                          Thomas Thomassen — SketchUp Monkey & Coding addict
                                          List of my plugins and link to the CookieWare fund

                                          1 條回覆 最後回覆 回覆 引用 0
                                          • T 離線
                                            tomasz
                                            最後由 編輯

                                            @thomthom said:

                                            What are you trying to do? String conversion? Or deal with files with unicode characters?

                                            I am trying to create a file with a path/filename containing for example Polish characters 'Błąd.xml'. They are not part of ISO 8859-1 so the .pack('C*') doesn't generate proper path and file will be created under different name 'Błąd.xml'

                                            Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                                            1 條回覆 最後回覆 回覆 引用 0
                                            • 1
                                            • 2
                                            • 3
                                            • 2 / 3
                                            • 第一個貼文
                                              最後的貼文
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement