;;; idn.el --- Recommended Identifier Profiles for IDN ;; ;; Author: Lennart Borgman (lennart O borgman A gmail O com) ;; Created: 2010-03-24 Wed ;; Version: 0.1 ;; Last-Updated: 2010-03-24 Wed ;; URL: ;; Keywords: ;; Compatibility: ;; ;; Features that might be required by this library: ;; ;; None ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Commentary: ;; ;; Functions for handling IDN chars defined by ;; `http://www.unicode.org/reports/tr39/'. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Change log: ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 3, or ;; (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth ;; Floor, Boston, MA 02110-1301, USA. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Code: (defvar uts39-datadir "c:/uts39/data/") (defun idn-init (bv) (let* ((idnchars-file (expand-file-name "idnchars.txt" uts39-datadir)) (idnchars-old (find-buffer-visiting idnchars-file)) (idnchars-buf (or idnchars-old (if (not (file-exists-p idnchars-file)) (message "Can't find file %S" idnchars-file) (find-file-noselect idnchars-file)))) here (range-patt (rx bol (group (repeat 4 (any xdigit))) (optional ".." (group (repeat 4 (any xdigit))))))) (when idnchars-buf (with-current-buffer idnchars-buf (setq here (point)) (save-restriction (widen) (goto-char (point-min)) (while (re-search-forward range-patt nil t) (let* ((str-beg (match-string 0)) (str-end (match-string 1)) (beg (string-to-number str-beg 16)) (end (or (when str-end (string-to-number str-end 16)) beg))) (dotimes (ii (1+ (- end beg))) (aset bv (+ ii beg) t))))) (goto-char here)) (unless idnchars-old (kill-buffer idnchars-buf)) t))) (defconst idn-chars "Boolean vector with recommended IDN chars. See URL `http://www.unicode.org/reports/tr39/'. Data is initialized from the file idnchars.txt in the directory `uts39-datadir'. This file is fetched from the above location." (let ((bv (make-bool-vector (1- (* 256 256)) nil))) (when (idn-init bv) ;; (string-to-number "002D" 16) ;; Make a quick sanity check: (unless (and (not (aref idn-chars 44)) (aref idn-chars 45)) (message "idn-chars: Bad idn data in file idnchars.txt")) bv))) (provide 'idn) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; idn.el ends here