2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
9
9
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- // This file defines extensions for interpolating integer expressions into a
13
+ // This file defines extensions for interpolating integer expressions into an
14
14
// OSLogMesage. It defines `appendInterpolation` functions for standard integer
15
15
// types. It also defines extensions for serializing integer types into the
16
16
// argument buffer passed to os_log ABIs.
17
17
//
18
- // The `appendInterpolation` functions defined in this file accept formatting
19
- // and privacy options along with the interpolated expression as shown below:
18
+ // The `appendInterpolation` functions defined in this file accept formatting,
19
+ // privacy and alignment options along with the interpolated expression as
20
+ // shown below:
20
21
//
21
- // "\(x, format: .hex, privacy: .private\)"
22
+ // 1. "\(x, format: .hex, privacy: .private, align: .right\)"
23
+ // 2. "\(x, format: .hex(minDigits: 10), align: .right(columns: 10)\)"
22
24
23
25
extension OSLogInterpolation {
24
26
25
27
/// Define interpolation for expressions of type Int.
26
28
/// - Parameters:
27
29
/// - number: the interpolated expression of type Int, which is autoclosured.
28
30
/// - format: a formatting option available for integer types, defined by the
29
- /// enum `OSLogIntegerFormatting`.
31
+ /// type`OSLogIntegerFormatting`. The default is .decimal.
32
+ /// - align: left or right alignment with the minimum number of columns as
33
+ /// defined by the type `OSLogStringAlignment`.
30
34
/// - privacy: a privacy qualifier which is either private or public.
31
- /// The default is public .
35
+ /// It is auto-inferred by default .
32
36
@_semantics ( " constant_evaluable " )
33
37
@inlinable
34
38
@_optimize ( none)
35
39
public mutating func appendInterpolation(
36
40
_ number: @autoclosure @escaping ( ) -> Int ,
37
41
format: OSLogIntegerFormatting = . decimal,
38
42
align: OSLogStringAlignment = . none,
39
- privacy: OSLogPrivacy = . public
43
+ privacy: OSLogPrivacy = . auto
40
44
) {
41
45
appendInteger ( number, format: format, align: align, privacy: privacy)
42
46
}
@@ -45,17 +49,19 @@ extension OSLogInterpolation {
45
49
/// - Parameters:
46
50
/// - number: the interpolated expression of type Int32, which is autoclosured.
47
51
/// - format: a formatting option available for integer types, defined by the
48
- /// enum `OSLogIntegerFormatting`.
52
+ /// type `OSLogIntegerFormatting`.
53
+ /// - align: left or right alignment with the minimum number of columns as
54
+ /// defined by the type `OSLogStringAlignment`.
49
55
/// - privacy: a privacy qualifier which is either private or public.
50
- /// The default is public .
56
+ /// It is auto-inferred by default .
51
57
@_semantics ( " constant_evaluable " )
52
58
@inlinable
53
59
@_optimize ( none)
54
60
public mutating func appendInterpolation(
55
61
_ number: @autoclosure @escaping ( ) -> Int32 ,
56
62
format: OSLogIntegerFormatting = . decimal,
57
63
align: OSLogStringAlignment = . none,
58
- privacy: OSLogPrivacy = . public
64
+ privacy: OSLogPrivacy = . auto
59
65
) {
60
66
appendInteger ( number, format: format, align: align, privacy: privacy)
61
67
}
@@ -64,17 +70,19 @@ extension OSLogInterpolation {
64
70
/// - Parameters:
65
71
/// - number: the interpolated expression of type UInt, which is autoclosured.
66
72
/// - format: a formatting option available for integer types, defined by the
67
- /// enum `OSLogIntegerFormatting`.
73
+ /// type `OSLogIntegerFormatting`.
74
+ /// - align: left or right alignment with the minimum number of columns as
75
+ /// defined by the type `OSLogStringAlignment`.
68
76
/// - privacy: a privacy qualifier which is either private or public.
69
- /// The default is public .
77
+ /// It is auto-inferred by default .
70
78
@_semantics ( " constant_evaluable " )
71
79
@inlinable
72
80
@_optimize ( none)
73
81
public mutating func appendInterpolation(
74
82
_ number: @autoclosure @escaping ( ) -> UInt ,
75
83
format: OSLogIntegerFormatting = . decimal,
76
84
align: OSLogStringAlignment = . none,
77
- privacy: OSLogPrivacy = . public
85
+ privacy: OSLogPrivacy = . auto
78
86
) {
79
87
appendInteger ( number, format: format, align: align, privacy: privacy)
80
88
}
@@ -94,9 +102,7 @@ extension OSLogInterpolation {
94
102
guard argumentCount < maxOSLogArgumentCount else { return }
95
103
formatString +=
96
104
format. formatSpecifier ( for: T . self, align: align, privacy: privacy)
97
-
98
- let isPrivateArgument = isPrivate ( privacy)
99
- addIntHeaders ( isPrivateArgument, sizeForEncoding ( T . self) )
105
+ addIntHeaders ( privacy, sizeForEncoding ( T . self) )
100
106
101
107
arguments. append ( number)
102
108
argumentCount += 1
@@ -107,9 +113,12 @@ extension OSLogInterpolation {
107
113
@_semantics ( " constant_evaluable " )
108
114
@inlinable
109
115
@_optimize ( none)
110
- internal mutating func addIntHeaders( _ isPrivate: Bool , _ byteCount: Int ) {
116
+ internal mutating func addIntHeaders(
117
+ _ privacy: OSLogPrivacy ,
118
+ _ byteCount: Int
119
+ ) {
111
120
// Append argument header.
112
- let argumentHeader = getArgumentHeader ( isPrivate : isPrivate , type: . scalar)
121
+ let argumentHeader = getArgumentHeader ( privacy : privacy , type: . scalar)
113
122
arguments. append ( argumentHeader)
114
123
115
124
// Append number of bytes needed to serialize the argument.
@@ -120,7 +129,7 @@ extension OSLogInterpolation {
120
129
// two bytes needed for the headers.
121
130
totalBytesForSerializingArguments += byteCount + 2
122
131
123
- preamble = getUpdatedPreamble ( isPrivate : isPrivate , isScalar: true )
132
+ preamble = getUpdatedPreamble ( privacy : privacy , isScalar: true )
124
133
}
125
134
}
126
135
0 commit comments