Skip to content

Instantly share code, notes, and snippets.

@sgrove
Created November 15, 2012 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgrove/a38106fe15a521288708 to your computer and use it in GitHub Desktop.
Save sgrove/a38106fe15a521288708 to your computer and use it in GitHub Desktop.
; Clojurescript, detect if a string contains a double-byte char. As soon as we find one, we should immediately return true
(defn double-byte-str? [string]
(.log js/console (str "Checking: " string))
(cond (empty? string) nil
(> (.charCodeAt string 0) 255) true
:else (recur (rest string))))
; Javascript version of the function
String.prototype.isDoubleByte = function() {
for (var i = 0, n = this.length; i < n; i++) {
if (this.charCodeAt( i ) > 255) { return true; }
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment