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. Product Lifecycle
  3. Free Tools
  4. Don't you love little websites that do exactly what you need? (UTF-8 to/from cstr)

Don't you love little websites that do exactly what you need? (UTF-8 to/from cstr)

Scheduled Pinned Locked Moved Free Tools
comgraphicsiotquestion
4 Posts 2 Posters 19 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.
  • H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #1

    UTF-8 encoder/decoder[^]

    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx

    C 1 Reply Last reply
    0
    • H honey the codewitch

      UTF-8 encoder/decoder[^]

      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx

      C Offline
      C Offline
      charles henington
      wrote on last edited by
      #2

      I use c# but asked chatgpt to convert my code to c++. To get the encoded you could use something like this.

      #include #include #include std::string Encrypt(const std::string& input) {
      std::string result;
      std::ostringstream oss;

      for (char c : input) {
          oss << "\\\\#" << std::setw(2) << std::setfill('0') << std::hex << std::uppercase << (int)c;
      }
      
      result = oss.str();
      return result;
      

      }

      To Decrypt back you can use

      #include #include std::string Decrypt(const std::string& input) {
      std::string result;

      for (size\_t i = 0; i < input.length(); i += 4) {
          // Extract the two hexadecimal characters (skip the \\#)
          std::string temp = input.substr(i + 2, 2);
          
          // Convert the hex string to an integer
          int num = std::stoi(temp, nullptr, 16);
          
          // Convert the integer to a character and append to the result
          result += static\_cast(num);
      }
      
      return result;
      

      }

      Let me know if this helps.

      H 2 Replies Last reply
      0
      • C charles henington

        I use c# but asked chatgpt to convert my code to c++. To get the encoded you could use something like this.

        #include #include #include std::string Encrypt(const std::string& input) {
        std::string result;
        std::ostringstream oss;

        for (char c : input) {
            oss << "\\\\#" << std::setw(2) << std::setfill('0') << std::hex << std::uppercase << (int)c;
        }
        
        result = oss.str();
        return result;
        

        }

        To Decrypt back you can use

        #include #include std::string Decrypt(const std::string& input) {
        std::string result;

        for (size\_t i = 0; i < input.length(); i += 4) {
            // Extract the two hexadecimal characters (skip the \\#)
            std::string temp = input.substr(i + 2, 2);
            
            // Convert the hex string to an integer
            int num = std::stoi(temp, nullptr, 16);
            
            // Convert the integer to a character and append to the result
            result += static\_cast(num);
        }
        
        return result;
        

        }

        Let me know if this helps.

        H Offline
        H Offline
        honey the codewitch
        wrote on last edited by
        #3

        It doesn't, because I know how to do that. It's more effort to build that, or even to just launch a terminal window in order to run that vs navigate to that website and type in a string. Was actually using it to test UTF-8 -> UTF-32 conversion in my graphics lib - that does NOT use the C++ runtimes or The STL because embedded.

        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

        1 Reply Last reply
        0
        • C charles henington

          I use c# but asked chatgpt to convert my code to c++. To get the encoded you could use something like this.

          #include #include #include std::string Encrypt(const std::string& input) {
          std::string result;
          std::ostringstream oss;

          for (char c : input) {
              oss << "\\\\#" << std::setw(2) << std::setfill('0') << std::hex << std::uppercase << (int)c;
          }
          
          result = oss.str();
          return result;
          

          }

          To Decrypt back you can use

          #include #include std::string Decrypt(const std::string& input) {
          std::string result;

          for (size\_t i = 0; i < input.length(); i += 4) {
              // Extract the two hexadecimal characters (skip the \\#)
              std::string temp = input.substr(i + 2, 2);
              
              // Convert the hex string to an integer
              int num = std::stoi(temp, nullptr, 16);
              
              // Convert the integer to a character and append to the result
              result += static\_cast(num);
          }
          
          return result;
          

          }

          Let me know if this helps.

          H Offline
          H Offline
          honey the codewitch
          wrote on last edited by
          #4

          Also looking at that code, it doesn't do what the website does at all. It has no conception of UTF encoding. Pro-tip: (This one's free) - Don't ask GPT for help with code.

          Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

          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