Example #1
0
ScreenBuffer.prototype.fill = function fill( options )
{
	//this.buffer.fill( 0 ) ; return this ;
	
	var i , attr , char , length ,
		clearBuffer = ScreenBuffer.CLEAR_BUFFER ,
		buffer = this.buffer ;
	
	if ( options && typeof options === 'object' ) 
	{
		clearBuffer = new Buffer( ScreenBuffer.ITEM_SIZE ) ;
		
		// Write the attributes
		attr = options.attr !== undefined ? options.attr : ScreenBuffer.DEFAULT_ATTR ;
		if ( attr && typeof attr === 'object' ) { attr = ScreenBuffer.object2attr( attr ) ; }
		if ( typeof attr !== 'number' ) { attr = ScreenBuffer.DEFAULT_ATTR ; }
		clearBuffer.writeUInt32BE( attr , 0 ) ;
		
		// Write the character
		char = options.char && typeof options.char === 'string' ? options.char : ' ' ;
		char = punycode.ucs2.encode( [ punycode.ucs2.decode( ScreenBuffer.stripControlChars( char ) )[ 0 ] ] ) ;
		clearBuffer.write( char , ScreenBuffer.ATTR_SIZE , ScreenBuffer.CHAR_SIZE ) ;
		
		// This option is used when we want to clear a Buffer instance, not a ScreenBuffer instance
		if ( options.buffer ) { buffer = options.buffer ; }
	}
	
	// It is always an integer
	length = buffer.length / ScreenBuffer.ITEM_SIZE ;
	
	for ( i = 0 ; i < length ; i ++ )
	{
		clearBuffer.copy( buffer , i * ScreenBuffer.ITEM_SIZE ) ;
	}
} ;
Example #2
0
unicode.toFullWidth = function toFullWidth( str )
{
	return punycode.ucs2.encode( 
		punycode.ucs2.decode( str ).map( function( code ) {
			if ( code >= 33 && code <= 126 ) { return 0xff00 + code - 0x20 ; }
			else { return code ; }
		} )
	) ;
} ;
Example #3
0
    replacements.forEach(function(replacement) {
        // The emote command
        var name = punycode.ucs2.encode(message.slice(replacement.first, replacement.last+1));

        // Unshift the end of the message (that doesn't contain the emote)
        tokenizedMessage.unshift(punycode.ucs2.encode(message.slice(replacement.last+1)));

        // Unshift the emote HTML (but not as a string to allow us to process links and escape html still)
        tokenizedMessage.unshift([ emoticon(replacement.id, name) ]);

        // Splice the unparsed piece of the message
        message = message.slice(0, replacement.first);
    });
Example #4
0
 Object.keys(tweetEmojis).forEach(function(key) {
   if (myEmojis.hasOwnProperty( punycode.ucs2.encode(['0x'+key]) )) {
     //increment counter on appropriate emoji in myEmojis
     myEmojis[ punycode.ucs2.encode(['0x'+key]) ].counter++;
   } else {
     //add new emoji info and set counter to 1
     myEmojis[ punycode.ucs2.encode(['0x'+key]) ] = {
       name: tweetEmojis[key].name,
       shortName: tweetEmojis[key].shortName,
       counter: 1
     };
   }
 });
