@@ -1017,15 +1017,12 @@ func unmarshalConnectionInformation(value: String) throws -> ConnectionInformati
1017
1017
}
1018
1018
1019
1019
let address : Address ? =
1020
- if fields. count > 2 {
1021
- Address (
1022
- address: fields [ 2 ] ,
1023
- ttl: nil ,
1024
- range: nil
1025
- )
1026
- } else {
1027
- nil
1028
- }
1020
+ fields. count > 2
1021
+ ? Address (
1022
+ address: fields [ 2 ] ,
1023
+ ttl: nil ,
1024
+ range: nil
1025
+ ) : nil
1029
1026
1030
1027
return ConnectionInformation (
1031
1028
networkType: fields [ 0 ] ,
@@ -1155,16 +1152,10 @@ func unmarshalSessionAttribute(lexer: inout Lexer) throws -> StateFn? {
1155
1152
let value = try lexer. readValue ( )
1156
1153
1157
1154
let fields = value. split ( separator: " : " , maxSplits: 1 ) . map { String ( $0) }
1158
- let attribute =
1159
- if fields. count == 2 {
1160
- Attribute (
1161
- key: fields [ 0 ] ,
1162
- value: fields [ 1 ]
1163
- )
1164
- } else {
1165
- Attribute (
1166
- key: fields [ 0 ] )
1167
- }
1155
+ let attribute = Attribute (
1156
+ key: fields [ 0 ] ,
1157
+ value: fields. count == 2 ? fields [ 1 ] : nil
1158
+ )
1168
1159
lexer. desc. attributes. append ( attribute)
1169
1160
1170
1161
return StateFn ( f: s11)
@@ -1294,16 +1285,10 @@ func unmarshalMediaAttribute(lexer: inout Lexer) throws -> StateFn? {
1294
1285
let value = try lexer. readValue ( )
1295
1286
1296
1287
let fields = value. split ( separator: " : " , maxSplits: 1 ) . map { String ( $0) }
1297
- let attribute =
1298
- if fields. count == 2 {
1299
- Attribute (
1300
- key: fields [ 0 ] ,
1301
- value: fields [ 1 ] )
1302
- } else {
1303
- Attribute (
1304
- key: fields [ 0 ] )
1305
- }
1306
-
1288
+ let attribute = Attribute (
1289
+ key: fields [ 0 ] ,
1290
+ value: fields. count == 2 ? fields [ 1 ] : nil
1291
+ )
1307
1292
if lexer. desc. mediaDescriptions. isEmpty {
1308
1293
throw SDPError . sdpEmptyTimeDescription
1309
1294
}
@@ -1317,23 +1302,26 @@ func unmarshalMediaAttribute(lexer: inout Lexer) throws -> StateFn? {
1317
1302
func parseTimeUnits( value: String ) throws -> Int64 {
1318
1303
// Some time offsets in the protocol can be provided with a shorthand
1319
1304
// notation. This code ensures to convert it to NTP timestamp format.
1320
- let ( num, factor) =
1321
- if let last = value. last {
1322
- switch last {
1323
- case " d " :
1324
- ( String ( value. dropLast ( ) ) , 86400 ) // days
1325
- case " h " :
1326
- ( String ( value. dropLast ( ) ) , 3600 ) // hours
1327
- case " m " :
1328
- ( String ( value. dropLast ( ) ) , 60 ) // minutes
1329
- case " s " :
1330
- ( String ( value. dropLast ( ) ) , 1 ) // seconds (allowed for completeness)
1331
- default :
1332
- ( value, 1 )
1333
- }
1334
- } else {
1335
- ( value, 1 )
1305
+ var ( num, factor) = ( value, 1 )
1306
+ if let last = value. last {
1307
+ switch last {
1308
+ case " d " :
1309
+ num = String ( value. dropLast ( ) )
1310
+ factor = 86400 // days
1311
+ case " h " :
1312
+ num = String ( value. dropLast ( ) )
1313
+ factor = 3600 // hours
1314
+ case " m " :
1315
+ num = String ( value. dropLast ( ) )
1316
+ factor = 60 // minutes
1317
+ case " s " :
1318
+ num = String ( value. dropLast ( ) )
1319
+ factor = 1 // seconds (allowed for completeness)
1320
+ default :
1321
+ num = value
1322
+ factor = 1
1336
1323
}
1324
+ }
1337
1325
1338
1326
guard let parsedNum = Int64 ( num) else {
1339
1327
throw SDPError . sdpInvalidValue ( value)
0 commit comments