@@ -240,31 +240,33 @@ final class Updater: ObservableObject {
240240 continue
241241 }
242242
243- let line = String ( line)
244- . replacingOccurrences ( of: " - " , with: " " ) // Remove bullet point
243+ let cleanedLine = String ( line)
244+ . replacingOccurrences ( of: " - " , with: " " )
245245 . trimmingCharacters ( in: . whitespaces)
246246
247- var user : String ?
248- if let regex = try ? NSRegularExpression ( pattern: #"\(@(.*)\)"# ) ,
249- let match = regex. firstMatch ( in: line, range: NSRange ( line. startIndex... , in: line) ) {
250- user = Range ( match. range ( at: 1 ) , in: line) . flatMap { String ( line [ $0] ) }
251- }
247+ let user = try ? NSRegularExpression ( pattern: #"\(@(.*?)\)"# )
248+ . firstMatch ( in: cleanedLine, range: NSRange ( cleanedLine. startIndex... , in: cleanedLine) )
249+ . flatMap { Range ( $0. range ( at: 1 ) , in: cleanedLine) . map { String ( cleanedLine [ $0] ) } }
252250
253- var reference : Int ?
254- if let regex = try ? NSRegularExpression ( pattern: #"#(\d+)"# ) ,
255- let match = regex. firstMatch ( in: line, range: NSRange ( line. startIndex... , in: line) ) {
256- reference = Int ( Range ( match. range ( at: 1 ) , in: line) . flatMap { String ( line [ $0] ) } ?? " " )
257- }
251+ let reference = try ? NSRegularExpression ( pattern: #"#(\d+)"# )
252+ . firstMatch ( in: cleanedLine, range: NSRange ( cleanedLine. startIndex... , in: cleanedLine) )
253+ . flatMap { Range ( $0. range ( at: 1 ) , in: cleanedLine) . flatMap { Int ( cleanedLine [ $0] ) } }
258254
259- let emoji = line. unicodeScalars. first ( where: \. properties. isEmoji) ?? currentSection? . unicodeScalars. first ( where: \. properties. isEmoji) ?? " 🔄 "
255+ /// we should use `isEmojiPresentation` instead of `isEmoji` to ensure that `#`s are excluded.
256+ let emoji = cleanedLine. unicodeScalars. first ( where: \. properties. isEmojiPresentation) ?? currentSection? . unicodeScalars. first ( where: \. properties. isEmojiPresentation) ?? " 🔄 "
260257
261- let text = line
262- . suffix ( line . count - 1 )
263- . replacingOccurrences ( of: #"#\d+"# , with: " " , options: . regularExpression) // Remove issue number
264- . replacingOccurrences ( of: #"\(@.*\)"# , with: " " , options: . regularExpression) // Remove author
258+ let text = cleanedLine
259+ . drop ( while : { $0 . unicodeScalars . first ? . properties . isEmojiPresentation == true } ) // remove any emojis
260+ . replacingOccurrences ( of: #"#\d+"# , with: " " , options: . regularExpression)
261+ . replacingOccurrences ( of: #"\(@.*? \)"# , with: " " , options: . regularExpression)
265262 . trimmingCharacters ( in: . whitespacesAndNewlines)
266263
267- changelog [ index] . body. append ( . init( emoji: String ( emoji) , text: text, user: user, reference: reference) )
264+ changelog [ index] . body. append ( . init(
265+ emoji: String ( emoji) ,
266+ text: text,
267+ user: user,
268+ reference: reference
269+ ) )
268270 }
269271 }
270272 }
0 commit comments