profile
viewpoint
Milo Yip miloyip Tencent Hong Kong, China

miloyip/game-programmer 11479

A Study Path for Game Programmer

Tencent/rapidjson 9749

A fast JSON parser/generator for C++ with both SAX/DOM style API

miloyip/json-tutorial 3698

从零开始的 JSON 库教程

miloyip/nativejson-benchmark 1349

C/C++ JSON parser/generator benchmark

miloyip/light2d 604

Light rendering in 2D

miloyip/svpng 468

Minimalistic C function for saving RGB/RGBA image as uncompressed PNG.

miloyip/itoa-benchmark 271

C++ integer-to-string conversion benchmark

miloyip/dtoa-benchmark 192

C++ double-to-string conversion benchmark

miloyip/line 136

2D Line Drawing Samples in C

miloyip/graphvizuml 121

使用 Graphviz 绘画 UML 图

pull request commentDanielmelody/Ruschm

feat: pairs and lists

Looks OK for me. But sometimes I think a little bit comments can help reading.

Danielmelody

comment created time in 3 days

pull request commentDanielmelody/Ruschm

feat: list and pair

Can't see related tests?

Danielmelody

comment created time in 8 days

issue commentTencent/rapidjson

Does rapidjson support data type: int128, uint128, float128 ?

These non-standardized types are not supported at the mean time.

gzliudan

comment created time in 10 days

PR opened Yatekii/imgui-wgpu-rs

fix: initial scale factor

Obtain initial scale factor correctly. This affect the initialization of font bitmap.

On MacOS, Before:

image

After:

image

+6 -3

0 comment

3 changed files

pr created time in 13 days

create barnchmiloyip/imgui-wgpu-rs

branch : initial_scale_factor

created branch time in 13 days

Pull request review commentDanielmelody/Ruschm

