Skip to content

Commit b39a5d8

Browse files
author
José Valim
committed
Deprecate %b and %B in favor of %s and %S
1 parent 4caa2e0 commit b39a5d8

34 files changed

+110
-94
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
* [Kernel] `list_to_binary/1`, `binary_to_list/1` and `binary_to_list/3` are deprecated in favor of `String.from_char_list!/1` and `String.to_char_list!/1` for characters and `:binary.list_to_bin/1`, `:binary.bin_to_list/1` and `:binary.bin_to_list/3` for bytes
5151
* [Kernel] `to_binary/1` is deprecated in favor of `to_string/1`
5252
* [Kernel] Deprecate `def/4` and friends in favor of `def/2` with unquote and friends
53+
* [Kernel] Deprecate `%b` and `%B` in favor of `%s` and `%S`
5354
* [List] `List.concat/2` is deprecated in favor of `Enum.concat/2`
5455
* [Macro] `Macro.unescape_binary/1` and `Macro.unescape_binary/2` are deprecated in favor of `Macro.unescape_string/1` and `Macro.unescape_string/2`
5556
* [Mix] `:umbrella` option for umbrella paths has been deprecated in favor of `:in_umbrella`

lib/eex/lib/eex.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defexception EEx.SyntaxError, message: nil
22

33
defmodule EEx do
4-
@moduledoc %B"""
4+
@moduledoc %S"""
55
EEx stands for Embedded Elixir. It allows you to embed
66
Elixir code inside a string in a robust way:
77

lib/eex/lib/eex/engine.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule EEx.Engine do
2-
@moduledoc %B"""
2+
@moduledoc %S"""
33
This is the basic EEx engine that ships with Elixir.
44
An engine needs to implement two functions:
55

lib/elixir/lib/dict.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule Dict do
2-
@moduledoc %B"""
2+
@moduledoc %S"""
33
This module specifies the Dict API expected to be
44
implemented by different dictionaries. It also provides
55
functions that redirect to the underlying Dict, allowing

lib/elixir/lib/file.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ defmodule File do
397397
end
398398
end
399399

400-
@doc %B"""
400+
@doc %S"""
401401
Copies the contents in source to destination.
402402
Similar to the command `cp -r` in Unix systems,
403403
this function behaves differently depending

lib/elixir/lib/inspect.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ defimpl Inspect, for: Atom do
135135
end
136136

137137
defimpl Inspect, for: BitString do
138-
@doc %B"""
138+
@doc %S"""
139139
Represents a string as itself escaping all necessary
140140
characters. Binaries that contain non-printable characters
141141
are printed using the bitstring syntax.
@@ -243,7 +243,7 @@ defimpl Inspect, for: BitString do
243243
end
244244

245245
defimpl Inspect, for: List do
246-
@doc %B"""
246+
@doc %S"""
247247
Represents a list, checking if it can be printed or not.
248248
If so, a single-quoted representation is returned,
249249
otherwise the brackets syntax is used. Keywords are
@@ -389,7 +389,7 @@ defimpl Inspect, for: Number do
389389
end
390390

391391
defimpl Inspect, for: Regex do
392-
@doc %B"""
392+
@doc %S"""
393393
Represents the Regex using the `%r""` syntax.
394394
395395
## Examples

lib/elixir/lib/inspect/algebra.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule Inspect.Algebra do
2-
@moduledoc %B"""
2+
@moduledoc %S"""
33
A set of functions for creating and manipulating algebra
44
documents, as described in ["Strictly Pretty" (2000) by Christian Lindig][0].
55
@@ -130,7 +130,7 @@ defmodule Inspect.Algebra do
130130
def nest(x, 0), do: x
131131
def nest(x, i) when is_integer(i), do: doc_nest(indent: i, doc: x)
132132

133-
@doc %B"""
133+
@doc %S"""
134134
Document entity representing a break. This break can
135135
be rendered as a linebreak or as spaces, depending on the
136136
`mode` of the chosen layout or the provided separator.
@@ -170,7 +170,7 @@ defmodule Inspect.Algebra do
170170
@spec glue(t, binary, t) :: doc_cons_t
171171
def glue(x, g, y) when is_binary(g), do: concat(x, concat(break(g), y))
172172

173-
@doc %B"""
173+
@doc %S"""
174174
Returns a group containing the specified document.
175175
176176
## Examples
@@ -213,7 +213,7 @@ defmodule Inspect.Algebra do
213213
@spec space(t, t) :: doc_cons_t
214214
def space(x, y), do: concat(x, concat(" ", y))
215215

216-
@doc %B"""
216+
@doc %S"""
217217
Inserts a mandatory linebreak between two document entities.
218218
219219
## Examples
@@ -247,7 +247,7 @@ defmodule Inspect.Algebra do
247247

248248
# Elixir conveniences
249249

250-
@doc %B"""
250+
@doc %S"""
251251
Surrounds a document with characters.
252252
253253
Puts the document between left and right enclosing and nesting it.
@@ -266,7 +266,7 @@ defmodule Inspect.Algebra do
266266
group concat [left, nest(doc, @nesting), right]
267267
end
268268

269-
@doc %B"""
269+
@doc %S"""
270270
Maps and glues a collection of items together using the given separator
271271
and surrounds them. A limit can be passed which, once reached, stops
272272
gluing and outputs "..." instead.

lib/elixir/lib/io/ansi.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ defmodule IO.ANSI do
138138
raise ArgumentError, message: "invalid ANSI sequence specification: #{spec}"
139139
end
140140

141-
@doc %B"""
141+
@doc %S"""
142142
Escapes a string by converting named ANSI sequences into actual ANSI codes.
143143
144144
The format for referring to sequences is `%{red}` and `%{red,bright}` (for
@@ -167,7 +167,7 @@ defmodule IO.ANSI do
167167
end
168168
end
169169

170-
@doc %B"""
170+
@doc %S"""
171171
Escapes a string by converting named ANSI sequences into actual ANSI codes.
172172
173173
The format for referring to sequences is `%{red}` and `%{red,bright}` (for

lib/elixir/lib/kernel.ex

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ defmodule Kernel do
13791379
@doc false
13801380
defmacro defmacrop(name, args, guards, do: contents)
13811381

1382-
@doc %B"""
1382+
@doc %S"""
13831383
Exports a module with a record definition and runtime operations.
13841384
13851385
Please see the `Record` module's documentation for an introduction
@@ -1500,7 +1500,7 @@ defmodule Kernel do
15001500
end
15011501
end
15021502

1503-
@doc %B"""
1503+
@doc %S"""
15041504
Defines a set of private macros to manipulate a record definition.
15051505
15061506
This macro defines a set of macros private to the current module to
@@ -2025,7 +2025,7 @@ defmodule Kernel do
20252025
end
20262026
end
20272027

2028-
@doc %B"""
2028+
@doc %S"""
20292029
Inspect the given arguments according to the `Inspect` protocol.
20302030
20312031
## Options
@@ -3373,34 +3373,46 @@ defmodule Kernel do
33733373
end
33743374

33753375
@doc """
3376-
Handles the sigil %B. It simples returns a binary
3376+
Handles the sigil %S. It simples returns a string
33773377
without escaping characters and without interpolations.
33783378
33793379
## Examples
33803380
3381-
iex> %B(foo)
3381+
iex> %S(foo)
33823382
"foo"
3383-
iex> %B(f\#{o}o)
3383+
iex> %S(f\#{o}o)
33843384
"f\\\#{o}o"
33853385
33863386
"""
3387+
defmacro sigil_S(string, []) do
3388+
string
3389+
end
3390+
3391+
@doc false
33873392
defmacro sigil_B(string, []) do
3393+
IO.write "%B() is deprecated, please use %S() instead\n#{Exception.format_stacktrace}"
33883394
string
33893395
end
33903396

33913397
@doc """
3392-
Handles the sigil %b. It returns a binary as if it was double quoted
3398+
Handles the sigil %s. It returns a string as if it was double quoted
33933399
string, unescaping characters and replacing interpolations.
33943400
33953401
## Examples
33963402
3397-
iex> %b(foo)
3403+
iex> %s(foo)
33983404
"foo"
3399-
iex> %b(f\#{:o}o)
3405+
iex> %s(f\#{:o}o)
34003406
"foo"
34013407
34023408
"""
3409+
defmacro sigil_s({ :<<>>, line, pieces }, []) do
3410+
{ :<<>>, line, Macro.unescape_tokens(pieces) }
3411+
end
3412+
3413+
@doc false
34033414
defmacro sigil_b({ :<<>>, line, pieces }, []) do
3415+
IO.write "%b() is deprecated, please use %s() instead\n#{Exception.format_stacktrace}"
34043416
{ :<<>>, line, Macro.unescape_tokens(pieces) }
34053417
end
34063418

@@ -3599,21 +3611,24 @@ defmodule Kernel do
35993611

36003612
defp split_words(string, modifiers) do
36013613
mod = case modifiers do
3602-
[] -> ?b
3603-
[mod] when mod in [?b, ?a, ?c] -> mod
3604-
_else -> raise ArgumentError, message: "modifier must be one of: b, a, c"
3614+
[] -> ?s
3615+
[mod] when mod in [?b] ->
3616+
IO.write "%w()b is deprecated, please use %w()s instead\n#{Exception.format_stacktrace}"
3617+
?s
3618+
[mod] when mod in [?s, ?a, ?c] -> mod
3619+
_else -> raise ArgumentError, message: "modifier must be one of: s, a, c"
36053620
end
36063621

36073622
case is_binary(string) do
36083623
true ->
36093624
case mod do
3610-
?b -> String.split(string)
3625+
?s -> String.split(string)
36113626
?a -> lc p inlist String.split(string), do: binary_to_atom(p)
36123627
?c -> lc p inlist String.split(string), do: String.to_char_list!(p)
36133628
end
36143629
false ->
36153630
case mod do
3616-
?b -> quote do: String.split(unquote(string))
3631+
?s -> quote do: String.split(unquote(string))
36173632
?a -> quote do: lc(p inlist String.split(unquote(string)), do: binary_to_atom(p))
36183633
?c -> quote do: lc(p inlist String.split(unquote(string)), do: String.to_char_list!(p))
36193634
end

lib/elixir/lib/list/chars.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defprotocol List.Chars do
2-
@moduledoc %B"""
2+
@moduledoc %S"""
33
The List.Chars protocol is responsible for
44
converting a structure to a list (only if applicable).
55
The only function required to be implemented is

0 commit comments

Comments
 (0)