Giter VIP home page Giter VIP logo

Comments (3)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
I modified write::WriteString to support it.
=================================================================
  void WriteString(const Ch* str, SizeType length)  {
    static const char hexDigits[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
    static const char escape[256] = {
#define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
#define B16 'b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b'
      //0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F
      'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'b', 't', 'n', 'u', 'f', 'r', 'u', 'u', // 00
      'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', // 10
        0,   0, '"',   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, // 20
      Z16, Z16,                                    // 30~4F
        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,'\\',   0,   0,   0, // 50
      Z16, Z16, // 60~7F
      B16, B16, B16, B16, B16, B16, B16, B16                // 80~FF
#undef Z16
#undef B16
    };

    os_.Put('\"');
    GenericStringStream<SourceEncoding> is(str);
    while (is.Tell() < length) {
      const Ch c = is.Peek();
      if ((sizeof(Ch) == 1 || (unsigned)c < 256) && escape[(unsigned char)c])  {
        os_.Put('\\');
        if (escape[(unsigned char)c] == 'u') {
          is.Take();
          os_.Put(escape[(unsigned char)c]);
          os_.Put('0');
          os_.Put('0');
          os_.Put(hexDigits[(unsigned char)c >> 4]);
          os_.Put(hexDigits[(unsigned char)c & 0xF]);
        }
        else if (escape[(unsigned char)c] == 'b') {
          unsigned codepoint;
          if (!SourceEncoding::Decode(is, &codepoint)) {
            // Error
          }
          else
          {
            os_.Put('u');
            os_.Put(hexDigits[(codepoint & 0xf000) >> 12]);
            os_.Put(hexDigits[(codepoint & 0x0f00) >> 8]);
            os_.Put(hexDigits[(codepoint & 0x00f0) >> 4]);
            os_.Put(hexDigits[(codepoint & 0x000f) >> 0]);
          }
        }
        else {
          is.Take();
          os_.Put(escape[(unsigned char)c]);
        }
      }
      else
        Transcoder<SourceEncoding, TargetEncoding>::Transcode(is, os_);
    }
    os_.Put('\"');
  }
...
================================================

I think we should append a boolean return for WriteString() function to 
indicate the process is seccess or not. 


Original comment by [email protected] on 12 Oct 2012 at 1:51

from rapidjson.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
I think, both Chinese characters or "\uXXXX" are correct format in UTF-8 JSON.

I propose two solutions.
1. Add an option to choose "\uXXXX" format.
2. Add an encoding which cannot encode unicode charaters, such as ASCII.

Welcome for discussion.

Original comment by [email protected] on 14 Nov 2012 at 3:05

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

from rapidjson.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
https://github.com/miloyip/rapidjson/pull/70

Original comment by [email protected] on 13 Jul 2014 at 5:14

  • Changed state: Started

from rapidjson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.