Skip to content

Conversation

cch123
Copy link
Contributor

@cch123 cch123 commented Jul 4, 2017

fix negative number to uint

@codecov
Copy link

codecov bot commented Jul 4, 2017

Codecov Report

Merging #106 into master will increase coverage by 1.1%.
The diff coverage is 100%.

Impacted file tree graph

@@ Coverage Diff @@ ## master #106 +/- ## ========================================= + Coverage 62.17% 63.28% +1.1%  ========================================= Files 60 60 Lines 5385 5387 +2 ========================================= + Hits 3348 3409 +61  + Misses 1812 1759 -53  + Partials 225 219 -6
Impacted Files Coverage Δ
feature_any_number.go 90.62% <ø> (+18.75%) ⬆️
feature_any_string.go 88% <100%> (+11.28%) ⬆️
feature_reflect_object.go 46.26% <0%> (ø) ⬆️
feature_any_object.go 45.72% <0%> (+2.23%) ⬆️
feature_any_array.go 69.18% <0%> (+4.86%) ⬆️
feature_any_bool.go 56.25% <0%> (+18.75%) ⬆️
feature_any_nil.go 62.5% <0%> (+37.5%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca8dd93...3f35bed. Read the comment docs.

Copy link
Contributor

@taowen taowen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该把改动控制在 any 里就可以了。应该读一下any 的 buf 的第一个byte就可以处理。不要去改 iterator。


func (iter *Iterator) ReadUint() uint {
if iter.buf[iter.head] == '-' && len(iter.buf) > 1 {
iter.buf = iter.buf[1:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样写是有问题的。buf 的当前位置不是0,是 iter.n。你得了解整个iterator维护当前进度的方式再来改这块。

}

func (iter *Iterator) ReadUint64() uint64 {
if iter.buf[iter.head] == '-' && len(iter.buf) > 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要加这样的判断?如果是负数,读取的时候应该报错啊。

Copy link
Contributor Author

@cch123 cch123 Jul 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

php里没有uint,不过直接把负值全扔掉也不好吧orz
不太确定,我再想想

@cch123
Copy link
Contributor Author

cch123 commented Jul 4, 2017

又想了想,go自己也是不支持负值向uint转换的,还是保留原来转成0的逻辑吧orz

pointOccurCnt := 0
pointPos := -1

for i := startPos; i < len(any.val); i++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥有这么复杂……

Copy link
Contributor Author

@cch123 cch123 Jul 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

想兼容一些恶心的string,比如123.12asd这种,因为php里强转能转出一个值来orz,要是不兼容就简单了。。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

简单点吧,这个太复杂了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还用标准库的ParseFloat么

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对啊。any 是 skip 出来的。你那样的数字都skip不出来。

Copy link
Contributor Author

@cch123 cch123 Jul 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int的先不改。。看起来还像还不算太复杂

@taowen taowen merged commit 3829a47 into json-iterator:master Jul 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants