Skip to content

Commit

Permalink
Add support for emojis in hashtags and mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
psharanda committed Jul 17, 2020
1 parent bbc3538 commit a5332ad
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Atributika.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Atributika"
s.version = "4.9.8"
s.version = "4.9.9"
s.summary = "Convert text with HTML tags, hashtags, mentions, links into NSAttributedString. Make them clickable with UILabel drop-in replacement."
s.description = <<-DESC
`Atributika` is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or even standard ios data detectors and style them with various attributes like font, color, etc. `Atributika` comes with drop-in label replacement `AttributedLabel` which is able to make any detection clickable.
Expand Down
5 changes: 3 additions & 2 deletions Demo/AttributedLabelDemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AttributedLabelDemoViewController: UIViewController {

private var tweets: [String] = [
"@e2F If only Bradley's arm was longer. Best photo ever. 😊 #oscars https://pic.twitter.com/C9U5NOtGap<br>Check this <a href=\"https://github.com/psharanda/Atributika\">link</a>",
"@e2F If only Bradley's arm was longer. Best photo ever. 😊 #oscars https://pic.twitter.com/C9U5NOtGap<br>Check this <a href=\"https://github.com/psharanda/Atributika\">link that won't detect click here</a>",
"@e2F If only Bradley's arm was longer. Best photo ever. 😊 #oscars😊 https://pic.twitter.com/C9U5NOtGap<br>Check this <a href=\"https://github.com/psharanda/Atributika\">link that won't detect click here</a>",
"For every retweet this gets, Pedigree will donate one bowl of dog food to dogs in need! 😊 #tweetforbowls",
"All the love as always. H",
"We got kicked out of a @Delta airplane because I spoke Arabic to my mom on the phone and with my friend slim... WTFFFFFFFF please spread",
Expand All @@ -41,7 +41,8 @@ class AttributedLabelDemoViewController: UIViewController {
"Always in my heart @Harry_Styles . Yours sincerely, Louis",
"HELP ME PLEASE. A MAN NEEDS HIS NUGGS https://pbs.twimg.com/media/C8sk8QlUwAAR3qI.jpg",
"Подтверждая номер телефона, вы\nпринимаете «<a>пользовательское соглашение</a>»",
"Here's how a similar one was solved 😄 \nhttps://medium.com/@narcelio/solving-decred-mockingbird-puzzle-5366efeaeed7\n"
"Here's how a similar one was solved 😄 \nhttps://medium.com/@narcelio/solving-decred-mockingbird-puzzle-5366efeaeed7\n",
"#Hello @World!"
]

override func viewDidLoad() {
Expand Down
4 changes: 2 additions & 2 deletions Sources/String+Detection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ extension String {

public func detectHashTags() -> [Range<String.Index>] {

return detect(regex: "[#]\\w\\S*\\b")
return detect(regex: "#[^[:punct:][:space:]]+")
}

public func detectMentions() -> [Range<String.Index>] {

return detect(regex: "[@]\\w\\S*\\b")
return detect(regex: "@[^[:punct:][:space:]]+")
}

public func detect(regex: String, options: NSRegularExpression.Options = []) -> [Range<String.Index>] {
Expand Down

1 comment on commit a5332ad

@qxtaiba
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! I just tried running this commit, although it still isn't recognizing hashtags with emojis as hashtags. I tested this by adding a breakpoint and when there is an emoji at the end, the hashtag case is never triggered.

I ttried creating a PR with a fix that worked for me but I don't have access to this repository.

If you simply replace return detect(regex: "[#]\\w\\S*\\b") with return detect(regex: "[#]\\S+") then you'll find that emojis are detected as part of the tag.

Please sign in to comment.