module.exports.setThePassword = function (url, password) {
  url.password = "";
  const decoded = punycode.ucs2.decode(password);
  for (let i = 0; i < decoded.length; ++i) {
    url.password += percentEncodeChar(decoded[i], isUserinfoPercentEncode);
  }
};
Example #6
0
exports.handleSurrogatePairs = function(message, emotes) {
    // Entire message decoded to array of char codes, combines
    // surrogate pairs to a single index
    var decoded = punycode.ucs2.decode(message);

    var surrogates = {};
    var i;
    for (i = 0; i < decoded.length; i++) {
        // Not surrogate
        if (decoded[i] <= 0xFFFF) continue;

        surrogates[i] = true;
    }

    // We can loop through all emote ids and all indexes that id
    // appears in the message, offsetting the indexes +1 for each
    // surrogate pair occurring before the index
    for (var id in emotes) {
        if (!Object.hasOwnProperty.call(emotes, id)) continue;

        var emote = emotes[id];
        for (i = emote.length - 1; i >= 0; i--) {
            for (var j = 0; j < emote[i].length; j++) {
                emote[i][j] = surrogateOffset(surrogates, emote[i][j]);
            }
        }
    }

    return emotes;
};
  it('should work with high code points', done => {
    const svgIconStream = fs.createReadStream(
      path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg')
    );
    const svgFontStream = new SVGIcons2SVGFontStream({ round: 1e3 });
    let content = '';
    const decoder = new StringDecoder('utf8');

    svgIconStream.metadata = {
      name: 'account',
      unicode: [ucs2.encode([0x1f63a])],
    };

    svgFontStream.on('data', chunk => {
      content += decoder.write(chunk);
    });

    svgFontStream.on('finish', () => {
      assert.equal(
        content,
        fs.readFileSync(
          path.join(__dirname, 'expected', 'cleanicons-high.svg'),
          { encoding: 'utf8' }
        )
      );
      done();
    });
    svgFontStream.write(svgIconStream);
    svgFontStream.end();
  });
function URLStateMachine(input, base, encodingOverride, url, stateOverride) {
  this.pointer = 0;
  this.input = input;
  this.base = base || null;
  this.encodingOverride = encodingOverride || "utf-8";
  this.stateOverride = stateOverride;
  this.url = url;
  this.failure = false;
  this.parseError = false;

  if (!this.url) {
    this.url = {
      scheme: "",
      username: "",
      password: "",
      host: null,
      port: null,
      path: [],
      query: null,
      fragment: null,

      cannotBeABaseURL: false
    };

    const res = trimControlChars(this.input);
    if (res !== this.input) {
      this.parseError = true;
    }
    this.input = res;
  }

  const res = trimTabAndNewline(this.input);
  if (res !== this.input) {
    this.parseError = true;
  }
  this.input = res;

  this.state = stateOverride || "scheme start";

  this.buffer = "";
  this.atFlag = false;
  this.arrFlag = false;
  this.passwordTokenSeenFlag = false;

  this.input = punycode.ucs2.decode(this.input);

  for (; this.pointer <= this.input.length; ++this.pointer) {
    const c = this.input[this.pointer];
    const cStr = isNaN(c) ? undefined : String.fromCodePoint(c);

    // exec state machine
    const ret = this["parse " + this.state](c, cStr);
    if (!ret) {
      break; // terminate algorithm
    } else if (ret === failure) {
      this.failure = true;
      break;
    }
  }
}
Example #9
0
File: codes.js Project: Tollere/WAF
test('astral num', function (t){
  var a = punycode.ucs2.encode([0x1d306]);
  var b = '&#x1d306;';
  t.equal(ent.decode(b), a);
  t.equal(ent.decode(b + b), a + a);
  t.end();
});
module.exports.setTheUsername = function (url, username) {
  url.username = "";
  const decoded = punycode.ucs2.decode(username);
  for (let i = 0; i < decoded.length; ++i) {
    url.username += percentEncodeChar(decoded[i], isUserinfoPercentEncode);
  }
};
Example #11
0
NodeParser.prototype.paintText = function(container) {
    container.applyTextTransform();
    var characters = punycode.ucs2.decode(container.node.data);
    var textList = (!this.options.letterRendering || noLetterSpacing(container)) && !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character) {
        return punycode.ucs2.encode([character]);
    });

    var weight = container.parent.fontWeight();
    var size = container.parent.css('fontSize');
    var family = container.parent.css('fontFamily');
    var shadows = container.parent.parseTextShadows();

    this.renderer.font(container.parent.color('color'), container.parent.css('fontStyle'), container.parent.css('fontVariant'), weight, size, family);
    if (shadows.length) {
        // TODO: support multiple text shadows
        this.renderer.fontShadow(shadows[0].color, shadows[0].offsetX, shadows[0].offsetY, shadows[0].blur);
    } else {
        this.renderer.clearShadow();
    }

    this.renderer.clip(container.parent.clip, function() {
        textList.map(this.parseTextBounds(container), this).forEach(function(bounds, index) {
            if (bounds) {
                this.renderer.text(textList[index], bounds.left, bounds.bottom);
                this.renderTextDecoration(container.parent, bounds, this.fontMetrics.getMetrics(family, size));
            }
        }, this);
    }, this);
};
Example #12
0
   glyph.unicode.forEach(function(unicode, i) {
     _this.push('\
 <glyph glyph-name="' + glyph.name + (0 === i ? '' : '-' + i) + '"\n\
   unicode="' + ucs2.decode(unicode).map(function(point) {
     return '&#x' + point.toString(16).toUpperCase() + ';';
   }).join('') + '"\n\
   horiz-adv-x="' + glyph.width + '" d="' + d + '" />\n');
   });
Example #13
0
var emoticonize = exports.emoticonize = function(message, emotes) {
    if(!emotes) return [message];

    var tokenizedMessage = [];

    var emotesList = Object.keys(emotes);

    var replacements = [];

    emotesList.forEach(function(id) {
        var emote = emotes[id];

        for(var i=emote.length-1; i>=0; i--) {
            replacements.push({ id: id, first: emote[i][0], last: emote[i][1] });
        }
    });

    replacements.sort(function(a, b) {
        return b.first - a.first;
    });

    // Tokenizes each character into an array
    // punycode deals with unicode symbols on surrogate pairs
    // punycode is used in the replacements loop below as well
    message = punycode.ucs2.decode(message);

    replacements.forEach(function(replacement) {
        // The emote command
        var name = punycode.ucs2.encode(message.slice(replacement.first, replacement.last+1));

        // Unshift the end of the message (that doesn't contain the emote)
        tokenizedMessage.unshift(punycode.ucs2.encode(message.slice(replacement.last+1)));

        // Unshift the emote HTML (but not as a string to allow us to process links and escape html still)
        tokenizedMessage.unshift([ emoticon(replacement.id, name) ]);

        // Splice the unparsed piece of the message
        message = message.slice(0, replacement.first);
    });

    // Unshift the remaining part of the message (that contains no emotes)
    tokenizedMessage.unshift(punycode.ucs2.encode(message));

    return tokenizedMessage;
};
Example #14
0
module.exports.setThePassword = function (url, password) {
  if (password === "") {
    url.password = null;
  } else {
    url.password = "";
    const decoded = punycode.ucs2.decode(password);
    for (let i = 0; i < decoded.length; ++i) {
      url.password += encodeChar(decoded[i], isUserInfoEncode);
    }
  }
};
Example #15
0
    return str.replace(/&(#?[^;\W]+;?)/g, function (_, match) {
        var m;
        if (m = /^#(\d+);?$/.exec(match)) {
            return punycode.ucs2.encode([ parseInt(m[1], 10) ]);
        } else if (m = /^#[Xx]([A-Fa-f0-9]+);?/.exec(match)) {
            return punycode.ucs2.encode([ parseInt(m[1], 16) ]);
        } else {
            // named entity
            var hasSemi = /;$/.test(match);
            var withoutSemi = hasSemi ? match.replace(/;$/, '') : match;
            var target = entities[withoutSemi] || (hasSemi && entities[match]);

            if (typeof target === 'number') {
                return punycode.ucs2.encode([ target ]);
            } else if (typeof target === 'string') {
                return target;
            } else {
                return '&' + match;
            }
        }
    });
