Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Converting a wstring to UTF8?

Converting a wstring to UTF8?

Scheduled Pinned Locked Moved ATL / WTL / STL
questionc++com
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    OK, following on from the char -> wchar_t question earlier, does anyone know of a neat STL-friendly way to perform UTF8 encoding/decoding? Currently I use the MS character encoding macros, e.g.:

    // Convert UTF8 string to Unicode
    wstring str = CA2W(utf8_string, CP_UTF8).m_psz;

    But I'd like to use something that is a bit more platform independent! :)


    The Rob Blog
    Google Talk: robert.caldecott

    M A 2 Replies Last reply
    0
    • L Lost User

      OK, following on from the char -> wchar_t question earlier, does anyone know of a neat STL-friendly way to perform UTF8 encoding/decoding? Currently I use the MS character encoding macros, e.g.:

      // Convert UTF8 string to Unicode
      wstring str = CA2W(utf8_string, CP_UTF8).m_psz;

      But I'd like to use something that is a bit more platform independent! :)


      The Rob Blog
      Google Talk: robert.caldecott

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      AFAIK STL doesn't have UTF-8 support because the elements in a basic_string have to all be the same size, and the UTF-8 encodings of characters have variying sizes.

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      N 1 Reply Last reply
      0
      • M Michael Dunn

        AFAIK STL doesn't have UTF-8 support because the elements in a basic_string have to all be the same size, and the UTF-8 encodings of characters have variying sizes.

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        N Offline
        N Offline
        Nemanja Trifunovic
        wrote on last edited by
        #3

        Never mind. You can store a utf-8 string as a sequence of bytes in std::string, just need to know which functions operate correctly on such a sequence and which not. As for the conversion, I have been writing an article on platform-independent STL friendly utf-8 string operations for months, but I just can't make myself finish it :^)


        My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.

        L 1 Reply Last reply
        0
        • L Lost User

          OK, following on from the char -> wchar_t question earlier, does anyone know of a neat STL-friendly way to perform UTF8 encoding/decoding? Currently I use the MS character encoding macros, e.g.:

          // Convert UTF8 string to Unicode
          wstring str = CA2W(utf8_string, CP_UTF8).m_psz;

          But I'd like to use something that is a bit more platform independent! :)


          The Rob Blog
          Google Talk: robert.caldecott

          A Offline
          A Offline
          alabax
          wrote on last edited by
          #4

          In the Microsoft stl libraries, localization uses C interface. The locale class calls setlocale function. And it cannot work with UTF-8. From the Remarks section on the setlocale function reference: "The set of available languages, country/region codes, and code pages includes all those supported by the Win32 NLS API (except code pages that require more than two bytes per character, like UTF-8)."

          1 Reply Last reply
          0
          • N Nemanja Trifunovic

            Never mind. You can store a utf-8 string as a sequence of bytes in std::string, just need to know which functions operate correctly on such a sequence and which not. As for the conversion, I have been writing an article on platform-independent STL friendly utf-8 string operations for months, but I just can't make myself finish it :^)


            My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Nemanja Trifunovic wrote:

            As for the conversion, I have been writing an article on platform-independent STL friendly utf-8 string operations for months, but I just can't make myself finish it

            Man, that would be sweet... :) :)


            The Rob Blog
            Google Talk: robert.caldecott

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups