emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 132/255: moving char-to-num and num-to-char to util


From: Eric Schulte
Subject: [elpa] 132/255: moving char-to-num and num-to-char to util
Date: Sun, 16 Mar 2014 01:02:34 +0000

eschulte pushed a commit to branch go
in repository elpa.

commit 848ea6d1e1dc481f6186b1f505bc21649d3a5bbf
Author: Eric Schulte <address@hidden>
Date:   Thu May 31 23:46:29 2012 -0600

    moving char-to-num and num-to-char to util
    
    these will later need to be renamed
---
 back-ends/gtp.el    |   22 ++--------------------
 back-ends/sgf2el.el |   17 ++++++++---------
 go-util.el          |   18 ++++++++++++++++++
 3 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/back-ends/gtp.el b/back-ends/gtp.el
index 42566f4..425107c 100644
--- a/back-ends/gtp.el
+++ b/back-ends/gtp.el
@@ -40,29 +40,11 @@
     (:W "white")
     (t (error "gtp: unknown turn %S" turn))))
 
-(defun gtp-char-to-num (char)
-  (flet ((err () (error "gtp: invalid char %s" char)))
-    (cond
-     ((< char ?A)  (err))
-     ((< char ?I)  (- char ?A))
-     ((<= char ?T) (1- (- char ?A)))
-     ((< char ?a)  (err))
-     ((< char ?i)  (- char ?a))
-     ((<= char ?t) (1- (- char ?a)))
-     (t (err)))))
-
-(defun gtp-num-to-char (num)
-  (flet ((err () (error "gtp: invalid num %s" num)))
-    (cond
-     ((< num 1) (err))
-     ((< num 9) (+ ?A (1- num)))
-     (t         (+ ?A num)))))
-
 (defun go-pos-to-gtp (pos)
-  (format "%c%d" (gtp-num-to-char (1+ (car pos))) (1+ (cdr pos))))
+  (format "%c%d" (num-to-char (1+ (car pos))) (1+ (cdr pos))))
 
 (defun gtp-to-pos (color gtp)
-  (cons color (cons :pos (cons (gtp-char-to-num (aref gtp 0))
+  (cons color (cons :pos (cons (char-to-num (aref gtp 0))
                                (1- (read (substring gtp 1)))))))
 
 (defun go-to-gtp-command (element)
diff --git a/back-ends/sgf2el.el b/back-ends/sgf2el.el
index b18bd0f..a4fc122 100644
--- a/back-ends/sgf2el.el
+++ b/back-ends/sgf2el.el
@@ -149,16 +149,15 @@
                       (car date-args)))))
 (add-to-list 'sgf2el-special-properties (cons :DT #'process-date))
 
-(defun char-to-num (char)
-  (cond
-   ((or (< char ?A) (< ?z char))
-    (error "sgf: invalid char %s" char))
-   ((< char ?a) (+ 26 (- char ?A)))
-   (t           (- char ?a))))
-
 (defun process-position (position-string)
-  (cons (char-to-num (aref position-string 0))
-        (char-to-num (aref position-string 1))))
+  (flet ((char-to-num (char)
+                      (cond
+                       ((or (< char ?A) (< ?z char))
+                        (error "sgf: invalid char %s" char))
+                       ((< char ?a) (+ 26 (- char ?A)))
+                       (t           (- char ?a)))))
+    (cons (char-to-num (aref position-string 0))
+          (char-to-num (aref position-string 1)))))
 
 (defun process-move (move-args)
   (list (cons :pos (process-position (car move-args)))))
diff --git a/go-util.el b/go-util.el
index deb5b6a..d248d55 100644
--- a/go-util.el
+++ b/go-util.el
@@ -72,4 +72,22 @@
 
 (defun ear-muffs (str) (concat "*" str "*"))
 
+(defun char-to-num (char)
+  (flet ((err () (error "gtp: invalid char %s" char)))
+    (cond
+     ((< char ?A)  (err))
+     ((< char ?I)  (- char ?A))
+     ((<= char ?T) (1- (- char ?A)))
+     ((< char ?a)  (err))
+     ((< char ?i)  (- char ?a))
+     ((<= char ?t) (1- (- char ?a)))
+     (t (err)))))
+
+(defun num-to-char (num)
+  (flet ((err () (error "gtp: invalid num %s" num)))
+    (cond
+     ((< num 1) (err))
+     ((< num 9) (+ ?A (1- num)))
+     (t         (+ ?A num)))))
+
 (provide 'go-util)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]