Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
* maint:
  [json] Fix missed integer callback for zero
  Clarify docs for string:jaro_similarity/2
  • Loading branch information
dgud committed Jun 19, 2024
2 parents 7453be0 + a404b35 commit ab1f7d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
6 changes: 4 additions & 2 deletions lib/stdlib/src/json.erl
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,11 @@ number_zero(<<$., Rest/bits>>, Original, Skip, Acc, Stack, Decode, Len) ->
number_zero(<<E, Rest/bits>>, Original, Skip, Acc, Stack, Decode, Len) when E =:= $E; E =:= $e ->
number_exp_copy(Rest, Original, Skip, Acc, Stack, Decode, Len + 1, <<"0">>);
number_zero(<<>>, Original, Skip, Acc, Stack, Decode, Len) ->
unexpected(Original, Skip, Acc, Stack, Decode, Len, 0, {number, 0});
Value = (Decode#decode.integer)(<<"0">>),
unexpected(Original, Skip, Acc, Stack, Decode, Len, 0, {number, Value});
number_zero(Rest, Original, Skip, Acc, Stack, Decode, Len) ->
continue(Rest, Original, Skip+Len, Acc, Stack, Decode, 0).
Value = (Decode#decode.integer)(<<"0">>),
continue(Rest, Original, Skip+Len, Acc, Stack, Decode, Value).

number(<<Num, Rest/bits>>, Original, Skip, Acc, Stack, Decode, Len) when ?is_0_to_9(Num) ->
number(Rest, Original, Skip, Acc, Stack, Decode, Len + 1);
Expand Down
10 changes: 5 additions & 5 deletions lib/stdlib/src/string.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,8 @@ find(String, SearchPattern, trailing) ->
-doc """
Returns a float between `+0.0` and `1.0` representing the
[Jaro similarity](https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance)
between the given strings. Strings with many letters in common relative to their
lengths will score closer to `1.0`.
The Jaro distance between two strings can be calculated with
`JaroDistance = 1.0-JaroSimilarity`.
between the given strings. Strings with a higher similarity will score closer
to `1.0`, with `+0.0` meaning no similarity and `1.0` meaning an exact match.
_Example:_
Expand All @@ -1052,6 +1049,9 @@ _Example:_
4> string:jaro_similarity(<<"Édouard"/utf8>>, <<"Claude">>).
0.5317460317460317
```
The Jaro distance between two strings can be calculated with
`JaroDistance = 1.0 - JaroSimilarity`.
""".
-doc(#{title => <<"Functions">>,since => <<"OTP 27.0">>}).
-spec jaro_similarity(String1, String2) -> Similarity when
Expand Down
20 changes: 11 additions & 9 deletions lib/stdlib/test/json_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ test_decode_api(_Config) ->
null => nil
},

Data = <<"{\"a\": [[], {}, true, false, null, {\"foo\": \"baz\"}], \"b\": [1, 2.0, \"three\"]}">>,
Data = <<"{\"a\": [[], {}, true, false, null, {\"foo\": \"baz\"}], \"b\": [1, 2.0, \"three\", 0]}">>,
{Decoded, Acc, <<>>} = json:decode(Data, {[], 0}, Decoders),
?assertEqual({[], 24}, Acc),
Expected = #{a => [[], #{}, true, false, nil, #{foo => baz}], b => [1, 2.0, three]},
?assertEqual({[], 25}, Acc),
Expected = #{a => [[], #{}, true, false, nil, #{foo => baz}], b => [1, 2.0, three, 0]},
?assertEqual(Expected, Decoded),
ExpectedHistory =
[
Expand Down Expand Up @@ -523,13 +523,15 @@ test_decode_api(_Config) ->
{array_push, {2.0, {[1], 19}}, {[2.0, 1], 20}},
{string, <<"three">>, three},
{array_push, {three, {[2.0, 1], 20}}, {[three, 2.0, 1], 21}},
{array_finish, {{[three, 2.0, 1], 21}, {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 17}},
{[1, 2.0, three], {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 22}}},
{object_push, {b, [1, 2.0, three], {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 22}}, {
[{b, [1, 2.0, three]}, {a, [[], #{}, true, false, nil, #{foo => baz}]}], 23
{integer, <<"0">>, 0},
{array_push, {0, {[three, 2.0, 1], 21}}, {[0, three, 2.0, 1], 22}},
{array_finish, {{[0, three, 2.0, 1], 22}, {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 17}},
{[1, 2.0, three, 0], {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 23}}},
{object_push, {b, [1, 2.0, three, 0], {[{a, [[], #{}, true, false, nil, #{foo => baz}]}], 23}}, {
[{b, [1, 2.0, three, 0]}, {a, [[], #{}, true, false, nil, #{foo => baz}]}], 24
}},
{object_finish, {{[{b, [1, 2.0, three]}, {a, [[], #{}, true, false, nil, #{foo => baz}]}], 23}, {[], 0}},
{#{a => [[], #{}, true, false, nil, #{foo => baz}], b => [1, 2.0, three]}, {[], 24}}}
{object_finish, {{[{b, [1, 2.0, three, 0]}, {a, [[], #{}, true, false, nil, #{foo => baz}]}], 24}, {[], 0}},
{#{a => [[], #{}, true, false, nil, #{foo => baz}], b => [1, 2.0, three, 0]}, {[], 25}}}
],
?assertEqual(ExpectedHistory, lists:reverse(get(history))).

Expand Down

0 comments on commit ab1f7d4

Please sign in to comment.