Initial CL parser/generator implementation
This commit is contained in:
34
lib/common-utilities.lisp
Normal file
34
lib/common-utilities.lisp
Normal file
@ -0,0 +1,34 @@
|
||||
;;;; PMSF-Lib --- PMSF Common Lisp Utility Library
|
||||
;;;; This is copyrighted software. See documentation for terms.
|
||||
;;;;
|
||||
;;;; common-utilities.lisp --- Common utilities
|
||||
;;;;
|
||||
;;;; $Id$
|
||||
|
||||
(cl:in-package #:pmsf-lib)
|
||||
|
||||
;;;; %File Description:
|
||||
;;;;
|
||||
;;;; This file contains common utilities for all kinds of processing
|
||||
;;;; and formatting.
|
||||
;;;;
|
||||
|
||||
(defun generate-printed-guid (&optional registry-format-p)
|
||||
"Generate a version 4 (PRNG) UUID and return its printed representation."
|
||||
(let ((state (make-random-state t)))
|
||||
(with-output-to-string (stream)
|
||||
(loop with chars = "0123456789abcdef"
|
||||
for index upfrom 0 below 32
|
||||
for value = (random 16 state)
|
||||
for offset = (cond
|
||||
((= index 12) 4)
|
||||
((= index 16) (+ 8 (ldb (byte 2 0) value)))
|
||||
(t value))
|
||||
do
|
||||
(write-char (char chars offset) stream)
|
||||
(when (member index '(7 11 15 20))
|
||||
(write-char #\- stream))
|
||||
initially
|
||||
(when registry-format-p (write-char #\{ stream))
|
||||
finally
|
||||
(when registry-format-p (write-char #\} stream))))))
|
||||
Reference in New Issue
Block a user