/[cmucl]/src/code/string.lisp
ViewVC logotype

Diff of /src/code/string.lisp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12.30.15 by rtoy, Mon May 18 13:38:11 2009 UTC revision 1.12.30.16 by rtoy, Tue May 19 20:24:19 2009 UTC
# Line 70  Line 70 
70               (lo (logior (ldb (byte 10 0) tmp) #xDC00)))               (lo (logior (ldb (byte 10 0) tmp) #xDC00)))
71          (values (code-char hi) (code-char lo)))))          (values (code-char hi) (code-char lo)))))
72    
73    (defun utf16-string-p (string)
74      "Check if String is a valid UTF-16 string.  If the string is valid,
75      T is returned.  If the string is not valid, NIL is returned, and the
76      second value is the index into the string of the invalid character."
77      (do ((len (length string))
78           (index 0 (1+ index)))
79          ((>= index len)
80           t)
81        (multiple-value-bind (codepoint wide)
82            (codepoint string index)
83          ;; We stepping through the string in order.  If there are any
84          ;; surrogates, we must reach the lead surrogate first, which
85          ;; means WIDE is +1.  If we get any surrogate codepoint that
86          ;; is in the surrogate range, we have an invalid string.
87          (when (or (eq wide -1)
88                    (<= #xD800 codepoint #xDFFF))
89            (return-from utf16-string-p (values nil index)))
90          (when wide (incf index)))))
91    
92  (defun string (X)  (defun string (X)
93    "Coerces X into a string.  If X is a string, X is returned.  If X is a    "Coerces X into a string.  If X is a string, X is returned.  If X is a

Legend:
Removed from v.1.12.30.15  
changed lines
  Added in v.1.12.30.16

  ViewVC Help
Powered by ViewVC 1.1.5