fix(lexer): prevent rational number denominator being zero

 fn atmosphere() -> Result<()> { #[test] fn comment() -> Result<()> {     assert_eq!(-        tokenize("abcd;+-12\t\n\r 12")?,+        tokenize("abcd;+-12\n 12;dew\r34")?,

removed \t ?

Danielmelody

comment created time in 13 days

PullRequestReviewEvent

Pull request review commentDanielmelody/Ruschm

feat: :sparkles: floor buildin function

 pub fn base_library<'a, R: RealNumberInternalTrait, E: IEnvironment<R>>(         }     } +    fn floor<R: RealNumberInternalTrait, E: IEnvironment<R>>(+        arguments: impl IntoIterator<Item = Value<R, E>>,+    ) -> Result<Value<R, E>> {+        match arguments.into_iter().next() {+            Some(Value::Number(number)) => Ok(Value::Number(match number {+                Number::Integer(num) => Number::Integer(num),+                Number::Real(num) => Number::Integer(num.floor().to_i32().unwrap()),+                Number::Rational(a, _) => {+                    if a >= 0 {+                        Number::Integer(a)+                    } else {+                        Number::Integer(a - 1)+                    }+                }

Is this correct? floor(a/b) = a ? BTW, I think these functions need unit tests.

CurryPseudo

comment created time in 14 days

PullRequestReviewEvent

Pull request review commentDanielmelody/Ruschm

feat: :sparkles: floor buildin function

 pub fn base_library<'a, R: RealNumberInternalTrait, E: IEnvironment<R>>(         }     } +    fn floor<R: RealNumberInternalTrait, E: IEnvironment<R>>(+        arguments: impl IntoIterator<Item = Value<R, E>>,+    ) -> Result<Value<R, E>> {+        match arguments.into_iter().next() {+            Some(Value::Number(number)) => Ok(Value::Number(match number {+                Number::Integer(num) => Number::Integer(num),+                Number::Real(num) => Number::Integer(num.floor().to_i32().unwrap()),

I think floor of Real should be Real, like floorf() in C. Otherwise it may be overflow.

CurryPseudo

comment created time in 14 days

PullRequestReviewEvent

pull request commentYatekii/imgui-wgpu-rs

feat: cube example with additional API in Renderer

Should also fix #24

miloyip

comment created time in 14 days

PR opened Yatekii/imgui-wgpu-rs

feat: cube example with additional API in Renderer

I was attempting to render a 3D scene with wgpu within a imgui Window.

I ported the cube example code from https://github.com/gfx-rs/wgpu-rs/tree/master/examples/cube for testing, and may also be useful for others.

In this example, I need API for creating a texture (not uploading one) with specific usage. And I also need to obtain the texture view from a TextureId.

Optionally, the texture can be resized according to the window size. So I need to add additional API for Renderer to replace the new texture.

I only tested it on my Mac. I am not sure if other platforms are good.

image

+699 -1

0 comment

7 changed files

pr created time in 14 days

create barnchmiloyip/imgui-wgpu-rs

branch : cube_example

created branch time in 14 days

fork miloyip/imgui-wgpu-rs

Dear imgui renderer for wgpu-rs.

fork in 14 days

pull request commentTencent/rapidjson

Fix build warnings emitted by GCC 10 on Aarch64

Ch can be std::uint16_t or other types.

philn

comment created time in 17 days

pull request commentTencent/rapidjson

Fix build warnings emitted by GCC 10 on Aarch64

This code is needed for sizeof(Ch) > 1. Otherwise the array lookup will be out of bound. May need to add some pragma to disable warning.

philn

comment created time in 17 days

PullRequestReviewEvent
PullRequestReviewEvent

issue commentTencent/rapidjson

Add set(distinct elements) in rapidjson

I think you may use std::unique() on your data structures, with std::sort() it is O(n log n). RapidJSON actually just use a vector-like data strcture internally, which cannot handle this purpose efficient (O(n^2)).

akankshamahajan15

comment created time in 23 days

issue commentTencent/rapidjson

can i convert a json string to escaped string using rapidjson?

Yes, use Document::Parse() can do the opposite. A notable difference is that parsing can be failed if the input is invalid, where "strinigify" normally will not fail.

ashjas

comment created time in a month

issue commentTencent/rapidjson

can i convert a json string to escaped string using rapidjson?

I forgot to pass the sb...

#include <string>
#include <iostream>
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"

using namespace rapidjson;

int main() {
    std::string ss = R"({"delta":"bac"})";
    StringBuffer sb;
    Writer<StringBuffer> writer(sb);
    writer.String(ss.c_str(),ss.size());
    std::string escaped = sb.GetString();
    std::cout << escaped << std::endl;
}
$ g++ -I ~/github/rapidjson/include -std=c++11 a.cpp && ./a.out
"{\"delta\":\"bac\"}"
ashjas

comment created time in a month

issue commentTencent/rapidjson

can i convert a json string to escaped string using rapidjson?

I think it should be simply:

StringBuffer sb;
Writer<StringBuffer> writer;
writer.String(string_to_be_escaped);
const char* escaped = sb.GetString();
ashjas

comment created time in a month

issue commentTencent/rapidjson

When parse a json string, kParseErrorStringEscapeInvalid error will appear, when the value string contains a tab character

This is a complete and runnable example:

#include "rapidjson/document.h"
#include <iostream>
#include <string>

int main() {
    std::string json = R"({"msg":"\thello abc","mtime":1596531824})";
    rapidjson::Document document;
    auto errorCode = document.Parse(json.c_str()).GetParseError();
   if (errorCode != rapidjson::kParseErrorNone)
        std::cout << "json parse failed. errorCode = "<< errorCode <<" ,data = "<< json.c_str() << std::endl;
    else
        std::cout << "json parse succeeded." << std::endl;
}

On my machine:

$ g++ -I ~/github/rapidjson/include -std=c++11 a.cpp && ./a.out
json parse succeeded.
zjs604381586

comment created time in a month

issue commentTencent/rapidjson

json解析报Invalid encoding in string

上面的不是合法的代码,要么传一个 .json 文件吧。

zqq2016

comment created time in a month

issue commentTencent/rapidjson

JSON字符串包含生僻中文字符无法解析

汉字

RapidJSON 只支持 UTF-8, UTF-16, UTF-32 和 ASCII 的 JSON,暂不支持其他编码。 JSON 标准也是以 Unicode 为基础。

muzipeng718

comment created time in a month

push eventTencent/rapidjson

miloyip

commit sha 69db8700b234461976f6e96607f829249d52de95

Automatic doxygen build

view details

push time in 2 months

issue commentTencent/rapidjson

Are AppVeyor 'Rolling builds' enabled?

image

I just tried to enable this for PR. Hope this will help.

escherstair

comment created time in 2 months

push eventTencent/rapidjson

escherstair

commit sha 6364c8e5ab1b9b5df01df25ff102d1c48aa0d389

fix _BitScanReverse() usage for CE6

view details

escherstair

commit sha 91940e84b139db8d098e7182ae836595c677b115

fallback to the naive version for CE6

view details

escherstair

commit sha aa5dd6086519717342cafd846f70737cba315aa7

fix naive version implementation

view details

escherstair

commit sha 58e29648561e47f6fc11ee2c2bbf8628ffc46f57

add unit test for clzll()

view details

escherstair

commit sha 7f559ec80ab4d129e3c3a3eb109fe5049e751e98

fix naive implementation for clzll()

view details

escherstair

commit sha 5fbf8bf89cec8154c4b0be0c5c529694e8477bf2

fix unit test

view details

Milo Yip

commit sha ce81bc9edfe773667a7a4454ba81dac72ed4364c

Merge pull request #1760 from escherstair/fix_ce6_support fix _BitScanReverse() usage for CE6

view details

push time in 2 months

pull request commentTencent/rapidjson

add gzfilereadstream (zlib reader)

I think including this in the main library will add extra dependency to this project. I suggest moving this to /contrib/gzip/. What do you think?

vindex10

comment created time in 2 months

pull request commentTencent/rapidjson

fix _BitScanReverse() usage for CE6

Would you mind adding an unit test (including the boundary cases) for this function?

escherstair

comment created time in 2 months

pull request commentTencent/rapidjson

fix _BitScanReverse() usage for CE6

I think you should just fallback to the navie version at the bottom of the function.

escherstair

comment created time in 2 months

issue commentTencent/rapidjson

Changing SizeType to size_t across project

You may change the compilation options in a project to define macro globally.

bpeikes

comment created time in 2 months

issue commentTencent/rapidjson

Should a document be reused in repeated parsing?

Using Document as local variable is the easiest way to go, if it is sufficient for your use case. Just parse, retrieve information and convert the information to your internal representation.

tesla1060

comment created time in 2 months

issue commentTencent/rapidjson

Float formatting when writting output

It seems to be a bug. Do you want to try to fix it and submit a PR?

NadegeEv

comment created time in 2 months

issue commentTencent/rapidjson

'intrin.h' not available with MSC compiler and CE6 target

You may try to fix it and if it is possible you can make a PR.

escherstair

comment created time in 2 months

issue commentTencent/rapidjson

Should accept new line sequence in PrettyWriter

I think you may just need to create a output stream (adapter) class that does this conversion.

kapilratnani

comment created time in 2 months

issue commentTencent/rapidjson

JSON字符串包含生僻中文字符无法解析

这是可以的

muzipeng718

comment created time in 2 months

issue commentTencent/rapidjson

json compare fails for some cases

Oh, yes... I misread your original example.

jm4R

comment created time in 2 months

issue closedTencent/rapidjson

Crash when parsing a JSON combining emoji and Cyrillic characters

Hello RapidJSON team / Milo,

I am getting a crash when invoking rapidjson::Document::Parse. The error code is kParseErrorStringUnicodeSurrogateInvalid.

The crash is coming from the if block between lines 1023 and 1032 in reader.h. If I comment the block out, the crash does not happen.

I don't see the version anywhere in the source code, but my files are dated by May 2018. Thanks in advance, and thanks for your work.

rapidjsoncrash.txt

closed time in 2 months

vadim-berman

issue commentTencent/rapidjson

json compare fails for some cases

https://github.com/Tencent/rapidjson/blob/f56928de85d56add3ca6ae7cf7f119a42ee1585b/include/rapidjson/document.h#L1010

jm4R

comment created time in 2 months

issue commentTencent/rapidjson

Crash when parsing a JSON combining emoji and Cyrillic characters

We added kParseErrorStringUnicodeSurrogateInvalid in #1744 And I found that "\ud83dе\udeac" in your JSON is invalid, causing the parse complain about this. But it should not "crash".

vadim-berman

comment created time in 2 months

issue commentTencent/rapidjson

JSON document comparison always returns true if it contains only a string value

These are not a valid JSON and parse() returns error. A valid JSON of a single string is, e.g., d1.Parse("\"hello\"");

mmustaquim

comment created time in 2 months

issue commentTencent/rapidjson

Accept 报错,编译通不过,当使用UTF16的时候

#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include <string>

using namespace std;
using namespace rapidjson;

int main() {
   GenericValue<rapidjson::UTF16<> > v; 
    v.SetString(L"你好");
    GenericStringBuffer<UTF16<> > wbuffer;
    Writer<GenericStringBuffer<UTF16<> >, UTF16<>, UTF16<> > writer(wbuffer);
    v.Accept(writer);
    wstring s = wbuffer.GetString();
}
826655197

comment created time in 2 months

issue commentTencent/rapidjson

JSON字符串包含生僻中文字符无法解析

https://docs.microsoft.com/zh-cn/cpp/preprocessor/execution-character-set?view=vs-2019

muzipeng718

comment created time in 2 months

issue commentTencent/rapidjson

JSON字符串包含生僻中文字符无法解析

那应该是 VC 的问题吧。打印出来的字面量都是 GB 码的,那和 RapidJSON 没有关系。

试一下用 C++11 的 u8 prefix 能不解决你的问题? https://en.cppreference.com/w/cpp/language/string_literal

muzipeng718

comment created time in 2 months

issue commentTencent/rapidjson

JSON字符串包含生僻中文字符无法解析

因为 5C 是 \,假设它是 UTF-8 的话,写出来需要转义成 \\

muzipeng718

comment created time in 2 months

issue commentTencent/rapidjson

JSON字符串包含生僻中文字符无法解析

D95C 是 GB 码⋯⋯不是 UTF-8

muzipeng718

comment created time in 2 months

issue commentTencent/rapidjson

JSON字符串包含生僻中文字符无法解析

试试 json_content = "賊";

muzipeng718

comment created time in 2 months

issue commentTencent/rapidjson

JSON字符串包含生僻中文字符无法解析

@caomfan 试改一下输出,看看结果?

    for (size_t i = 0; i < json_content.size(); i++)
        std::cout << std::hex << (unsigned)(unsigned char)json_content[i] << " " << json_content[i] << std::endl;
7b {
22 "
63 c
6f o
6e n
74 t
65 e
6e n
74 t
22 "
3a :
22 "
e8 ?
b3 ?
8a ?
22 "
7d }

賊的 UTF-8 确实是 0xE8 0xB3 0x8A

muzipeng718

comment created time in 2 months

issue commentTencent/rapidjson

JSON字符串包含生僻中文字符无法解析

@caomfan 我在这机器上不能重现

 g++ -I ~/github/rapidjson/include a.cpp && ./a.out                
{"content":"賊"}
muzipeng718

comment created time in 2 months

issue commentTencent/rapidjson

JSON字符串包含生僻中文字符无法解析

你的 C++ 源文件是不是 UTF-8?

muzipeng718

comment created time in 2 months

issue commentTencent/rapidjson

JSON字符串包含生僻中文字符无法解析

不能重现:

in.json

{"賊":1}

a.cpp:

#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/filereadstream.h"
#include "rapidjson/filewritestream.h"

using namespace rapidjson;

int main() {
    Document d;

    {
        FILE* fp = fopen("in.json", "r");
        char buffer[256];
        FileReadStream frs(fp, buffer, sizeof(buffer));
        d.ParseStream(frs);
        fclose(fp);
    }

    {
        FILE* fp = fopen("out.json", "w");
        char buffer[256];
        FileWriteStream fws(fp, buffer, sizeof(buffer));
        Writer<FileWriteStream> writer(fws);
        d.Accept(writer);
        fclose(fp);
    }
}
$g++ -I ~/github/rapidjson/include a.cpp && ./a.out && cat out.json
{"賊":1}

Archive.zip

muzipeng718

comment created time in 2 months

push eventTencent/rapidjson

miloyip

commit sha aa6b3452f4dbe26c9774c0be5cc724a5464f0711

Automatic doxygen build

view details

push time in 2 months

issue commentTencent/rapidjson

Should accept new line sequence in PrettyWriter

On Windows, this should have been handled by the standard library, e.g. fopen(filename, "wt"), as in https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen?view=vs-2019

In text mode, carriage return-line feed combinations are translated into single line feeds on input, and line feed characters are translated to carriage return-line feed combinations on output.

kapilratnani

comment created time in 2 months

issue commentTencent/rapidjson

Document 放到另一个Document下面,为什么会core_dump?

b1 的内存还是来自于 b1 的分配器。 需要先用 a 的分配器来复制 b1。

 a.AddMember("test1", Value(b1, a.GetAllocator()).Move(), a.GetAllocator());
ywsswy

comment created time in 2 months

issue closedTencent/rapidjson

Difference in parse and write validation

Hello,

I encountered some differences between the kParseValidateEncodingFlag and the kWriteValidateEncodingFlag with regrads to surrogates.

In the following example:

int main () {
   const auto input = R"EOS(["\udc4d"])EOS";
   rapidjson::Document doc;
   rapidjson::ParseResult parseResult = doc.Parse<rapidjson::kParseValidateEncodingFlag>(input);
   if(parseResult.IsError()) {
     throw std::runtime_error("Parse Error");
   }   
   OStreamWrapper wrapper{std::cout};
   auto writer = Writer<rapidjson::OStreamWrapper, rapidjson::UTF8<>, rapidjson::UTF8<>, rapidjson::CrtAllocator, rapidjson::kWriteValidateEncodingFlag>(wrapper);
   if(!doc.Accept(writer)) {
     throw std::runtime_error("Write Error");
   }   
}

the input (an array with a single low surrogate) is parsed without an error, but later when writing the document to the stream an error is thrown. is this a known issue or am I missing something in the example ? If this is an issue and should be fixed I could provide a pull request that modifies the handling of surrogates in reader.h

Thanks for your work and kind regards

closed time in 2 months

lklein53

pull request commentTencent/rapidjson

Improve surrogate handling (#1738)

Thank you

lklein53

comment created time in 2 months

push eventTencent/rapidjson

Lars Klein

commit sha ed73d7bdb4cae1bac509ec85b4fbc4de4ac4b558

Improve surrogate handling Report a single low surrogate as kParseErrorStringUnicodeSurrogateInvalid.

view details

Lars Klein

commit sha 6694c996b9e5a5e44d9f7cea1d619cae86384981

Add test case for low surrogate handling

view details

Milo Yip

commit sha f56928de85d56add3ca6ae7cf7f119a42ee1585b

Merge pull request #1744 from lklein53/improve-surrogate-handling Improve surrogate handling (#1738)

view details

push time in 2 months

PR merged Tencent/rapidjson

Improve surrogate handling (#1738)

Report a single low surrogate as kParseErrorStringUnicodeSurrogateInvalid.

+19 -8

1 comment

2 changed files

lklein53

pr closed time in 2 months

issue commentTencent/rapidjson

move document into value

How about using swapping?

    Document d;
    Value v;
    d.Swap(v);

But need to remind that the values in document is allocated by the document's allocator. Need to preserve the lifetime of document.

Krisonrik

comment created time in 3 months

issue commentTencent/rapidjson

wrong output with int64_t writing

9223372036854776000 is larger than 2^63 -1 so it is not representable as int64_t. But it should not cause a crash.

#include "rapidjson/writer.h"
#include <iostream>

using namespace rapidjson;

int main() {
    StringBuffer sb;
    Writer<StringBuffer> writer(sb);
    writer.Int64(9223372036854776000LL);
    std::cout << sb.GetString();
}
g++ -std=c++11 -I ~/github/rapidjson/include -g a.cpp && ./a.out
a.cpp:9:18: warning: integer literal is too large to be represented in a signed integer type, interpreting as unsigned
      [-Wimplicitly-unsigned-literal]
    writer.Int64(9223372036854776000LL);
                 ^
1 warning generated.
-9223372036854775616
jcelerier

comment created time in 3 months

issue commentTencent/rapidjson

Difference in parse and write validation

I think kParseValidateEncodingFlag is not related in this problem, and can be omitted to reproduce this situation. I checked the currently Reader handled unpaired surrogate with single high surrogate, but not single low surrogate:

https://github.com/Tencent/rapidjson/blob/88bd956d66d348f478bceebfdadb8e26c6844695/include/rapidjson/reader.h#L1026-L1035

I think it should generate kParseErrorStringUnicodeSurrogateInvalid as well for leading low surrogate. I have not research much on this. May need to dig more on the standards and try on other implementations. Open for discussion.

lklein53

comment created time in 3 months

issue commentTencent/rapidjson

different behavior by json_parser.Parse<0>(str) for doubles

Will it be possible the "bigger project" also include another version of rapidjson, so that the linker behave incorrectly? If so, you may try customizing the namespace of your part by defining RAPIDJSON_NAMESPACE to an unique identifier.

Jaberh

comment created time in 3 months

more