mirror of
https://github.com/idanoo/GoScrobble
synced 2025-07-01 13:42:20 +00:00
0.2.0 - Mid migration
This commit is contained in:
parent
139e6a915e
commit
7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions
6
web/node_modules/buffer-indexof/.travis.yml
generated
vendored
Normal file
6
web/node_modules/buffer-indexof/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- 4
|
||||
- 6
|
20
web/node_modules/buffer-indexof/LICENSE
generated
vendored
Normal file
20
web/node_modules/buffer-indexof/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Ryan Day
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
37
web/node_modules/buffer-indexof/README.md
generated
vendored
Normal file
37
web/node_modules/buffer-indexof/README.md
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
[](http://travis-ci.org/soldair/node-buffer-indexof)
|
||||
|
||||
|
||||
buffer-indexof
|
||||
===================
|
||||
|
||||
find the index of a buffer in a buffer. should behave like String.indexOf etc.
|
||||
|
||||
```js
|
||||
|
||||
var bindexOf = require('buffer-indexof');
|
||||
|
||||
var newLineBuffer = new Buffer("\n");
|
||||
|
||||
var b = new Buffer("hi\nho\nsilver");
|
||||
|
||||
|
||||
bindexOf(b,newLineBuffer) === 2
|
||||
|
||||
// you can also start from index
|
||||
|
||||
bindexOf(b,newLineBuffer,3) === 5
|
||||
|
||||
// no match === -1
|
||||
|
||||
bindexOf(b,newLineBuffer,6) === -1
|
||||
|
||||
|
||||
```
|
||||
|
||||
CHANGELOG
|
||||
----------
|
||||
|
||||
- 1.0.0
|
||||
- fixed issue finding multibyte needles in haystack. thanks @imulus
|
||||
- 1.0.1
|
||||
- fixed failing to find partial matches as pointed out by @bahaa-aidi in #2
|
58
web/node_modules/buffer-indexof/bm.js
generated
vendored
Normal file
58
web/node_modules/buffer-indexof/bm.js
generated
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
//boyer-moore?
|
||||
module.exports = function bm(buf,search,offset){
|
||||
var m = 0, j = 0
|
||||
var table = []
|
||||
|
||||
var ret = -1;
|
||||
for(var i=offset||0;i<buf.length;++i){
|
||||
console.log('i',i)
|
||||
|
||||
table[i] = [[i,0]]
|
||||
if(buf[i] === search[0]) {
|
||||
for(j = search.length-1;j>0;--j){
|
||||
table[i].push([i+j,j])
|
||||
console.log('j',j)
|
||||
if(buf[i+j] !== search[j]) {
|
||||
|
||||
//i += j
|
||||
j = -1
|
||||
break
|
||||
}
|
||||
}
|
||||
if(j === 0) {
|
||||
ret = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(table)
|
||||
renderTable(table,buf,search)
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
var chalk = require('chalk')
|
||||
function renderTable(table,buf,search){
|
||||
var s = ''
|
||||
|
||||
console.log('-----')
|
||||
console.log('search:',search)
|
||||
console.log('-----')
|
||||
console.log(buf+'')
|
||||
|
||||
table.forEach(function(a){
|
||||
if(!a) return;// console.log('')
|
||||
a.forEach(function(v){
|
||||
if(!v) return;
|
||||
var pad = ''
|
||||
while(pad.length < v[0]){
|
||||
pad += ' '
|
||||
}
|
||||
if(search[v[1]] === buf[v[0]]) console.log(pad+chalk.green(search[v[1]]))
|
||||
else console.log(pad+chalk.red(search[v[1]]))
|
||||
|
||||
})
|
||||
})
|
||||
console.log('-----')
|
||||
}
|
73
web/node_modules/buffer-indexof/index.js
generated
vendored
Normal file
73
web/node_modules/buffer-indexof/index.js
generated
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
module.exports = function bufferIndexOf(buff, search, offset, encoding){
|
||||
if (!Buffer.isBuffer(buff)) {
|
||||
throw TypeError('buffer is not a buffer');
|
||||
}
|
||||
|
||||
// allow optional offset when providing an encoding
|
||||
if (encoding === undefined && typeof offset === 'string') {
|
||||
encoding = offset;
|
||||
offset = undefined;
|
||||
}
|
||||
|
||||
if (typeof search === 'string') {
|
||||
search = new Buffer(search, encoding || 'utf8');
|
||||
} else if (typeof search === 'number' && !isNaN(search)) {
|
||||
search = new Buffer([search])
|
||||
} else if (!Buffer.isBuffer(search)) {
|
||||
throw TypeError('search is not a bufferable object');
|
||||
}
|
||||
|
||||
if (search.length === 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (offset === undefined || (typeof offset === 'number' && isNaN(offset))) {
|
||||
offset = 0;
|
||||
} else if (typeof offset !== 'number') {
|
||||
throw TypeError('offset is not a number');
|
||||
}
|
||||
|
||||
if (offset < 0) {
|
||||
offset = buff.length + offset
|
||||
}
|
||||
|
||||
if (offset < 0) {
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
var m = 0;
|
||||
var s = -1;
|
||||
|
||||
for (var i = offset; i < buff.length ; ++i) {
|
||||
if(buff[i] != search[m]){
|
||||
s = -1;
|
||||
// <-- go back
|
||||
// match abc to aabc
|
||||
// 'aabc'
|
||||
// 'aab'
|
||||
// ^ no match
|
||||
// a'abc'
|
||||
// ^ set index here now and look at these again.
|
||||
// 'abc' yay!
|
||||
i -= m-1
|
||||
m = 0;
|
||||
}
|
||||
|
||||
if(buff[i] == search[m]) {
|
||||
if(s == -1) {
|
||||
s = i;
|
||||
}
|
||||
++m;
|
||||
if(m == search.length) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s > -1 && buff.length - s < search.length) {
|
||||
return -1;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
19
web/node_modules/buffer-indexof/package.json
generated
vendored
Normal file
19
web/node_modules/buffer-indexof/package.json
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "buffer-indexof",
|
||||
"description": "find the index of a buffer in a buffer",
|
||||
"version": "1.1.1",
|
||||
"repository": {
|
||||
"url": "git://github.com/soldair/node-buffer-indexof.git"
|
||||
},
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "tape test/*.js"
|
||||
},
|
||||
"author": "Ryan Day",
|
||||
"license": "MIT",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"chalk": "^1.1.3",
|
||||
"tape": "~1.1.0"
|
||||
}
|
||||
}
|
15
web/node_modules/buffer-indexof/test/bm.js
generated
vendored
Normal file
15
web/node_modules/buffer-indexof/test/bm.js
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
var test = require('tape')
|
||||
var bm = require('../bm')
|
||||
test("omg",function(t){
|
||||
|
||||
t.equals(bm('abc','bc'),1)
|
||||
t.equals(bm('ababc','bc'),3)
|
||||
t.equals(bm('abc','de'),-1)
|
||||
|
||||
t.equals(bm('123123412345','345'),9)
|
||||
|
||||
t.equals(bm('aaaba','aaba'),1,'partial matches should not be skipped')
|
||||
t.end()
|
||||
|
||||
|
||||
})
|
15
web/node_modules/buffer-indexof/test/multibyteneedle.js
generated
vendored
Normal file
15
web/node_modules/buffer-indexof/test/multibyteneedle.js
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
var test = require('tape')
|
||||
var bindexof = require('../')
|
||||
|
||||
test("can find mutibyte needles",function(t){
|
||||
|
||||
t.equals(bindexof(new Buffer("hi"),new Buffer("hi")),0,'should find multibyte needle when its the whole buffer')
|
||||
|
||||
// https://github.com/soldair/node-buffer-indexof/issues/2
|
||||
t.equals(bindexof(new Buffer("aaba"), new Buffer("ab")),1,'should find multibyte needle in haystack')
|
||||
|
||||
|
||||
t.end();
|
||||
|
||||
|
||||
})
|
8
web/node_modules/buffer-indexof/test/partial-match.js
generated
vendored
Normal file
8
web/node_modules/buffer-indexof/test/partial-match.js
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
var test = require('tape')
|
||||
var bufferIndexOf = require('../')
|
||||
|
||||
test("doesnt skip partial matches",function(t){
|
||||
//'aaaba'.indexOf('aaba') // --> 1
|
||||
t.equals(bufferIndexOf(new Buffer('aaaba'), new Buffer('aaba')),1,'partial matches should not be skipped')
|
||||
t.end()
|
||||
})
|
400
web/node_modules/buffer-indexof/test/test-buffer-indexof.js
generated
vendored
Normal file
400
web/node_modules/buffer-indexof/test/test-buffer-indexof.js
generated
vendored
Normal file
|
@ -0,0 +1,400 @@
|
|||
'use strict';
|
||||
var test = require('tape')
|
||||
var bindexOf = require('../')
|
||||
|
||||
var b = new Buffer('abcdef');
|
||||
var buf_a = new Buffer('a');
|
||||
var buf_bc = new Buffer('bc');
|
||||
var buf_f = new Buffer('f');
|
||||
var buf_z = new Buffer('z');
|
||||
var buf_empty = new Buffer('');
|
||||
|
||||
test('node 6 buffer indexOf tests', function(t) {
|
||||
t.equal(bindexOf(b, 'a'), 0);
|
||||
t.equal(bindexOf(b, 'a', 1), -1);
|
||||
t.equal(bindexOf(b, 'a', -1), -1);
|
||||
t.equal(bindexOf(b, 'a', -4), -1);
|
||||
t.equal(bindexOf(b, 'a', -b.length), 0);
|
||||
t.equal(bindexOf(b, 'a', NaN), 0);
|
||||
t.equal(bindexOf(b, 'a', -Infinity), 0);
|
||||
t.equal(bindexOf(b, 'a', Infinity), -1);
|
||||
t.equal(bindexOf(b, 'bc'), 1);
|
||||
t.equal(bindexOf(b, 'bc', 2), -1);
|
||||
t.equal(bindexOf(b, 'bc', -1), -1);
|
||||
t.equal(bindexOf(b, 'bc', -3), -1);
|
||||
t.equal(bindexOf(b, 'bc', -5), 1);
|
||||
t.equal(bindexOf(b, 'bc', NaN), 1);
|
||||
t.equal(bindexOf(b, 'bc', -Infinity), 1);
|
||||
t.equal(bindexOf(b, 'bc', Infinity), -1);
|
||||
t.equal(bindexOf(b, 'f'), b.length - 1);
|
||||
t.equal(bindexOf(b, 'z'), -1);
|
||||
t.equal(bindexOf(b, ''), -1);
|
||||
t.equal(bindexOf(b, '', 1), -1);
|
||||
t.equal(bindexOf(b, '', b.length + 1), -1);
|
||||
t.equal(bindexOf(b, '', Infinity), -1);
|
||||
t.equal(bindexOf(b, buf_a), 0);
|
||||
t.equal(bindexOf(b, buf_a, 1), -1);
|
||||
t.equal(bindexOf(b, buf_a, -1), -1);
|
||||
t.equal(bindexOf(b, buf_a, -4), -1);
|
||||
t.equal(bindexOf(b, buf_a, -b.length), 0);
|
||||
t.equal(bindexOf(b, buf_a, NaN), 0);
|
||||
t.equal(bindexOf(b, buf_a, -Infinity), 0);
|
||||
t.equal(bindexOf(b, buf_a, Infinity), -1);
|
||||
t.equal(bindexOf(b, buf_bc), 1);
|
||||
t.equal(bindexOf(b, buf_bc, 2), -1);
|
||||
t.equal(bindexOf(b, buf_bc, -1), -1);
|
||||
t.equal(bindexOf(b, buf_bc, -3), -1);
|
||||
t.equal(bindexOf(b, buf_bc, -5), 1);
|
||||
t.equal(bindexOf(b, buf_bc, NaN), 1);
|
||||
t.equal(bindexOf(b, buf_bc, -Infinity), 1);
|
||||
t.equal(bindexOf(b, buf_bc, Infinity), -1);
|
||||
t.equal(bindexOf(b, buf_f), b.length - 1);
|
||||
t.equal(bindexOf(b, buf_z), -1);
|
||||
t.equal(bindexOf(b, buf_empty), -1);
|
||||
t.equal(bindexOf(b, buf_empty, 1), -1);
|
||||
t.equal(bindexOf(b, buf_empty, b.length + 1), -1);
|
||||
t.equal(bindexOf(b, buf_empty, Infinity), -1);
|
||||
t.equal(bindexOf(b, 0x61), 0);
|
||||
t.equal(bindexOf(b, 0x61, 1), -1);
|
||||
t.equal(bindexOf(b, 0x61, -1), -1);
|
||||
t.equal(bindexOf(b, 0x61, -4), -1);
|
||||
t.equal(bindexOf(b, 0x61, -b.length), 0);
|
||||
t.equal(bindexOf(b, 0x61, NaN), 0);
|
||||
t.equal(bindexOf(b, 0x61, -Infinity), 0);
|
||||
t.equal(bindexOf(b, 0x61, Infinity), -1);
|
||||
t.equal(bindexOf(b, 0x0), -1);
|
||||
|
||||
// test offsets
|
||||
t.equal(bindexOf(b, 'd', 2), 3);
|
||||
t.equal(bindexOf(b, 'f', 5), 5);
|
||||
t.equal(bindexOf(b, 'f', -1), 5);
|
||||
t.equal(bindexOf(b, 'f', 6), -1);
|
||||
|
||||
t.equal(bindexOf(b, new Buffer('d'), 2), 3);
|
||||
t.equal(bindexOf(b, new Buffer('f'), 5), 5);
|
||||
t.equal(bindexOf(b, new Buffer('f'), -1), 5);
|
||||
t.equal(bindexOf(b, new Buffer('f'), 6), -1);
|
||||
|
||||
// This one doesn't make any sense
|
||||
// t.equal(bindexOf(new Buffer('ff'), new Buffer('f'), 1, 'ucs2'), -1);
|
||||
|
||||
// test hex encoding
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer(b.toString('hex'), 'hex'),
|
||||
'64',
|
||||
0,
|
||||
'hex'
|
||||
),
|
||||
3
|
||||
);
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer(b.toString('hex'), 'hex'),
|
||||
new Buffer('64', 'hex'), 0, 'hex'
|
||||
),
|
||||
3
|
||||
);
|
||||
|
||||
// test base64 encoding
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer(b.toString('base64'), 'base64'),
|
||||
'ZA==', 0, 'base64'
|
||||
),
|
||||
3
|
||||
);
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer(b.toString('base64'), 'base64'),
|
||||
new Buffer('ZA==', 'base64'), 0, 'base64'
|
||||
),
|
||||
3
|
||||
);
|
||||
|
||||
// test ascii encoding
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer(b.toString('ascii'), 'ascii'),
|
||||
'd', 0, 'ascii'
|
||||
),
|
||||
3
|
||||
);
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer(b.toString('ascii'), 'ascii'),
|
||||
new Buffer('d', 'ascii'), 0, 'ascii'
|
||||
),
|
||||
3
|
||||
);
|
||||
|
||||
// test latin1 encoding
|
||||
// does not work in LTS
|
||||
/*
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer(b.toString('latin1'), 'latin1'),
|
||||
'd',
|
||||
0,
|
||||
'latin1'
|
||||
),
|
||||
3
|
||||
);
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer(b.toString('latin1'), 'latin1'),
|
||||
new Buffer('d', 'latin1'),
|
||||
0,
|
||||
'latin1'
|
||||
),
|
||||
3
|
||||
);
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer('aa\u00e8aa', 'latin1'),
|
||||
'\u00e8',
|
||||
'latin1'
|
||||
),
|
||||
2
|
||||
);
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer('\u00e8', 'latin1'),
|
||||
'\u00e8',
|
||||
'latin1'
|
||||
),
|
||||
0
|
||||
);
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer('\u00e8', 'latin1'),
|
||||
new Buffer('\u00e8', 'latin1'),
|
||||
0,
|
||||
'latin1'
|
||||
),
|
||||
0
|
||||
);
|
||||
*/
|
||||
// test binary encoding
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer(b.toString('binary'), 'binary'),
|
||||
'd',
|
||||
0,
|
||||
'binary'
|
||||
),
|
||||
3
|
||||
);
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer(b.toString('binary'), 'binary'),
|
||||
new Buffer('d', 'binary'),
|
||||
0,
|
||||
'binary'
|
||||
),
|
||||
3
|
||||
);
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer('aa\u00e8aa', 'binary'),
|
||||
'\u00e8',
|
||||
0,
|
||||
'binary'
|
||||
),
|
||||
2
|
||||
);
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer('\u00e8', 'binary'),
|
||||
'\u00e8',
|
||||
0,
|
||||
'binary'
|
||||
),
|
||||
0
|
||||
);
|
||||
t.equal(
|
||||
bindexOf(
|
||||
new Buffer('\u00e8', 'binary'),
|
||||
new Buffer('\u00e8', 'binary'),
|
||||
0,
|
||||
'binary'
|
||||
),
|
||||
0
|
||||
);
|
||||
|
||||
|
||||
// test optional offset with passed encoding
|
||||
t.equal(new Buffer('aaaa0').indexOf('30', 'hex'), 4);
|
||||
t.equal(new Buffer('aaaa00a').indexOf('3030', 'hex'), 4);
|
||||
|
||||
{
|
||||
// test usc2 encoding
|
||||
var twoByteString = new Buffer('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
|
||||
|
||||
t.equal(8, twoByteString.indexOf('\u0395', 4, 'ucs2'));
|
||||
t.equal(6, twoByteString.indexOf('\u03a3', -4, 'ucs2'));
|
||||
t.equal(4, twoByteString.indexOf('\u03a3', -6, 'ucs2'));
|
||||
t.equal(4, twoByteString.indexOf(
|
||||
new Buffer('\u03a3', 'ucs2'), -6, 'ucs2'));
|
||||
t.equal(-1, twoByteString.indexOf('\u03a3', -2, 'ucs2'));
|
||||
}
|
||||
|
||||
var mixedByteStringUcs2 =
|
||||
new Buffer('\u039a\u0391abc\u03a3\u03a3\u0395', 'ucs2');
|
||||
t.equal(6, mixedByteStringUcs2.indexOf('bc', 0, 'ucs2'));
|
||||
t.equal(10, mixedByteStringUcs2.indexOf('\u03a3', 0, 'ucs2'));
|
||||
t.equal(-1, mixedByteStringUcs2.indexOf('\u0396', 0, 'ucs2'));
|
||||
|
||||
t.equal(
|
||||
6, mixedByteStringUcs2.indexOf(new Buffer('bc', 'ucs2'), 0, 'ucs2'));
|
||||
t.equal(
|
||||
10, mixedByteStringUcs2.indexOf(new Buffer('\u03a3', 'ucs2'), 0, 'ucs2'));
|
||||
t.equal(
|
||||
-1, mixedByteStringUcs2.indexOf(new Buffer('\u0396', 'ucs2'), 0, 'ucs2'));
|
||||
|
||||
{
|
||||
var twoByteString = new Buffer('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
|
||||
|
||||
// Test single char pattern
|
||||
t.equal(0, twoByteString.indexOf('\u039a', 0, 'ucs2'));
|
||||
t.equal(2, twoByteString.indexOf('\u0391', 0, 'ucs2'), 'Alpha');
|
||||
t.equal(4, twoByteString.indexOf('\u03a3', 0, 'ucs2'), 'First Sigma');
|
||||
t.equal(6, twoByteString.indexOf('\u03a3', 6, 'ucs2'), 'Second Sigma');
|
||||
t.equal(8, twoByteString.indexOf('\u0395', 0, 'ucs2'), 'Epsilon');
|
||||
t.equal(-1, twoByteString.indexOf('\u0392', 0, 'ucs2'), 'Not beta');
|
||||
|
||||
// Test multi-char pattern
|
||||
t.equal(
|
||||
0, twoByteString.indexOf('\u039a\u0391', 0, 'ucs2'), 'Lambda Alpha');
|
||||
t.equal(
|
||||
2, twoByteString.indexOf('\u0391\u03a3', 0, 'ucs2'), 'Alpha Sigma');
|
||||
t.equal(
|
||||
4, twoByteString.indexOf('\u03a3\u03a3', 0, 'ucs2'), 'Sigma Sigma');
|
||||
t.equal(
|
||||
6, twoByteString.indexOf('\u03a3\u0395', 0, 'ucs2'), 'Sigma Epsilon');
|
||||
}
|
||||
|
||||
var mixedByteStringUtf8 = new Buffer('\u039a\u0391abc\u03a3\u03a3\u0395');
|
||||
t.equal(5, mixedByteStringUtf8.indexOf('bc'));
|
||||
t.equal(5, mixedByteStringUtf8.indexOf('bc', 5));
|
||||
t.equal(5, mixedByteStringUtf8.indexOf('bc', -8));
|
||||
t.equal(7, mixedByteStringUtf8.indexOf('\u03a3'));
|
||||
t.equal(-1, mixedByteStringUtf8.indexOf('\u0396'));
|
||||
|
||||
|
||||
// Test complex string indexOf algorithms. Only trigger for long strings.
|
||||
// Long string that isn't a simple repeat of a shorter string.
|
||||
var longString = 'A';
|
||||
for (var i = 66; i < 76; i++) { // from 'B' to 'K'
|
||||
longString = longString + String.fromCharCode(i) + longString;
|
||||
}
|
||||
|
||||
var longBufferString = new Buffer(longString);
|
||||
|
||||
// pattern of 15 chars, repeated every 16 chars in long
|
||||
var pattern = 'ABACABADABACABA';
|
||||
for (var i = 0; i < longBufferString.length - pattern.length; i += 7) {
|
||||
var index = longBufferString.indexOf(pattern, i);
|
||||
t.equal((i + 15) & ~0xf, index, 'Long ABACABA...-string at index ' + i);
|
||||
}
|
||||
t.equal(510, longBufferString.indexOf('AJABACA'), 'Long AJABACA, First J');
|
||||
t.equal(
|
||||
1534, longBufferString.indexOf('AJABACA', 511), 'Long AJABACA, Second J');
|
||||
|
||||
pattern = 'JABACABADABACABA';
|
||||
t.equal(
|
||||
511, longBufferString.indexOf(pattern), 'Long JABACABA..., First J');
|
||||
t.equal(
|
||||
1535, longBufferString.indexOf(pattern, 512), 'Long JABACABA..., Second J');
|
||||
|
||||
// Search for a non-ASCII string in a pure ASCII string.
|
||||
var asciiString = new Buffer(
|
||||
'arglebargleglopglyfarglebargleglopglyfarglebargleglopglyf');
|
||||
t.equal(-1, asciiString.indexOf('\x2061'));
|
||||
t.equal(3, asciiString.indexOf('leb', 0));
|
||||
|
||||
// Search in string containing many non-ASCII chars.
|
||||
var allCodePoints = [];
|
||||
for (var i = 0; i < 65536; i++) allCodePoints[i] = i;
|
||||
var allCharsString = String.fromCharCode.apply(String, allCodePoints);
|
||||
var allCharsBufferUtf8 = new Buffer(allCharsString);
|
||||
var allCharsBufferUcs2 = new Buffer(allCharsString, 'ucs2');
|
||||
|
||||
// Search for string long enough to trigger complex search with ASCII pattern
|
||||
// and UC16 subject.
|
||||
t.equal(-1, allCharsBufferUtf8.indexOf('notfound'));
|
||||
t.equal(-1, allCharsBufferUcs2.indexOf('notfound'));
|
||||
|
||||
// Needle is longer than haystack, but only because it's encoded as UTF-16
|
||||
t.equal(new Buffer('aaaa').indexOf('a'.repeat(4), 'ucs2'), -1);
|
||||
|
||||
t.equal(new Buffer('aaaa').indexOf('a'.repeat(4), 'utf8'), 0);
|
||||
t.equal(new Buffer('aaaa').indexOf('你好', 'ucs2'), -1);
|
||||
|
||||
// Haystack has odd length, but the needle is UCS2.
|
||||
t.equal(new Buffer('aaaaa').indexOf('b', 'ucs2'), -1);
|
||||
|
||||
{
|
||||
// Find substrings in Utf8.
|
||||
var lengths = [1, 3, 15]; // Single char, simple and complex.
|
||||
var indices = [0x5, 0x60, 0x400, 0x680, 0x7ee, 0xFF02, 0x16610, 0x2f77b];
|
||||
for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
|
||||
for (var i = 0; i < indices.length; i++) {
|
||||
var index = indices[i];
|
||||
var length = lengths[lengthIndex];
|
||||
|
||||
if (index + length > 0x7F) {
|
||||
length = 2 * length;
|
||||
}
|
||||
|
||||
if (index + length > 0x7FF) {
|
||||
length = 3 * length;
|
||||
}
|
||||
|
||||
if (index + length > 0xFFFF) {
|
||||
length = 4 * length;
|
||||
}
|
||||
|
||||
var patternBufferUtf8 = allCharsBufferUtf8.slice(index, index + length);
|
||||
t.equal(index, allCharsBufferUtf8.indexOf(patternBufferUtf8));
|
||||
|
||||
var patternStringUtf8 = patternBufferUtf8.toString();
|
||||
t.equal(index, allCharsBufferUtf8.indexOf(patternStringUtf8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Find substrings in Usc2.
|
||||
var lengths = [2, 4, 16]; // Single char, simple and complex.
|
||||
var indices = [0x5, 0x65, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0];
|
||||
for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
|
||||
for (var i = 0; i < indices.length; i++) {
|
||||
var index = indices[i] * 2;
|
||||
var length = lengths[lengthIndex];
|
||||
|
||||
var patternBufferUcs2 =
|
||||
allCharsBufferUcs2.slice(index, index + length);
|
||||
t.equal(
|
||||
index, allCharsBufferUcs2.indexOf(patternBufferUcs2, 0, 'ucs2'));
|
||||
|
||||
var patternStringUcs2 = patternBufferUcs2.toString('ucs2');
|
||||
t.equal(
|
||||
index, allCharsBufferUcs2.indexOf(patternStringUcs2, 0, 'ucs2'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t.throws(function() {
|
||||
bindexOf(b, function() { });
|
||||
});
|
||||
t.throws(function() {
|
||||
bindexOf(b, {});
|
||||
});
|
||||
t.throws(function() {
|
||||
bindexOf(b, []);
|
||||
});
|
||||
|
||||
|
||||
t.end();
|
||||
});
|
37
web/node_modules/buffer-indexof/test/test.js
generated
vendored
Normal file
37
web/node_modules/buffer-indexof/test/test.js
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
var test = require('tape');
|
||||
var bindexOf = require('../');
|
||||
|
||||
test("can haz working",function(t){
|
||||
|
||||
|
||||
var newLineBuffer = new Buffer("\n");
|
||||
|
||||
var b = new Buffer("hi\nho\nsilver");
|
||||
|
||||
t.equals(bindexOf(new Buffer('a'), new Buffer('abc')), -1, 'should not match')
|
||||
|
||||
|
||||
t.equals(bindexOf(new Buffer('aaa'), new Buffer('aa'), 2), -1, 'should not match with 2 offset')
|
||||
t.equals(bindexOf(new Buffer('aaa'), new Buffer('aa')), 0, 'should match')
|
||||
|
||||
t.equals(bindexOf(b,newLineBuffer),2,'should find newlines');
|
||||
|
||||
// you can also start from index
|
||||
|
||||
t.equals(bindexOf(b,newLineBuffer,3),5,"should find newlines after offset");
|
||||
|
||||
// no match === -1
|
||||
|
||||
t.equals(bindexOf(b,newLineBuffer,6),-1,"should not find newlines where none are.");
|
||||
|
||||
|
||||
t.end();
|
||||
})
|
||||
|
||||
|
||||
test("can handle overlapping matches",function(t){
|
||||
console.log(1,'aaaba'.indexOf('aaba'))
|
||||
console.log(2,bindexOf(new Buffer('aaaba'), new Buffer('aaba')))
|
||||
console.log(3,(new Buffer('aaaba')).indexOf(new Buffer('aaba')))
|
||||
t.end()
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue