@@ -2102,18 +2102,27 @@ end
2102
2102
"""
2103
2103
`alignment(io, X)` returns a tuple (left,right) showing how many characters are
2104
2104
needed on either side of an alignment feature such as a decimal point.
2105
+
2106
+ # Examples
2107
+ ```jldoctest
2108
+ julia> Base.alignment(stdout, 42)
2109
+ (2, 0)
2110
+
2111
+ julia> Base.alignment(stdout, 4.23)
2112
+ (1, 3)
2113
+
2114
+ julia> Base.alignment(stdout, 1 + 10im)
2115
+ (3, 5)
2116
+ ```
2105
2117
"""
2106
2118
alignment (io:: IO , x:: Any ) = (0 , length (sprint (show, x, context= io, sizehint= 0 )))
2107
2119
alignment (io:: IO , x:: Number ) = (length (sprint (show, x, context= io, sizehint= 0 )), 0 )
2108
- " `alignment(stdout, 42)` yields (2, 0)"
2109
2120
alignment (io:: IO , x:: Integer ) = (length (sprint (show, x, context= io, sizehint= 0 )), 0 )
2110
- " `alignment(stdout, 4.23)` yields (1, 3) for `4` and `.23`"
2111
2121
function alignment (io:: IO , x:: Real )
2112
2122
m = match (r" ^(.*?)((?:[\. eEfF].*)?)$" , sprint (show, x, context= io, sizehint= 0 ))
2113
2123
m === nothing ? (length (sprint (show, x, context= io, sizehint= 0 )), 0 ) :
2114
2124
(length (m. captures[1 ]), length (m. captures[2 ]))
2115
2125
end
2116
- " `alignment(stdout, 1 + 10im)` yields (3, 5) for `1 +` and `_10im` (plus sign on left, space on right)"
2117
2126
function alignment (io:: IO , x:: Complex )
2118
2127
m = match (r" ^(.*[^ef][\+\- ])(.*)$" , sprint (show, x, context= io, sizehint= 0 ))
2119
2128
m === nothing ? (length (sprint (show, x, context= io, sizehint= 0 )), 0 ) :
0 commit comments