Note that there are some explanatory texts on larger screens.

plurals
  1. POgetting exactly equal clojure/clojurescript strings in UTF-8
    primarykey
    data
    text
    <p>I have one clj file:</p> <pre><code>;; stringparity.clj ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (ns stringparity) (defn get-java-string [input] (.getBytes input "UTF-8")) </code></pre> <p>And one cljs file:</p> <pre><code>;;; stringparity.cljs ;;;;;;;;;;;;;;;;;;;;;;;;;;;; (ns stringparity (:import goog.crypt)) (defn get-js-string [input] (goog.crypt.stringToUtf8ByteArray input)) </code></pre> <p>The following code is not executable, as <code>get-js-string</code> only works in javascript, and <code>get-java-string</code> works in java; I am just pretending that you could run them in the same machine to illustrate what is going wrong. Both functions work fine when using "simple" strings, but fail when using "complex" strings like <code>""</code>. I want to be able to hash any string on either clojure or clojurescript and have their hash be the same. In order to do that, I need to be able to convert a javascript or a java string to its equivalent byte array. It appears that I am using UTF-8 for both the clojure and clojurescript side of things, but they do not generate the same byte arrays (they aren't even the same length). How do I generate the exact same byte arrays for any two equivalent strings in both clojure and clojurescript.</p> <pre><code>(= (seq (get-js-string "hello")) [104, 101, 108, 108, 111] (seq (get-java-string "hello") [104, 101, 108, 108, 111])) (= (seq (get-js-string "")) ;; when in cljs, get-js-string evaluates to the following [237 160 180 237 188 134] (seq (get-java-string "")) ;; when in clj, get-java-string evaluates to the following [-16 -99 -116 -122]) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload