Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F13780807
tags.go
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
tags.go
View Options
package
category
import
(
"strings"
"unicode"
)
// titleFromHashtag generates an all-lowercase title, with spaces inserted based on initial capitalization -- e.g.
// "MyWordyTag" becomes "my wordy tag".
func
titleFromHashtag
(
hashtag
string
)
string
{
var
t
strings
.
Builder
var
prev
rune
for
i
,
c
:=
range
hashtag
{
if
unicode
.
IsUpper
(
c
)
{
if
i
>
0
&&
!
unicode
.
IsUpper
(
prev
)
{
// Insert space if previous rune wasn't also uppercase (e.g. an abbreviation)
t
.
WriteRune
(
' '
)
}
t
.
WriteRune
(
unicode
.
ToLower
(
c
))
}
else
{
t
.
WriteRune
(
c
)
}
prev
=
c
}
return
t
.
String
()
}
// HashtagFromTitle generates a valid single-word, camelCase hashtag from a title (which might include spaces,
// punctuation, etc.).
func
HashtagFromTitle
(
title
string
)
string
{
var
t
strings
.
Builder
var
prev
rune
for
_
,
c
:=
range
title
{
if
!
unicode
.
IsLetter
(
c
)
&&
!
unicode
.
IsNumber
(
c
)
{
prev
=
c
continue
}
if
unicode
.
IsSpace
(
prev
)
{
// Uppercase next word
t
.
WriteRune
(
unicode
.
ToUpper
(
c
))
}
else
{
t
.
WriteRune
(
c
)
}
prev
=
c
}
return
t
.
String
()
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 30, 2:13 PM (4 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3610794
Attached To
rWC Write.as Web Core
Event Timeline
Log In to Comment