comparison lisp/net/newst-backend.el @ 106458:3b1d7962549d

Fixed Bug#5008.
author Ulf Jasper <ulf.jasper@web.de>
date Sun, 06 Dec 2009 18:13:19 +0000
parents 53d1b718f76a
children e341c53bc4af
comparison
equal deleted inserted replaced
106457:c15d1227e860 106458:3b1d7962549d
5 5
6 ;; Author: Ulf Jasper <ulf.jasper@web.de> 6 ;; Author: Ulf Jasper <ulf.jasper@web.de>
7 ;; Filename: newst-backend.el 7 ;; Filename: newst-backend.el
8 ;; URL: http://www.nongnu.org/newsticker 8 ;; URL: http://www.nongnu.org/newsticker
9 ;; Keywords: News, RSS, Atom 9 ;; Keywords: News, RSS, Atom
10 ;; Time-stamp: "4. Dezember 2009, 20:08:17 (ulf)" 10 ;; Time-stamp: "5. Dezember 2009, 13:21:27 (ulf)"
11 11
12 ;; ====================================================================== 12 ;; ======================================================================
13 13
14 ;; This file is part of GNU Emacs. 14 ;; This file is part of GNU Emacs.
15 15
1406 (link (or link "")) 1406 (link (or link ""))
1407 (old-item nil) 1407 (old-item nil)
1408 (position 0) 1408 (position 0)
1409 (something-was-added nil)) 1409 (something-was-added nil))
1410 ;; decode numeric entities 1410 ;; decode numeric entities
1411 (setq title (newsticker--decode-numeric-entities title)) 1411 (setq title (xml-substitute-numeric-entities title))
1412 (setq desc (newsticker--decode-numeric-entities desc)) 1412 (setq desc (xml-substitute-numeric-entities desc))
1413 (setq link (newsticker--decode-numeric-entities link)) 1413 (setq link (xml-substitute-numeric-entities link))
1414 ;; remove whitespace from title, desc, and link 1414 ;; remove whitespace from title, desc, and link
1415 (setq title (newsticker--remove-whitespace title)) 1415 (setq title (newsticker--remove-whitespace title))
1416 (setq desc (newsticker--remove-whitespace desc)) 1416 (setq desc (newsticker--remove-whitespace desc))
1417 (setq link (newsticker--remove-whitespace link)) 1417 (setq link (newsticker--remove-whitespace link))
1418 1418
1460 (setq desc (prin1-to-string desc))) 1460 (setq desc (prin1-to-string desc)))
1461 ;; ignore items with empty title AND empty desc 1461 ;; ignore items with empty title AND empty desc
1462 (when (or (> (length title) 0) 1462 (when (or (> (length title) 0)
1463 (> (length desc) 0)) 1463 (> (length desc) 0))
1464 ;; decode numeric entities 1464 ;; decode numeric entities
1465 (setq title (newsticker--decode-numeric-entities title)) 1465 (setq title (xml-substitute-numeric-entities title))
1466 (when desc 1466 (when desc
1467 (setq desc (newsticker--decode-numeric-entities desc))) 1467 (setq desc (xml-substitute-numeric-entities desc)))
1468 (setq link (newsticker--decode-numeric-entities link)) 1468 (setq link (xml-substitute-numeric-entities link))
1469 ;; remove whitespace from title, desc, and link 1469 ;; remove whitespace from title, desc, and link
1470 (setq title (newsticker--remove-whitespace title)) 1470 (setq title (newsticker--remove-whitespace title))
1471 (setq desc (newsticker--remove-whitespace desc)) 1471 (setq desc (newsticker--remove-whitespace desc))
1472 (setq link (newsticker--remove-whitespace link)) 1472 (setq link (newsticker--remove-whitespace link))
1473 ;; add data to cache 1473 ;; add data to cache
1515 something-was-added)) 1515 something-was-added))
1516 1516
1517 ;; ====================================================================== 1517 ;; ======================================================================
1518 ;;; Misc 1518 ;;; Misc
1519 ;; ====================================================================== 1519 ;; ======================================================================
1520 (defun newsticker--decode-numeric-entities (string)
1521 "Decode SGML numeric entities by their respective utf characters.
1522 This function replaces numeric entities in the input STRING and
1523 returns the modified string. For example \"&#42;\" gets replaced
1524 by \"*\"."
1525 (if (and string (stringp string))
1526 (let ((start 0))
1527 (while (string-match "&#\\([0-9]+\\);" string start)
1528 (condition-case nil
1529 (setq string (replace-match
1530 (string (read (substring string
1531 (match-beginning 1)
1532 (match-end 1))))
1533 nil nil string))
1534 (error nil))
1535 (setq start (1+ (match-beginning 0))))
1536 string)
1537 nil))
1538 1520
1539 (defun newsticker--remove-whitespace (string) 1521 (defun newsticker--remove-whitespace (string)
1540 "Remove leading and trailing whitespace from STRING." 1522 "Remove leading and trailing whitespace from STRING."
1541 ;; we must have ...+ but not ...* in the regexps otherwise xemacs loops 1523 ;; we must have ...+ but not ...* in the regexps otherwise xemacs loops
1542 ;; endlessly... 1524 ;; endlessly...