本文整理汇总了Golang中html.UnescapeString函数的典型用法代码示例。如果您正苦于以下问题:Golang UnescapeString函数的具体用法?Golang UnescapeString怎么用?Golang UnescapeString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UnescapeString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TrimString
// TrimString returns the specified number of characters from the
// specified string
func (viewHelper *ViewHelper) TrimString(s string, length int) string {
if len(s) <= length {
return html.UnescapeString(s)
}
return html.UnescapeString(s[0:length])
}
示例2: fetch
func fetch(urls []string) Entries {
var result Entries
p := gofeed.NewParser()
for _, url := range urls {
resp, err := http.Get(url)
if err != nil {
log.Error("cannot fetch feed", "url", url, "error", err.Error())
continue
}
feed, err := p.Parse(resp.Body)
resp.Body.Close()
if err != nil {
log.Error("cannot parse feed", "url", url, "error", err.Error())
continue
}
for _, it := range feed.Items {
result = append(result, &Entry{
Feed: Feed{
Title: html.UnescapeString(feed.Title),
Link: feed.Link,
},
Title: html.UnescapeString(it.Title),
Link: it.Link,
Published: parseTime(it.Published),
})
}
}
return result
}
示例3: formatEvent
func (m *Module) formatEvent(event interface{}) string {
var msg string
switch t := event.(type) {
case anaconda.ApiError:
msg = fmt.Sprintf("Twitter API error %d: %s", t.StatusCode, t.Decoded.Error())
case anaconda.StatusDeletionNotice:
msg = fmt.Sprintf("Tweet %d has been deleted", t.Id)
case anaconda.DirectMessage:
msg = fmt.Sprintf("Direct message %d by %s sent to %s: %s", t.Id,
t.SenderScreenName, t.RecipientScreenName, html.UnescapeString(t.Text))
case anaconda.Tweet:
if t.RetweetedStatus != nil && t.User.Id != m.user.Id {
break
}
msg = fmt.Sprintf("Tweet %d by %s: %s", t.Id, t.User.ScreenName,
html.UnescapeString(t.Text))
case anaconda.EventTweet:
if t.Event.Event != "favorite" || t.Source.Id != m.user.Id {
break
}
text := html.UnescapeString(t.TargetObject.Text)
msg = fmt.Sprintf("%s favorited tweet %d by %s: %s",
t.Source.ScreenName, t.TargetObject.Id, t.Target.ScreenName, text)
}
return msg
}
示例4: main
func main() {
raw := []string{
"hello",
"<i>Hello</i>",
"alert('hello');",
"foo & bar",
`"how are you?" He asked.`,
}
log.Println("html.EscapeString")
for _, s := range raw {
log.Printf("\t%s -> %s", s, html.EscapeString(s))
}
log.Println("html.UnescapeString(html.EscapeString)")
for _, s := range raw {
flipped := html.UnescapeString(html.EscapeString(s))
log.Printf("\t%s -> %s", s, flipped)
}
escaped := []string{
"á",
"»",
"·",
"<i>htllo</i>",
}
log.Println("html.UnescapeString")
for _, s := range escaped {
log.Printf("\t%s -> %s", s, html.UnescapeString(s))
}
}
示例5: AddQuestions
func AddQuestions(db *sql.DB, newQns *stackongo.Questions) error {
defer UpdateTableTimes(db, "questions")
for _, item := range newQns.Items {
//INSERT IGNORE ensures that the same question won't be added again
stmt, err := db.Prepare("INSERT IGNORE INTO questions(question_id, question_title, question_URL, body, creation_date) VALUES (?, ?, ?, ?, ?)")
if err != nil {
return err
}
_, err = stmt.Exec(item.Question_id, html.UnescapeString(item.Title), item.Link, html.UnescapeString(StripTags(item.Body)), item.Creation_date)
if err != nil {
log.Println("Exec insertion for question failed!:\t", err)
continue
}
for _, tag := range item.Tags {
stmt, err = db.Prepare("INSERT IGNORE INTO question_tag(question_id, tag) VALUES(?, ?)")
if err != nil {
log.Println("question_tag insertion failed!:\t", err)
continue
}
_, err = stmt.Exec(item.Question_id, tag)
if err != nil {
log.Println("Exec insertion for question_tag failed!:\t", err)
continue
}
}
}
return nil
}
示例6: Google
func Google(searchTerm string, results int) GoogleResult {
var resp GoogleResult
var uri string = fmt.Sprintf("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=%d&q=%s",
results, url.QueryEscape(searchTerm))
body, err := Get(&uri)
if err != "" {
resp.Error = err
return resp
}
errr := json.Unmarshal(body, &resp)
if errr != nil {
resp.Error = errr.Error()
return resp
}
if len(resp.Results.Data) == 0 {
resp.Error = fmt.Sprintf("Google couldn't find \"%s\"", searchTerm)
return resp
}
for i, _ := range resp.Results.Data {
if resp.Results.Data[i].Title != "" {
resp.Results.Data[i].Title = html.UnescapeString(resp.Results.Data[i].Title)
}
if resp.Results.Data[i].Content != "" {
resp.Results.Data[i].Content = html.UnescapeString(resp.Results.Data[i].Content)
}
}
return resp
}
示例7: Message
// Message returns the message content for this message.
func (m *LiveChatMessage) Message() string {
switch m.Snippet.Type {
case LiveChatMessageSnippetTypeText:
return html.UnescapeString(m.Snippet.TextMessageDetails.MessageText)
}
return html.UnescapeString(m.Snippet.DisplayMessage)
}
示例8: parseRSS
func parseRSS(rss []byte, source string) (map[string]MangaEntry, error) {
src := strings.Split(lib.Sanitise(string(rss[bytes.Index(rss, []byte("<item>")):])), "</item>")
src = src[0 : len(src)-1]
entries := map[string]MangaEntry{}
var title, tmpDate string
for _, line := range src {
if line == "" {
continue
}
title = line[strings.Index(line, "<title>")+7 : strings.Index(line, "</title>")]
title = html.UnescapeString(title)
if source == "mangafox" {
title = html.UnescapeString(title) // one more time - mangafox double escape sometimes -.-
}
tmpDate = line[strings.Index(line, "<pubDate>")+9 : strings.Index(line, "</pubDate>")]
date, err := time.Parse("Mon, 2 Jan 2006 15:04:05 -0700", tmpDate)
if err != nil {
logger.Error(err.Error())
return nil, errors.New("parseRSS failed to parse time : " + tmpDate)
}
entries[strings.ToLower(title)] = MangaEntry{
Title: title,
Link: line[strings.Index(line, "<link>")+6 : strings.Index(line, "</link>")],
Date: date.Unix(),
Desc: line[strings.Index(line, "<description>")+13 : strings.Index(line, "</description>")],
}
}
return entries, nil
}
示例9: DisplayQuestionCard
// Sends a message show the players the question card.
func (bot *CAHBot) DisplayQuestionCard(GameID string, AddCardsToPlayersHands bool) {
log.Printf("Getting question card index for game with id %v", GameID)
tx, err := bot.db_conn.Begin()
defer tx.Rollback()
if err != nil {
log.Printf("ERROR: %v", err)
return
}
var index int
err = tx.QueryRow("SELECT get_question_card($1)", GameID).Scan(&index)
if err != nil {
log.Printf("ERROR: %v", err)
return
}
log.Printf("The current question cards for game with id %v has index %v.", GameID, index)
if AddCardsToPlayersHands && bot.AllQuestionCards[index].NumAnswers > 1 {
_, err = tx.Exec("SELECT add_cards_to_all_in_game($1, $2)", GameID, bot.AllQuestionCards[index].NumAnswers-1)
if err != nil {
log.Printf("ERROR: %v", err)
return
}
}
tx.Commit()
log.Printf("Sending question card to game with ID %v...", GameID)
var message string = "Here is the question card:\n\n"
message += strings.Replace(html.UnescapeString(bot.AllQuestionCards[index].Text), "\\\"", "", -1)
bot.SendMessageToGame(GameID, html.UnescapeString(message))
}
示例10: FormattedExcerpt
func (presenter EntryPresenter) FormattedExcerpt() template.HTML {
unescaped := html.UnescapeString(presenter.Excerpt)
p := bluemonday.UGCPolicy()
sanitized := p.Sanitize(unescaped)
unescaped = html.UnescapeString(sanitized)
return template.HTML(unescaped)
}
示例11: ListAnswers
// This method lists the answers for everyone and allows the czar to choose one.
func (bot *CAHBot) ListAnswers(GameID string) {
tx, err := bot.db_conn.Begin()
defer tx.Rollback()
if err != nil {
log.Printf("ERROR: %v", err)
return
}
var cards string
err = tx.QueryRow("SELECT get_answers($1)", GameID).Scan(&cards)
if err != nil {
log.Printf("ERROR: %v", err)
return
}
text := "Here are the submitted answers:\n\n"
cardsKeyboard := make([][]string, 1)
for i, val := range ShuffleAnswers(strings.Split(cards[1:len(cards)-1], "+=+\",")) {
text += strings.Replace(html.UnescapeString(strings.Replace(val[1:len(val)-1], "+=+", "", -1)), "\\\"", "", -1) + "\n"
cardsKeyboard[i] = make([]string, 1)
cardsKeyboard[i][0] = strings.Replace(html.UnescapeString(strings.Replace(val[1:len(val)-1], "+=+", "", -1)), "\\\"", "", -1)
}
log.Printf("Showing everyone the answers submitted for game %v.", GameID)
bot.SendMessageToGame(GameID, text)
var czarID int
err = tx.QueryRow("SELECT czar_id($1, $2)", GameID, "czarbest").Scan(&czarID)
if err != nil {
log.Printf("ERROR: %v", err)
return
}
tx.Commit()
log.Printf("Asking the czar, %v, to pick an answer for game with id %v.", czarID, GameID)
message := tgbotapi.NewMessage(czarID, "Czar, please choose the best answer.")
message.ReplyMarkup = tgbotapi.ReplyKeyboardMarkup{cardsKeyboard, true, true, false}
bot.SendMessage(message)
}
示例12: Last
func Last(user string) (string, error) {
brl := "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&limit=1&api_key=37c444dd2fb14904cca0bce2999e4a81&user="
url := brl + user
r, x := http.Get(url)
if x != nil {
return "", nil
}
defer r.Body.Close()
b, x := ioutil.ReadAll(r.Body)
if x != nil {
return "", nil
}
if b == nil {
return "", nil
}
buf := string(b)
re := regexp.MustCompile("<name>.*?</name>")
title := re.FindString(buf)
re = regexp.MustCompile("<artist.*?\">.*?</artist>")
artist := re.FindString(buf)
re = regexp.MustCompile("<.*?>")
artist = re.ReplaceAllLiteralString(artist, "")
artist = html.UnescapeString(artist)
title = re.ReplaceAllLiteralString(title, "")
title = html.UnescapeString(title)
if title != "" && artist != "" {
return (artist + " - " + title), nil
}
return "", nil
}
示例13: notify
func (m *Module) notify(client *irc.Client, post post) {
ftitle := html.UnescapeString(post.Feed.Title)
for _, ch := range client.Channels {
ititle := html.UnescapeString(post.Item.Title)
client.Write("NOTICE %s :%s -- %s new entry %s: %s",
ch, strings.ToUpper(m.Name()), ftitle, ititle, post.Item.Link)
}
}
示例14: ToString
func (t *Text) ToString() string {
switch t.Type {
case "text":
return html.UnescapeString(t.Body)
case "html":
return html.UnescapeString(sanitizer.StripTags(t.Body))
}
return t.Body
}
示例15: MergeAndSendEmail
// MergeAndSendEmail creates both parts of an email from database stored
// templates and then merges the metadata and sends them.
func MergeAndSendEmail(
siteID int64,
from string,
to string,
subjectTemplate *template.Template,
textTemplate *template.Template,
htmlTemplate *template.Template,
data interface{},
) (int, error) {
// If we are not prod environment we really never want to send emails
// by accident as we may be spamming people if the database hasn't been
// sanitised (which it shoud). This is by whitelist, if this isn't the
// production environment then only @microcosm.cc recipients will
// get the email.
//
// If you need to test emails to specific external email hosts then you
// will need to consciously do so by doing so outside of this code
if conf.ConfigStrings[conf.Environment] != `prod` &&
!strings.Contains(to, "@microcosm.cc") {
glog.Infof("dev environment, skipping email to %s", to)
return http.StatusOK, nil
}
var email = EmailType{}
email.From = from
email.To = to
var emailSubject bytes.Buffer
err := subjectTemplate.Execute(&emailSubject, data)
if err != nil {
glog.Errorf("%s %+v", "subjectTemplate.Execute()", err)
return http.StatusInternalServerError, err
}
email.Subject = html.UnescapeString(emailSubject.String())
var emailText bytes.Buffer
err = textTemplate.Execute(&emailText, data)
if err != nil {
glog.Errorf("%s %+v", "textTemplate.Execute()", err)
return http.StatusInternalServerError, err
}
email.BodyText = html.UnescapeString(emailText.String())
var emailHTML bytes.Buffer
err = htmlTemplate.Execute(&emailHTML, data)
if err != nil {
glog.Errorf("%s %+v", "htmlTemplate.Execute()", err)
return http.StatusInternalServerError, err
}
email.BodyHTML = emailHTML.String()
return email.Send(siteID)
}