function parseOpaqueHost(input) {
  if (containsForbiddenHostCodePointExcludingPercent(input)) {
    return failure;
  }

  let output = "";
  const decoded = punycode.ucs2.decode(input);
  for (let i = 0; i < decoded.length; ++i) {
    output += percentEncodeChar(decoded[i], isC0ControlPercentEncode);
  }
  return output;
}
Example #17
0
function getWords(characters) {
    var words = [], i = 0, onWordBoundary = false, word;
    while(characters.length) {
        if (isWordBoundary(characters[i]) === onWordBoundary) {
            word = characters.splice(0, i);
            if (word.length) {
                words.push(punycode.ucs2.encode(word));
            }
            onWordBoundary =! onWordBoundary;
            i = 0;
        } else {
            i++;
        }

        if (i >= characters.length) {
            word = characters.splice(0, i);
            if (word.length) {
                words.push(punycode.ucs2.encode(word));
            }
        }
    }
    return words;
}
Example #18
0
 .replace(/&([^;\W]+;?)/g, function (m, e) {
     var ee = e.replace(/;$/, '');
     var target = entities[e]
         || (e.match(/;$/) && entities[ee])
     ;
     
     if (typeof target === 'number') {
         return punycode.ucs2.encode([target]);
     }
     else if (typeof target === 'string') {
         return target;
     }
     else {
         return m;
     }
 })
Example #19
0
 /**
  * Converts raw block to object with nested style objects,
  * while it returns an object not a string
  * the idea is still mostly same as backdraft.js (https://github.com/evanc/backdraft-js)
  */
 parse(block) {
   const { text, inlineStyleRanges: ranges, entityRanges, decoratorRanges = [] } = block;
   // Some unicode charactes actualy have length of more than 1
   // this creates an array of code points using es6 string iterator
   this.textArray = punycode.ucs2.decode(text);
   this.ranges = ranges;
   this.iterator = 0;
   // get all the relevant indexes for whole block
   this.relevantIndexes = getRelevantIndexes(text, ranges, entityRanges, decoratorRanges);
   // create entity or empty nodes to place the inline styles in
   const nodes = createNodes(entityRanges, decoratorRanges, this.textArray, block);
   const parsedNodes = nodes.map(node =>
     this.nodeIterator(node, node.start, node.end)
   );
   return new ContentNode({ block, content: parsedNodes });
 }
Example #20
0
function URLStateMachine(input, base, encoding_override, url, state_override) {
  this.pointer = 0;
  this.input = input;
  this.base = base || null;
  this.encoding_override = encoding_override || "utf-8";
  this.state_override = state_override;
  this.url = url;

  if (!this.url) {
    this.url = {
      scheme: "",
      username: "",
      password: null,
      host: null,
      port: "",
      path: [],
      query: null,
      fragment: null,

      nonRelative: false
    };

    this.input = trimControlChars(this.input);
  }

  this.state = state_override || STATES.SCHEME_START;

  this.buffer = "";
  this.at_flag = false;
  this.arr_flag = false;
  this.parse_error = false;

  this.input = punycode.ucs2.decode(this.input);

  for (; this.pointer <= this.input.length; ++this.pointer) {
    const c = this.input[this.pointer];
    const c_str = isNaN(c) ? undefined : String.fromCodePoint(c);

    // exec state machine
    if (this["parse" + this.state](c, c_str) === false) {
      break; // terminate algorithm
    }
  }
}
Example #21
0
    update: function (text) {
        var self = this;

        var events = [];
        if (text !== undefined) {
            if (text.normalize) {
                text = text.normalize('NFC');
            }

            var newBuffer = punycode.ucs2.decode(text);

            events = generateEvents(this.buffer, newBuffer.slice());

            this.buffer = newBuffer;
            this.trigger('change:buffer');
        }

        if (this.changedBetweenResets && Date.now() - this.lastReset > this.resetInterval) {
            this.queue = [];
            this.queue.push({
                type: 'insert',
                text:  this.text
            });
            this.isReset = true;
            this.lastTime = Date.now();
            this.lastReset = Date.now();
            this.changedBetweenResets = false;
        } else if (events.length) {
            var wait = Date.now() - (this.lastTime || Date.now());
            if (wait > 0) {
                this.queue.push({
                    type: 'wait',
                    num: wait * this.replaySpeedScale
                });
            }
            events.forEach(function (event) {
                self.queue.push(event);
            });
            this.lastTime = Date.now();
            this.changedBetweenResets = true;
        }
    },
Example #22
0
    insert: function (text, pos) {
        if (pos === undefined) {
            pos = this.buffer.length;
        }

        if (text.normalize) {
            text = text.normalize('NFC');
        }

        var args = punycode.ucs2.decode(text);
        var textLen = args.length;

        args.unshift(0);
        args.unshift(pos);

        this.buffer.splice.apply(this.buffer, args);

        this.cursor = pos + textLen;

        this.trigger('change:buffer');
    },
Example #23
0
 .replace(/&#[xX]([A-Fa-f0-9]+);?/g, function (_, hex) {
     return punycode.ucs2.encode([parseInt(hex, 16)]);
 })
Example #24
0
 .replace(/&#(\d+);?/g, function (_, code) {
     return punycode.ucs2.encode([code]);
 })
Example #25
0
/* Return the integer numbers for each character in str.
 * > punycode.ucs2.decode('abc')
     [ 97, 98, 99 ]
 */
function strToInts(str){
    return punycode.ucs2.decode(str);
}
Example #26
0
      test.decoded
  )
};

tests.forEach((testCase) => {
  Object.keys(testBattery).forEach((key) => {
    try {
      testBattery[key](testCase);
    } catch (error) {
      handleError(error, key);
    }
  });
});

// BMP code point
assert.strictEqual(punycode.ucs2.encode([0x61]), 'a');
// supplementary code point (surrogate pair)
assert.strictEqual(punycode.ucs2.encode([0x1D306]), '\uD834\uDF06');
// high surrogate
assert.strictEqual(punycode.ucs2.encode([0xD800]), '\uD800');
// high surrogate followed by non-surrogates
assert.strictEqual(punycode.ucs2.encode([0xD800, 0x61, 0x62]), '\uD800ab');
// low surrogate
assert.strictEqual(punycode.ucs2.encode([0xDC00]), '\uDC00');
// low surrogate followed by non-surrogates
assert.strictEqual(punycode.ucs2.encode([0xDC00, 0x61, 0x62]), '\uDC00ab');

assert.strictEqual(errors, 0);

// test map domain
assert.strictEqual(punycode.toASCII('Bücher@日本語.com'),
Example #27
0
 var textList = (!this.options.letterRendering || noLetterSpacing(container)) && !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character) {
     return punycode.ucs2.encode([character]);
 });
Example #28
0
function filterResults(ch, block) {
  var charCodes,
    decCode,
    result,
    re;

  function testRow(row) {
    return (
      re.test(row.name) ||
      re.test(row.altName) ||
      row.htmlEntity === ch ||
      row.hexCode === ch ||
      row.code === decCode
    );
  }

  block = (block || '');
  decCode = parseInt(ch, 10) || -1;

  // Convert JavaScript string (UCS-2 encoding) into an array of numbers
  // representing Unicode code points, because String.charCodeAt() only works on
  // single-byte characters.
  charCodes = ucs2.decode(ch);

  // There are four potential search types:
  // - literal character
  // - name but no block ID
  // - name and block ID
  // - block ID but no name

  // Simplest case: match single character.
  if (charCodes.length === 1) {
    chars.some(function (row) {
      if (row.code === charCodes[0]) {
        result = [row];
        return true;
      }
    });
    return result;
  }

  ch = (ch || '').toLowerCase();
  re = new RegExp(ch);

  // Find by name, but no block ID
  if (block === '') {
    return chars.filter(testRow);
  }

  // No character given but...
  if (ch === '') {

    // ...WGL4 meta-block given.
    if (block === '-1') {
      return chars.filter(function (row) {
        return row.wgl4;
      });
    }

    // ...real block ID given.
    return chars.filter(function (row) {
      return row.blockId === block;
    });
  }

  // Char name given and...
  if (block === '-1') {
    // ...WGL4 meta-block given.

    return chars.filter(function (row) {
      return testRow(row) && row.wgl4;
    });
  }

  // ...char name and real block given.
  return chars.filter(function (row) {
    return testRow(row) && row.blockId === block;
  });
}
Example #29
0
 fn: function () {
     return punycode.ucs2.encode(this.buffer.slice());
 }
Example #30
0
function countSymbols(str) {
  return punycode.ucs2.decode(str).length;
}