Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This</strong> is along the lines of what I was looking for. It needs better support for the different string functions. As I add to it I will update this answer.</p> <pre><code>function wString(str){ var T = this; //makes 'this' visible in functions T.cp = []; //code point array T.length = 0; //length attribute T.wString = true; // (item.wString) tests for wString object //member functions sortSurrogates = function(s){ //returns array of utf-16 code points var chrs = []; while(s.length){ // loop till we've done the whole string if(/[\uD800-\uDFFF]/.test(s.substr(0,1))){ // test the first character // High surrogate found low surrogate follows chrs.push(s.substr(0,2)); // push the two onto array s = s.substr(2); // clip the two off the string }else{ // else BMP code point chrs.push(s.substr(0,1)); // push one onto array s = s.substr(1); // clip one from string } } // loop return chrs; }; //end member functions //prototype functions T.substr = function(start,len){ if(len){ return T.cp.slice(start,start+len).join(''); }else{ return T.cp.slice(start).join(''); } }; T.substring = function(start,end){ return T.cp.slice(start,end).join(''); }; T.replace = function(target,str){ //allow wStrings as parameters if(str.wString) str = str.cp.join(''); if(target.wString) target = target.cp.join(''); return T.toString().replace(target,str); }; T.equals = function(s){ if(!s.wString){ s = sortSurrogates(s); T.cp = s; }else{ T.cp = s.cp; } T.length = T.cp.length; }; T.toString = function(){return T.cp.join('');}; //end prototype functions T.equals(str) }; </code></pre> <p>Test results:</p> <pre><code>// plain string var x = "0123456789"; alert(x); // 0123456789 alert(x.substr(4,5)) // 45678 alert(x.substring(2,4)) // 23 alert(x.replace("456","x")); // 0123x789 alert(x.length); // 10 // wString object x = new wString(""); alert(x); // alert(x.substr(4,5)) // alert(x.substring(2,4)) // alert(x.replace("","x")); // x alert(x.length); // 10 </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.
    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