Port stringToColor to C++.

Fixes #50.
This commit is contained in:
Black Hat
2018-09-16 16:09:36 +08:00
parent 03a8eae491
commit 1e04013e3d
11 changed files with 20 additions and 27 deletions

View File

@@ -1,18 +1,5 @@
.pragma library
function stringToColor(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var colour = '#';
for (var j = 0; j < 3; j++) {
var value = (hash >> (j * 8)) & 0xFF;
colour += ('00' + value.toString(16)).substr(-2);
}
return colour;
}
function pushToStack(stack, page) {
if(page && stack.currentItem !== page) {
if(stack.depth === 1) {