/
lj-util.el
66 lines (49 loc) · 1.86 KB
/
lj-util.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;;; lj-util.el --- misc elisp utilities for ljupdate
;; Copyright (C) 2002, 2003, 2004, 2005 Edward O'Connor <ted@oconnor.cx>
;; Author: Edward O'Connor <ted@oconnor.cx>
;; Keywords: convenience
;; This file is part of ljupdate, a LiveJournal client for Emacs.
;; ljupdate 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 2, or
;; {at your option} any later version.
;; ljupdate 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 GNU Emacs; see the file COPYING, or type `C-h C-c'. If
;; not, write to the Free Software Foundation at this address:
;; Free Software Foundation
;; 51 Franklin Street, Fifth Floor
;; Boston, MA 02110-1301
;; USA
;;; Commentary:
;;
;;; History:
;;
;;; Code:
(require 'md5)
(require 'lj-compat)
(defun lj-md5 (string)
"MD5s STRING and downcases the result.
The LiveJournal server code doesn't accept upcased MD5sums. Case
sensitivity is dumb."
(downcase (md5 string nil nil lj-coding-system)))
(defun lj-number (thing)
"Convert THING to a number, if necessary."
(cond ((numberp thing) thing)
((stringp thing) (string-to-number thing))
(t 0)))
(defun lj-exp2 (n)
"Return a string representation of 2^N for 0 <= N <= 30."
(cond ((or (< n 0) (> n 30))
(signal 'args-out-of-range n))
((< n 27) (number-to-string (lsh 1 n)))
;; Emacs integers aren't 32-bit quantities, so we cheat.
((= n 27) "134217728")
((= n 28) "268435456")
((= n 29) "536870912")
((= n 30) "1073741824")))
(provide 'lj-util)
;;; lj-util.el ends here