Skip to content

Commit fbac408

Browse files
committed
Merge branch 'lukas/stdlib/doctest-uri-string/OTP-20322' into maint
* lukas/stdlib/doctest-uri-string/OTP-20322: stdlib: Update string to use doctests for its examples stdlib: Update uri_string to use doctests for its examples
2 parents 2e99ee9 + 597dec5 commit fbac408

4 files changed

Lines changed: 67 additions & 147 deletions

File tree

lib/stdlib/src/string.erl

Lines changed: 21 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ _Example:_
354354
```erlang
355355
1> Reverse = string:reverse(unicode:characters_to_nfd_binary("ÅÄÖ")).
356356
[[79,776],[65,776],[65,778]]
357-
2> io:format("~ts~n",[Reverse]).
358-
ÖÄÅ
357+
2> io:format("%% ~ts~n",[Reverse]).
358+
%% ÖÄÅ
359359
```
360360
""".
361361
-doc(#{group => <<"Functions">>,since => <<"OTP 20.0">>}).
@@ -444,10 +444,10 @@ _Example:_
444444
```erlang
445445
1> string:pad(<<"He̊llö"/utf8>>, 8).
446446
[<<72,101,204,138,108,108,195,182>>,32,32,32]
447-
2> io:format("'~ts'~n",[string:pad("He̊llö", 8, leading)]).
448-
' He̊llö'
449-
3> io:format("'~ts'~n",[string:pad("He̊llö", 8, both)]).
450-
' He̊llö '
447+
2> io:format("%% '~ts'~n",[string:pad("He̊llö", 8, leading)]).
448+
%% ' He̊llö'
449+
3> io:format("%% '~ts'~n",[string:pad("He̊llö", 8, both)]).
450+
%% ' He̊llö '
451451
```
452452
""".
453453
-doc(#{group => <<"Functions">>,since => <<"OTP 20.0">>}).
@@ -542,9 +542,9 @@ Returns a string where any trailing `\n` or `\r\n` have been removed from
542542
_Example:_
543543

544544
```erlang
545-
182> string:chomp(<<"\nHello\n\n">>).
545+
1> string:chomp(<<"\nHello\n\n">>).
546546
<<"\nHello">>
547-
183> string:chomp("\nHello\r\r\n").
547+
2> string:chomp("\nHello\r\r\n").
548548
"\nHello\r"
549549
```
550550
""".
@@ -582,13 +582,13 @@ taken.
582582
_Example:_
583583

584584
```erlang
585-
5> string:take("abc0z123", lists:seq($a,$z)).
585+
1> string:take("abc0z123", lists:seq($a,$z)).
586586
{"abc","0z123"}
587-
6> string:take(<<"abc0z123">>, lists:seq($0,$9), true, leading).
587+
2> string:take(<<"abc0z123">>, lists:seq($0,$9), true, leading).
588588
{<<"abc">>,<<"0z123">>}
589-
7> string:take("abc0z123", lists:seq($0,$9), false, trailing).
589+
3> string:take("abc0z123", lists:seq($0,$9), false, trailing).
590590
{"abc0z","123"}
591-
8> string:take(<<"abc0z123">>, lists:seq($a,$z), true, trailing).
591+
4> string:take(<<"abc0z123">>, lists:seq($a,$z), true, trailing).
592592
{<<"abc0z">>,<<"123">>}
593593
```
594594
""".
@@ -660,7 +660,7 @@ tested for equality.
660660
_Example:_
661661

662662
```erlang
663-
2> string:lowercase(string:uppercase("Michał")).
663+
1> string:lowercase(string:uppercase("Michał")).
664664
"michał"
665665
```
666666
""".
@@ -745,8 +745,8 @@ _Example:_
745745

746746
```erlang
747747
1> {I1,Is} = string:to_integer("33+22"),
748-
1> {I2,[]} = string:to_integer(Is),
749-
1> I1-I2.
748+
{I2,[]} = string:to_integer(Is),
749+
I1-I2.
750750
11
751751
2> string:to_integer("0.5").
752752
{0,".5"}
@@ -786,8 +786,8 @@ _Example:_
786786

787787
```erlang
788788
1> {F1,Fs} = string:to_float("1.0-1.0e-1"),
789-
1> {F2,[]} = string:to_float(Fs),
790-
1> F1+F2.
789+
{F2,[]} = string:to_float(Fs),
790+
F1+F2.
791791
0.9
792792
2> string:to_float("3/2=1.5").
793793
{error,no_float}
@@ -870,11 +870,11 @@ parts. `Where`, default `leading`, indicates whether the `leading`, the
870870
_Example:_
871871

872872
```erlang
873-
0> string:split("ab..bc..cd", "..").
873+
1> string:split("ab..bc..cd", "..").
874874
["ab","bc..cd"]
875-
1> string:split(<<"ab..bc..cd">>, "..", trailing).
875+
2> string:split(<<"ab..bc..cd">>, "..", trailing).
876876
[<<"ab..bc">>,<<"cd">>]
877-
2> string:split(<<"ab..bc....cd">>, "..", all).
877+
3> string:split(<<"ab..bc....cd">>, "..", all).
878878
[<<"ab">>,<<"bc">>,<<>>,<<"cd">>]
879879
```
880880
""".
@@ -2506,13 +2506,6 @@ Returns the position where the first occurrence of `SubString` begins in
25062506
`String`. Returns `0` if `SubString` does not exist in `String`.
25072507

25082508
This function is [obsolete](`m:string#obsolete-api-functions`). Use `find/2`.
2509-
2510-
_Example:_
2511-
2512-
```erlang
2513-
1> string:str(" Hello Hello World World ", "Hello World").
2514-
8
2515-
```
25162509
""".
25172510
-doc(#{group => <<"Obsolete API functions">>}).
25182511
-spec str(String, SubString) -> Index when
@@ -2535,13 +2528,6 @@ Returns the position where the last occurrence of `SubString` begins in
25352528
`String`. Returns `0` if `SubString` does not exist in `String`.
25362529

25372530
This function is [obsolete](`m:string#obsolete-api-functions`). Use `find/3`.
2538-
2539-
_Example:_
2540-
2541-
```erlang
2542-
1> string:rstr(" Hello Hello World World ", "Hello World").
2543-
8
2544-
```
25452531
""".
25462532
-doc(#{group => <<"Obsolete API functions">>}).
25472533
-spec rstr(String, SubString) -> Index when
@@ -2571,13 +2557,6 @@ Returns the length of the maximum initial segment of `String`, which consists
25712557
entirely of characters from `Chars`.
25722558

25732559
This function is [obsolete](`m:string#obsolete-api-functions`). Use `take/2`.
2574-
2575-
_Example:_
2576-
2577-
```erlang
2578-
1> string:span("\t abcdef", " \t").
2579-
5
2580-
```
25812560
""".
25822561
-doc(#{group => <<"Obsolete API functions">>}).
25832562
-spec span(String, Chars) -> Length when
@@ -2599,13 +2578,6 @@ Returns the length of the maximum initial segment of `String`, which consists
25992578
entirely of characters not from `Chars`.
26002579

26012580
This function is [obsolete](`m:string#obsolete-api-functions`). Use `take/3`.
2602-
2603-
_Example:_
2604-
2605-
```erlang
2606-
1> string:cspan("\t abcdef", " \t").
2607-
0
2608-
```
26092581
""".
26102582
-doc(#{group => <<"Obsolete API functions">>}).
26112583
-spec cspan(String, Chars) -> Length when
@@ -2643,13 +2615,6 @@ Returns a substring of `String`, starting at position `Start`, and ending at the
26432615
end of the string or at length `Length`.
26442616

26452617
This function is [obsolete](`m:string#obsolete-api-functions`). Use `slice/3`.
2646-
2647-
_Example:_
2648-
2649-
```erlang
2650-
1> substr("Hello World", 4, 5).
2651-
"lo Wo"
2652-
```
26532618
""".
26542619
-doc(#{group => <<"Obsolete API functions">>}).
26552620
-spec substr(String, Start, Length) -> SubString when
@@ -2674,14 +2639,7 @@ substr2([_|String], S) -> substr2(String, S-1).
26742639
Returns a list of tokens in `String`, separated by the characters in
26752640
`SeparatorList`.
26762641

2677-
_Example:_
2678-
2679-
```erlang
2680-
1> tokens("abc defxxghix jkl", "x ").
2681-
["abc", "def", "ghi", "jkl"]
2682-
```
2683-
2684-
Notice that, as shown in this example, two or more adjacent separator characters
2642+
Notice that two or more adjacent separator characters
26852643
in `String` are treated as one. That is, there are no empty strings in the
26862644
resulting list of tokens.
26872645

@@ -2802,13 +2760,6 @@ words(String) -> words(String, $\s).
28022760
Returns the number of words in `String`, separated by blanks or `Character`.
28032761

28042762
This function is [obsolete](`m:string#obsolete-api-functions`). Use `lexemes/2`.
2805-
2806-
_Example:_
2807-
2808-
```erlang
2809-
1> words(" Hello old boy!", $o).
2810-
4
2811-
```
28122763
""".
28132764
-doc(#{group => <<"Obsolete API functions">>}).
28142765
-spec words(String, Character) -> Count when
@@ -2840,13 +2791,6 @@ or `Character`s.
28402791

28412792
This function is [obsolete](`m:string#obsolete-api-functions`). Use
28422793
`nth_lexeme/3`.
2843-
2844-
_Example:_
2845-
2846-
```erlang
2847-
1> string:sub_word(" Hello old boy !",3,$o).
2848-
"ld b"
2849-
```
28502794
""".
28512795
-doc(#{group => <<"Obsolete API functions">>}).
28522796
-spec sub_word(String, Number, Character) -> Word when
@@ -2900,13 +2844,6 @@ Returns a string, where leading or trailing, or both, blanks or a number of
29002844
[`strip/1`](`strip/1`) is equivalent to [`strip(String, both)`](`strip/2`).
29012845

29022846
This function is [obsolete](`m:string#obsolete-api-functions`). Use `trim/3`.
2903-
2904-
_Example:_
2905-
2906-
```erlang
2907-
1> string:strip("...Hello.....", both, $.).
2908-
"Hello"
2909-
```
29102847
""".
29112848
-doc(#{group => <<"Obsolete API functions">>}).
29122849
-spec strip(String, Direction, Character) -> Stripped when
@@ -2953,13 +2890,6 @@ padded with blanks or `Character`s.
29532890

29542891
This function is [obsolete](`m:string#obsolete-api-functions`). Use `pad/2` or
29552892
`pad/3`.
2956-
2957-
_Example:_
2958-
2959-
```erlang
2960-
1> string:left("Hello",10,$.).
2961-
"Hello....."
2962-
```
29632893
""".
29642894
-doc(#{group => <<"Obsolete API functions">>}).
29652895
-spec left(String, Number, Character) -> Left when
@@ -2995,13 +2925,6 @@ margin is fixed. If the length of `(String)` < `Number`, then `String` is padded
29952925
with blanks or `Character`s.
29962926

29972927
This function is [obsolete](`m:string#obsolete-api-functions`). Use `pad/3`.
2998-
2999-
_Example:_
3000-
3001-
```erlang
3002-
1> string:right("Hello", 10, $.).
3003-
".....Hello"
3004-
```
30052928
""".
30062929
-doc(#{group => <<"Obsolete API functions">>}).
30072930
-spec right(String, Number, Character) -> Right when
@@ -3072,13 +2995,6 @@ Returns a substring of `String`, starting at position `Start` to the end of the
30722995
string, or to and including position `Stop`.
30732996

30742997
This function is [obsolete](`m:string#obsolete-api-functions`). Use `slice/3`.
3075-
3076-
_Example:_
3077-
3078-
```erlang
3079-
1> sub_string("Hello World", 4, 8).
3080-
"lo Wo"
3081-
```
30822998
""".
30832999
-doc(#{group => <<"Obsolete API functions">>}).
30843000
-spec sub_string(String, Start, Stop) -> SubString when
@@ -3160,13 +3076,6 @@ Returns a string with the elements of `StringList` separated by the string in
31603076

31613077
This function is [obsolete](`m:string#obsolete-api-functions`). Use
31623078
`lists:join/2`.
3163-
3164-
_Example:_
3165-
3166-
```erlang
3167-
1> join(["one", "two", "three"], ", ").
3168-
"one, two, three"
3169-
```
31703079
""".
31713080
-doc(#{group => <<"Obsolete API functions">>}).
31723081
-spec join(StringList, Separator) -> String when

0 commit comments

Comments
 (0)