The class I am using to parse JSON does not allow you to have colons in any string. For example, this would cause an error in parsing:
{
"Test:": "Just a test"
}
Any ideas on how to make this class ignore colons that are in a string? Here is the class I am using:
class JSON {
static var inst;
var text;
function JSON() {
}
static function getInstance() {
if (inst == null) {
inst = new cinqetdemi.JSON();
}
return (inst);
}
static function stringify(arg) {
var _local3;
var _local2;
var _local6;
var _local1 = "";
var _local4;
switch (typeof (arg)) {
case "object" :
if (arg) {
if (arg instanceof Array) {
_local2 = 0;
while (_local2 < arg.length) {
_local4 = stringify(arg[_local2]);
if (_local1) {
_local1 = _local1 + ",";
}
_local1 = _local1 + _local4;
_local2++;
}
return (("[" + _local1) + "]");
} else if (typeof (arg.toString) != "undefined") {
for (_local2 in arg) {
_local4 = arg[_local2];
if ((typeof (_local4) != "undefined") && (typeof (_local4) != "function")) {
_local4 = stringify(_local4);
if (_local1) {
_local1 = _local1 + ",";
}
_local1 = _local1 + ((stringify(_local2) + ":") + _local4);
}
}
return (("{" + _local1) + "}");
}
}
return ("null");
case "number" :
return ((isFinite(arg) ? (String(arg)) : "null"));
case "string" :
_local6 = arg.length;
_local1 = "\"";
_local2 = 0;
while (_local2 < _local6) {
_local3 = arg.charAt(_local2);
if (_local3 >= " ") {
if ((_local3 == "\\") || (_local3 == "\"")) {
_local1 = _local1 + "\\";
}
_local1 = _local1 + _local3;
} else {
switch (_local3) {
case "\b" :
_local1 = _local1 + "\\b";
break;
case "\f" :
_local1 = _local1 + "\\f";
break;
case newline :
_local1 = _local1 + "\\n";
break;
case "\r" :
_local1 = _local1 + "\\r";
break;
case "\t" :
_local1 = _local1 + "\\t";
break;
default :
_local3 = _local3.charCodeAt();
_local1 = _local1 + (("\\u00" + Math.floor(_local3 / 16).toString(16)) + (_local3 % 16).toString(16));
}
}
_local2 = _local2 + 1;
}
return (_local1 + "\"");
case "boolean" :
return (String(arg));
}
return ("null");
}
static function parse(text) {
if (!text.length) {
throw new Error("JSONError: Text missing");
}
var _local1 = getInstance();
_local1.at = 0;
_local1.ch = " ";
_local1.text = text;
return (_local1.value());
}
function error(m) {
var _local2 = ((("JSONError: " + m) + " at ") + (at - 1)) + newline;
_local2 = _local2 + (text.substr(at - 10, 20) + newline);
_local2 = _local2 + " ^";
throw new Error(_local2);
}
function next() {
ch = text.charAt(at);
at = at + 1;
return (ch);
}
function white() {
while (ch) {
if (ch <= " ") {
next();
} else if (ch == "/") {
switch (next()) {
case "/" :
while ((next() && (ch != newline)) && (ch != "\r")) {
}
break;
case "*" :
next();
while (true) {
if (ch) {
if (ch == "*") {
if (next() == "/") {
next();
break;
}
} else {
next();
}
} else {
error("Unterminated comment");
}
}
break;
default :
error("Syntax error");
}
} else {
break;
}
}
}
function str() {
var _local5;
var _local2 = "";
var _local4;
var _local3;
var _local6 = false;
if ((ch == "\"") || (ch == "'")) {
var _local7 = ch;
while (next()) {
if (ch == _local7) {
next();
return (_local2);
} else if (ch == "\\") {
switch (next()) {
case "b" :
_local2 = _local2 + "\b";
break;
case "f" :
_local2 = _local2 + "\f";
break;
case "n" :
_local2 = _local2 + newline;
break;
case "r" :
_local2 = _local2 + "\r";
break;
case "t" :
_local2 = _local2 + "\t";
break;
case "u" :
_local3 = 0;
_local5 = 0;
while (_local5 < 4) {
_local4 = parseInt(next(), 16);
if (!isFinite(_local4)) {
_local6 = true;
break;
}
_local3 = (_local3 * 16) + _local4;
_local5 = _local5 + 1;
}
if (_local6) {
_local6 = false;
break;
}
_local2 = _local2 + String.fromCharCode(_local3);
break;
default :
_local2 = _local2 + ch;
}
} else {
_local2 = _local2 + ch;
}
}
}
error("Bad string");
}
function key() {
var _local2 = ch;
var _local6 = false;
var _local3 = text.indexOf(":", at);
var _local4 = text.indexOf("\"", at);
var _local5 = text.indexOf("'", at);
if (((_local4 <= _local3) && (_local4 > -1)) || ((_local5 <= _local3) && (_local5 > -1))) {
_local2 = str();
white();
if (ch == ":") {
return (_local2);
} else {
error("Bad key");
}
}
while (next()) {
if (ch == ":") {
return (_local2);
}
if (ch <= " ") {
} else {
_local2 = _local2 + ch;
}
}
error("Bad key");
}
function arr() {
var _local2 = [];
if (ch == "[") {
next();
white();
if (ch == "]") {
next();
return (_local2);
}
while (ch) {
if (ch == "]") {
next();
return (_local2);
}
_local2.push(value());
white();
if (ch == "]") {
next();
return (_local2);
} else if (ch != ",") {
break;
}
next();
white();
}
}
error("Bad array");
}
function obj() {
var _local3;
var _local2 = {};
if (ch == "{") {
next();
white();
if (ch == "}") {
next();
return (_local2);
}
while (ch) {
if (ch == "}") {
next();
return (_local2);
}
_local3 = this.key();
if (ch != ":") {
break;
}
next();
_local2[_local3] = value();
white();
if (ch == "}") {
next();
return (_local2);
} else if (ch != ",") {
break;
}
next();
white();
}
}
error("Bad object");
}
function num() {
var _local2 = "";
var _local3;
if (ch == "-") {
_local2 = "-";
next();
}
while (((((ch >= "0") && (ch <= "9")) || (ch == "x")) || ((ch >= "a") && (ch <= "f"))) || ((ch >= "A") && (ch <= "F"))) {
_local2 = _local2 + ch;
next();
}
if (ch == ".") {
_local2 = _local2 + ".";
next();
while ((ch >= "0") && (ch <= "9")) {
_local2 = _local2 + ch;
next();
}
}
if ((ch == "e") || (ch == "E")) {
_local2 = _local2 + ch;
next();
if ((ch == "-") || (ch == "+")) {
_local2 = _local2 + ch;
next();
}
while ((ch >= "0") && (ch <= "9")) {
_local2 = _local2 + ch;
next();
}
}
_local3 = Number(_local2);
if (!isFinite(_local3)) {
error("Bad number");
}
return (_local3);
}
function word() {
switch (ch) {
case "t" :
if (((next() == "r") && (next() == "u")) && (next() == "e")) {
next();
return (true);
}
break;
case "f" :
if ((((next() == "a") && (next() == "l")) && (next() == "s")) && (next() == "e")) {
next();
return (false);
}
break;
case "n" :
if (((next() == "u") && (next() == "l")) && (next() == "l")) {
next();
return (null);
}
break;
}
error("Syntax error");
}
function value() {
white();
switch (ch) {
case "{" :
return (obj());
case "[" :
return (arr());
case "\"" :
case "'" :
return (str());
case "-" :
return (num());
}
return ((((ch >= "0") && (ch <= "9")) ? (num()) : (word())));
}
var at = 0;
var ch = " ";
}
Take a look on my answer of this question and use the JSON class that I mentioned there, it's working fine with your test content :
import JSON;
var json = new JSON();
var data:String = '{"Test:": "Just a test"}';
trace(json.parse(data)['Test:']); // gives : Just a test
Hope that can help.
Related
I'm trying to find the coordinates (LAT LONG) of a street from the beginning to the end of the street with the GOOGLE MAPS API. I can not find some simillaria on the net
Thanks
I use this code :
function findEndAddr(addr) {
for (var i = 500;;) {
var Http = new XMLHttpRequest();
var url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + i.toString().split('.')[0] + addr.replace(/\s/g, '') + '&key=KEY_API';
console.log(url);
Http.open("GET", url, false);
Http.send(null);
if (Http.status == 200 && Http.readyState == 4) {
var resp = JSON.parse(Http.responseText);
if (resp['results'][0]['address_components'][0]['types'][0] != 'street_number') {
i = i / 2;
}
else {
return findEndAddrNext(addr, i, i, 2);
}
}
}
}
And I use this function :
function findEndAddrNext(addr, i, nb, div) {
var Http = new XMLHttpRequest();
var url;
url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + nb.toString().split('.')[0] + addr.replace(/\s/g, '') + '&key=KEY-API';
console.log(url);
Http.open("GET", url, false);
Http.send(null);
if (Http.status == 200 && Http.readyState == 4) {
var resp = JSON.parse(Http.responseText);
var index = 0;
for (let cpt = 0; cpt < resp['results'].length; cpt++) {
console.log(getThing(resp['results'][cpt]['address_components'], 'postal_code'));
console.log(addr.split(',')[2]);
if (getThing(resp['results'][cpt]['address_components'], 'locality') == addr.split(',')[1]) {
index = cpt;
break;
}
}
if (resp['results'][index]['address_components'][0]['types'][0] == 'street_number') {
i = nb;
if ((nb / div) <= 2) {
if (getThing(resp['results'][index]['address_components'], 'locality') != addr.split(',')[1]) {
oui = searchFinal(getThing(resp['results'][index]['address_components'], 'street_number'), addr);
return;
}
oui = [resp['results'][index]['geometry']['location'].lat, resp['results'][0]['geometry']['location'].lng];
console.log(resp);
return;
}
nb = nb + (nb / div);
findEndAddrNext(addr, i, nb, div);
}
if (resp['results'][index]['address_components'][0]['types'][0] != 'street_number') {
div *= 2;
nb = i + (i / div);
findEndAddrNext(addr, i, nb, div);
}
}
}
Last night, my little brother asked me if it were possible to make a program that would substitute every letter for another letter in the alphabet, to turn it into a code, and also turn it back to its normal state.
So I made this: http://www.skyetheguy.com/novatranslationtool
And by all accounts, it does the job, but I feel like, code-wise, it's clunky as all get-out, and I'd really love to improve my knowledge on things like loops...
EDIT: The above has since been updated with DodgerThud's amazing answer and works like a dream. : ) Dreams DO come true!
Also, this is very pie-in-the-sky, but it'd be amazing to get this to work with longer-than-two-characters things. My code definitely wouldn't do that at all. But, you know, all those fun codes with apostrophes in them... good stuff!
stop();
// SET-UP STUFF
inputText.alpha = .5;
outputText.alpha = .5;
inputText.borderColor = 0xCCCCCC;
outputText.borderColor = 0xCCCCCC;
var textinProgress:String;
textinProgress = inputText.text;
if (textinProgress.charAt(0) == "\r") {
inputText.text = "";
}
stage.addEventListener(Event.ENTER_FRAME, refresh_frame1);
function refresh_frame1(e:Event):void {
inputScroll.update();
outputScroll.update();
}
// ORIGINAL ALPHABET
var letters_aArray:Array = new Array();
letters_aArray[0] = "a";
letters_aArray[1] = "b";
letters_aArray[2] = "c";
letters_aArray[3] = "d";
letters_aArray[4] = "e";
letters_aArray[5] = "f";
letters_aArray[6] = "g";
letters_aArray[7] = "h";
letters_aArray[8] = "i";
letters_aArray[9] = "j";
letters_aArray[10] = "k";
letters_aArray[11] = "l";
letters_aArray[12] = "m";
letters_aArray[13] = "n";
letters_aArray[14] = "o";
letters_aArray[15] = "p";
letters_aArray[16] = "q";
letters_aArray[17] = "r";
letters_aArray[18] = "s";
letters_aArray[19] = "t";
letters_aArray[20] = "u";
letters_aArray[21] = "v";
letters_aArray[22] = "w";
letters_aArray[23] = "x";
letters_aArray[24] = "y";
letters_aArray[25] = "z";
// NEW ALPHABET
var letters_bArray:Array = new Array();
letters_bArray[0] = "m";
letters_bArray[1] = "n";
letters_bArray[2] = "b";
letters_bArray[3] = "v";
letters_bArray[4] = "c";
letters_bArray[5] = "x";
letters_bArray[6] = "z";
letters_bArray[7] = "l";
letters_bArray[8] = "k";
letters_bArray[9] = "j";
letters_bArray[10] = "h";
letters_bArray[11] = "g";
letters_bArray[12] = "f";
letters_bArray[13] = "d";
letters_bArray[14] = "s";
letters_bArray[15] = "a";
letters_bArray[16] = "p";
letters_bArray[17] = "o";
letters_bArray[18] = "i";
letters_bArray[19] = "u";
letters_bArray[20] = "y";
letters_bArray[21] = "t";
letters_bArray[22] = "r";
letters_bArray[23] = "e";
letters_bArray[24] = "w";
letters_bArray[25] = "q";
// ENCODE BUTTON
encode_btn.addEventListener(MouseEvent.CLICK, encode_btnclick);
function encode_btnclick(event:MouseEvent):void
{
textinProgress = inputText.text;
outputText.text = "";
for (var b=0; b<textinProgress.length; b++) {
if (textinProgress.charAt(b).search(letters_aArray[0]) == 0) {
outputText.appendText(letters_bArray[0]);
} else if (textinProgress.charAt(b).search(letters_aArray[0].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[0].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[1]) == 0) {
outputText.appendText(letters_bArray[1]);
} else if (textinProgress.charAt(b).search(letters_aArray[1].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[1].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[2]) == 0) {
outputText.appendText(letters_bArray[2]);
} else if (textinProgress.charAt(b).search(letters_aArray[2].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[2].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[3]) == 0) {
outputText.appendText(letters_bArray[3]);
} else if (textinProgress.charAt(b).search(letters_aArray[3].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[3].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[4]) == 0) {
outputText.appendText(letters_bArray[4]);
} else if (textinProgress.charAt(b).search(letters_aArray[4].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[4].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[5]) == 0) {
outputText.appendText(letters_bArray[5]);
} else if (textinProgress.charAt(b).search(letters_aArray[5].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[5].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[6]) == 0) {
outputText.appendText(letters_bArray[6]);
} else if (textinProgress.charAt(b).search(letters_aArray[6].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[6].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[7]) == 0) {
outputText.appendText(letters_bArray[7]);
} else if (textinProgress.charAt(b).search(letters_aArray[7].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[7].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[8]) == 0) {
outputText.appendText(letters_bArray[8]);
} else if (textinProgress.charAt(b).search(letters_aArray[8].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[8].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[9]) == 0) {
outputText.appendText(letters_bArray[9]);
} else if (textinProgress.charAt(b).search(letters_aArray[9].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[9].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[10]) == 0) {
outputText.appendText(letters_bArray[10]);
} else if (textinProgress.charAt(b).search(letters_aArray[10].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[10].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[11]) == 0) {
outputText.appendText(letters_bArray[11]);
} else if (textinProgress.charAt(b).search(letters_aArray[11].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[11].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[12]) == 0) {
outputText.appendText(letters_bArray[12]);
} else if (textinProgress.charAt(b).search(letters_aArray[12].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[12].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[13]) == 0) {
outputText.appendText(letters_bArray[13]);
} else if (textinProgress.charAt(b).search(letters_aArray[13].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[13].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[14]) == 0) {
outputText.appendText(letters_bArray[14]);
} else if (textinProgress.charAt(b).search(letters_aArray[14].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[14].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[15]) == 0) {
outputText.appendText(letters_bArray[15]);
} else if (textinProgress.charAt(b).search(letters_aArray[15].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[15].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[16]) == 0) {
outputText.appendText(letters_bArray[16]);
} else if (textinProgress.charAt(b).search(letters_aArray[16].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[16].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[17]) == 0) {
outputText.appendText(letters_bArray[17]);
} else if (textinProgress.charAt(b).search(letters_aArray[17].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[17].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[18]) == 0) {
outputText.appendText(letters_bArray[18]);
} else if (textinProgress.charAt(b).search(letters_aArray[18].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[18].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[19]) == 0) {
outputText.appendText(letters_bArray[19]);
} else if (textinProgress.charAt(b).search(letters_aArray[19].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[19].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[20]) == 0) {
outputText.appendText(letters_bArray[20]);
} else if (textinProgress.charAt(b).search(letters_aArray[20].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[20].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[21]) == 0) {
outputText.appendText(letters_bArray[21]);
} else if (textinProgress.charAt(b).search(letters_aArray[21].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[21].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[22]) == 0) {
outputText.appendText(letters_bArray[22]);
} else if (textinProgress.charAt(b).search(letters_aArray[22].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[22].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[23]) == 0) {
outputText.appendText(letters_bArray[23]);
} else if (textinProgress.charAt(b).search(letters_aArray[23].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[23].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[24]) == 0) {
outputText.appendText(letters_bArray[24]);
} else if (textinProgress.charAt(b).search(letters_aArray[24].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[24].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_aArray[25]) == 0) {
outputText.appendText(letters_bArray[25]);
} else if (textinProgress.charAt(b).search(letters_aArray[25].toUpperCase()) == 0) {
outputText.appendText(letters_bArray[25].toUpperCase());
} else if (textinProgress.charAt(b) == "\r") {
outputText.appendText("\n");
} else {
outputText.appendText(textinProgress.charAt(b));
}
}
}
// DECODE BUTTON
decode_btn.addEventListener(MouseEvent.CLICK, decode_btnclick);
function decode_btnclick(event:MouseEvent):void
{
textinProgress = inputText.text;
outputText.text = "";
for (var b=0; b<textinProgress.length; b++) {
if (textinProgress.charAt(b).search(letters_bArray[0]) == 0) {
outputText.appendText(letters_aArray[0]);
} else if (textinProgress.charAt(b).search(letters_bArray[0].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[0].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[1]) == 0) {
outputText.appendText(letters_aArray[1]);
} else if (textinProgress.charAt(b).search(letters_bArray[1].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[1].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[2]) == 0) {
outputText.appendText(letters_aArray[2]);
} else if (textinProgress.charAt(b).search(letters_bArray[2].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[2].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[3]) == 0) {
outputText.appendText(letters_aArray[3]);
} else if (textinProgress.charAt(b).search(letters_bArray[3].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[3].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[4]) == 0) {
outputText.appendText(letters_aArray[4]);
} else if (textinProgress.charAt(b).search(letters_bArray[4].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[4].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[5]) == 0) {
outputText.appendText(letters_aArray[5]);
} else if (textinProgress.charAt(b).search(letters_bArray[5].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[5].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[6]) == 0) {
outputText.appendText(letters_aArray[6]);
} else if (textinProgress.charAt(b).search(letters_bArray[6].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[6].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[7]) == 0) {
outputText.appendText(letters_aArray[7]);
} else if (textinProgress.charAt(b).search(letters_bArray[7].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[7].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[8]) == 0) {
outputText.appendText(letters_aArray[8]);
} else if (textinProgress.charAt(b).search(letters_bArray[8].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[8].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[9]) == 0) {
outputText.appendText(letters_aArray[9]);
} else if (textinProgress.charAt(b).search(letters_bArray[9].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[9].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[10]) == 0) {
outputText.appendText(letters_aArray[10]);
} else if (textinProgress.charAt(b).search(letters_bArray[10].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[10].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[11]) == 0) {
outputText.appendText(letters_aArray[11]);
} else if (textinProgress.charAt(b).search(letters_bArray[11].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[11].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[12]) == 0) {
outputText.appendText(letters_aArray[12]);
} else if (textinProgress.charAt(b).search(letters_bArray[12].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[12].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[13]) == 0) {
outputText.appendText(letters_aArray[13]);
} else if (textinProgress.charAt(b).search(letters_bArray[13].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[13].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[14]) == 0) {
outputText.appendText(letters_aArray[14]);
} else if (textinProgress.charAt(b).search(letters_bArray[14].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[14].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[15]) == 0) {
outputText.appendText(letters_aArray[15]);
} else if (textinProgress.charAt(b).search(letters_bArray[15].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[15].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[16]) == 0) {
outputText.appendText(letters_aArray[16]);
} else if (textinProgress.charAt(b).search(letters_bArray[16].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[16].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[17]) == 0) {
outputText.appendText(letters_aArray[17]);
} else if (textinProgress.charAt(b).search(letters_bArray[17].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[17].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[18]) == 0) {
outputText.appendText(letters_aArray[18]);
} else if (textinProgress.charAt(b).search(letters_bArray[18].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[18].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[19]) == 0) {
outputText.appendText(letters_aArray[19]);
} else if (textinProgress.charAt(b).search(letters_bArray[19].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[19].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[20]) == 0) {
outputText.appendText(letters_aArray[20]);
} else if (textinProgress.charAt(b).search(letters_bArray[20].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[20].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[21]) == 0) {
outputText.appendText(letters_aArray[21]);
} else if (textinProgress.charAt(b).search(letters_bArray[21].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[21].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[22]) == 0) {
outputText.appendText(letters_aArray[22]);
} else if (textinProgress.charAt(b).search(letters_bArray[22].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[22].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[23]) == 0) {
outputText.appendText(letters_aArray[23]);
} else if (textinProgress.charAt(b).search(letters_bArray[23].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[23].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[24]) == 0) {
outputText.appendText(letters_aArray[24]);
} else if (textinProgress.charAt(b).search(letters_bArray[24].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[24].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[25]) == 0) {
outputText.appendText(letters_aArray[25]);
} else if (textinProgress.charAt(b).search(letters_bArray[25].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[25].toUpperCase());
} else if (textinProgress.charAt(b) == "\r") {
outputText.appendText("\n");
} else {
outputText.appendText(textinProgress.charAt(b));
}
}
}
// RECODE BUTTON (scrambles, takes what's in the output and applies the cipher again)
recode_btn.addEventListener(MouseEvent.CLICK, recode_btnclick);
function recode_btnclick(event:MouseEvent):void
{
textinProgress = outputText.text;
outputText.text = "";
for (var b=0; b<textinProgress.length; b++) {
if (textinProgress.charAt(b).search(letters_bArray[0]) == 0) {
outputText.appendText(letters_aArray[0]);
} else if (textinProgress.charAt(b).search(letters_bArray[0].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[0].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[1]) == 0) {
outputText.appendText(letters_aArray[1]);
} else if (textinProgress.charAt(b).search(letters_bArray[1].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[1].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[2]) == 0) {
outputText.appendText(letters_aArray[2]);
} else if (textinProgress.charAt(b).search(letters_bArray[2].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[2].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[3]) == 0) {
outputText.appendText(letters_aArray[3]);
} else if (textinProgress.charAt(b).search(letters_bArray[3].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[3].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[4]) == 0) {
outputText.appendText(letters_aArray[4]);
} else if (textinProgress.charAt(b).search(letters_bArray[4].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[4].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[5]) == 0) {
outputText.appendText(letters_aArray[5]);
} else if (textinProgress.charAt(b).search(letters_bArray[5].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[5].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[6]) == 0) {
outputText.appendText(letters_aArray[6]);
} else if (textinProgress.charAt(b).search(letters_bArray[6].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[6].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[7]) == 0) {
outputText.appendText(letters_aArray[7]);
} else if (textinProgress.charAt(b).search(letters_bArray[7].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[7].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[8]) == 0) {
outputText.appendText(letters_aArray[8]);
} else if (textinProgress.charAt(b).search(letters_bArray[8].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[8].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[9]) == 0) {
outputText.appendText(letters_aArray[9]);
} else if (textinProgress.charAt(b).search(letters_bArray[9].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[9].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[10]) == 0) {
outputText.appendText(letters_aArray[10]);
} else if (textinProgress.charAt(b).search(letters_bArray[10].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[10].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[11]) == 0) {
outputText.appendText(letters_aArray[11]);
} else if (textinProgress.charAt(b).search(letters_bArray[11].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[11].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[12]) == 0) {
outputText.appendText(letters_aArray[12]);
} else if (textinProgress.charAt(b).search(letters_bArray[12].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[12].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[13]) == 0) {
outputText.appendText(letters_aArray[13]);
} else if (textinProgress.charAt(b).search(letters_bArray[13].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[13].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[14]) == 0) {
outputText.appendText(letters_aArray[14]);
} else if (textinProgress.charAt(b).search(letters_bArray[14].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[14].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[15]) == 0) {
outputText.appendText(letters_aArray[15]);
} else if (textinProgress.charAt(b).search(letters_bArray[15].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[15].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[16]) == 0) {
outputText.appendText(letters_aArray[16]);
} else if (textinProgress.charAt(b).search(letters_bArray[16].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[16].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[17]) == 0) {
outputText.appendText(letters_aArray[17]);
} else if (textinProgress.charAt(b).search(letters_bArray[17].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[17].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[18]) == 0) {
outputText.appendText(letters_aArray[18]);
} else if (textinProgress.charAt(b).search(letters_bArray[18].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[18].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[19]) == 0) {
outputText.appendText(letters_aArray[19]);
} else if (textinProgress.charAt(b).search(letters_bArray[19].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[19].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[20]) == 0) {
outputText.appendText(letters_aArray[20]);
} else if (textinProgress.charAt(b).search(letters_bArray[20].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[20].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[21]) == 0) {
outputText.appendText(letters_aArray[21]);
} else if (textinProgress.charAt(b).search(letters_bArray[21].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[21].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[22]) == 0) {
outputText.appendText(letters_aArray[22]);
} else if (textinProgress.charAt(b).search(letters_bArray[22].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[22].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[23]) == 0) {
outputText.appendText(letters_aArray[23]);
} else if (textinProgress.charAt(b).search(letters_bArray[23].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[23].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[24]) == 0) {
outputText.appendText(letters_aArray[24]);
} else if (textinProgress.charAt(b).search(letters_bArray[24].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[24].toUpperCase());
} else if (textinProgress.charAt(b).search(letters_bArray[25]) == 0) {
outputText.appendText(letters_aArray[25]);
} else if (textinProgress.charAt(b).search(letters_bArray[25].toUpperCase()) == 0) {
outputText.appendText(letters_aArray[25].toUpperCase());
} else if (textinProgress.charAt(b) == "\r") {
outputText.appendText("\n");
} else {
outputText.appendText(textinProgress.charAt(b));
}
}
}
Just gonna tell you why I did all the incredibly arbitrary and loopy stuff that I did...
If you do any of the other normal replace things other people have talked about here (from what I've FOUND, at least), you end up replacing your own work at a certain point. For example if you want B to be A, but then you want A to be C, then if you type "BA", you get back "CC" instead of "AC". So my code actually takes each character and spits them all out one at a time.
I did all that tedious ".toUpperCase()" stuff to make sure that this tool was case-sensitive-- so that if I typed in a lowercase or uppercase key, it would always generate the proper one in its place. That's why RegExp didn't quite work for me.
It also takes into account things like line breaks and random symbols not included in the alphabet.
I know for SURE there's simpler, more energy-efficient ways to code this, but I just have no idea how.
I'm gonna expand on my comment and show you how can simplify your code and cut out a lot of it.
First off, you don't need to use Arrays. String objects in essence already are Arrays of byte values. So instead of creating big arrays, you can do this
var alphabet:String = "abcdefghijklmnopqrstuvwxyz";
var substitution:String = "mnbvcxzlkjhgfdsapoiuytrewq";
In order to access a specific character, you can simply call the indexOf method on the string.
var indexOfJ = alphabet.indexOf("j");
trace(indexOfJ); //puts out 9
And you already now how to get the character of a string from a specific index.
var charAtIndex7:String = alphabet.charAt(7);
trace(charAtIndex7); //puts out "h"
Edit fom here:
Looks like I was only half-awake when I wrote that answer last night. The issue with the double for-loop is simply that it will always run the whole way through, even if it found an if clause that gets accepted. You already figured out on
your own that the last else-clause causes the input character to be printed 25 times. So, lets fix it.
function cipher(input:Textfield, output:Textfield, alphabet:String, substitution:String){
textinProgress = input.text;
var result:String = "";
for(var b=0;b<textinProgress.length;b++)
{
var anyHit = false;
for(var i=0;i<alphabet.length;i++){
if(textinProgress.charAt(b).search(alphabet.charAt(i)) == 0){
result += substituton.charAt(i);
anyHit = true;
break;
}
else if(textinProgress.charAt(b).search(alphabet.charAt(i).toUpperCase()) == 0){
result += substituton.charAt(i).toUpperCase();
anyHit = true;
break;
}
else if(textinProgress.charAt(b) == "\r"){
result += "\n";
anyHit = true;
break;
}
}
if(anyHit == false){
result += textinProgress.charAt(b);
}
}
output.text = result;
}
I had a coworker test this code for me earlier today, and it should work as intended.
But that's not all we can do to simplify your code. We can cut out the second if clause by defining our alphabet and substitution variables with both lowercase and uppercase letters.
var alphabet:String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var substitution:String = "mnbvcxzlkjhgfdsapoiuytrewqMNBVCXZLKJHGFDSAPOIUYTREWQ";
You should also be able to put in special symbols into your alphabet and substitution string, like \r for example.
var alphabet:String = "\rabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var substitution:String = "\nmnbvcxzlkjhgfdsapoiuytrewqMNBVCXZLKJHGFDSAPOIUYTREWQ";
I'm not entirely sure if this will work, but it should.
Now you have already considerably shortened your code, but we can even shorten it further. Is the inner for loop really neccessary? Because our alphabet and our substitution are the same length, maybe we can simplify this even more.
function cipher(input:Textfield, output:Textfield, alphabet:String, substitution:String){
textinProgress = input.text;
var result:String = "";
for(var b=0;b<textinProgress.length;b++)
{
var index:int = alphabet.indexOf(textinProgress.charAt(b));
if(index >= 0){
result += substitution.charAt(index);
}else{
result += textinProgress.charAt(b);
}
}
output.text = result;
}
Putting it all together.
var alphabet:String = "\rabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var substitution:String = "\nmnbvcxzlkjhgfdsapoiuytrewqMNBVCXZLKJHGFDSAPOIUYTREWQ";
function cipher(input:Textfield, output:Textfield, alphabet:String, substitution:String){
textinProgress = input.text;
var result:String = "";
for(var b=0;b<textinProgress.length;b++)
{
var index:int = alphabet.indexOf(textinProgress.charAt(b));
if(index >= 0){
result += substitution.charAt(index);
}else{
result += textinProgress.charAt(b);
}
}
output.text = result;
}
function encode_btnclick(event:MouseEvent):void{
cipher(inputText, outputText, alphabet, substitution);
}
function decode_btnclick(event:MouseEvent):void{
cipher(inputText, outputText, substitution, alphabet);
}
function recode_btnclick(event:MouseEvent):void{
cipher(outputText, outputText, alphabet, substitution);
}
This should be able to handle
Text of any length
Line breaks
Upper- and Lowercase letters
Undefined characters
You should search for Substitution ciphers, e.g., one of the simplest ones is the Caesar cipher.
Hello!
I have This in my website:
var docCookies = {
getItem: function (sKey) {
if (!sKey) { return null; }
return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
},
setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {return false; }
var sExpires = "";
if (vEnd) {
switch (vEnd.constructor) {
case Number:
sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
break;
case String:
sExpires = "; expires=" + vEnd;
break;
case Date:
sExpires = "; expires=" + vEnd.toUTCString();
break;
}
}
document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
return true;
},
removeItem: function (sKey, sPath, sDomain) {
if (!this.hasItem(sKey)) { return false; }
document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "");
return true;
},
hasItem: function (sKey) {
if (!sKey) { return false; }
return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
},
keys: function () {
var aKeys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, "").split(/\s*(?:\=[^;]*)?;\s*/);
for (var nLen = aKeys.length, nIdx = 0; nIdx < nLen; nIdx++) { aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]); }
return aKeys;
}
};
alert('In next prompt enter "admin".')
var admin = prompt('Name?')
docCookies.setItem('name',admin);
setInterval(function() {if (docCookies.getItem('name')){}else{var a = 2}}, 1000)
But this is not work:
setInterval(function() {if (docCookies.getItem('name')){}else{var a = 2}}, 1000)
Why thi is not work:
setInterval(function() {if (docCookies.getItem('name')){}else{var a = 2}}, 1000)
What in page not work and why?
I
<script type="text/javascript">
var docCookies = {
getItem: function (sKey) {
if (!sKey) { return null; }
return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
},
setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { return false; }
var sExpires = "";
if (vEnd) {
switch (vEnd.constructor) {
case Number:
sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
break;
case String:
sExpires = "; expires=" + vEnd;
break;
case Date:
sExpires = "; expires=" + vEnd.toUTCString();
break;
}
}
document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
return true;
},
removeItem: function (sKey, sPath, sDomain) {
if (!this.hasItem(sKey)) { return false; }
document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "");
return true;
},
hasItem: function (sKey) {
if (!sKey) { return false; }
return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
},
keys: function () {
var aKeys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, "").split(/\s*(?:\=[^;]*)?;\s*/);
for (var nLen = aKeys.length, nIdx = 0; nIdx < nLen; nIdx++) { aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]); }
return aKeys;
}
};
alert('In next prompt enter "admin".')
var admin = prompt('Name?')
docCookies.setItem('name',admin);
setInterval(function() {if (docCookies.getItem('name')){}else{var a = 2}}, 1000)
The variable is declared locally in the function, so it only exists inside that scope, and only while the function is running.
Declare the variable in the global scope, so that you can set it and read it anywhere:
var a;
setInterval(function() {
if (!docCookies.getItem('name')) {
a = 2;
}
}, 1000)
My Nodejs Code:
i am trying to download files (excel) from a server and parse those excel files and from that data store only required data into mysql database i may download multiple files for that my loop may get interrupted so how to do my below code to run in a series of synchronous way
var r=0;
if (issue.fields.attachment != '') {
while (typeof issue.fields.attachment[r] != "undefined") {
if (typeof issue.fields.attachment[r].content != "undefined") {
var url = issue.fields.attachment[r].content;
request({
method: "GET",
"url": url,
"headers": { "Content-Type": "application/json", }
}, function(err, data, body) {
console.log('file downloading');
}).pipe(fs.createWriteStream('file.xlsx'));
console.log('file downloaded');
parseXlsx('file.xlsx', function(err, data) {
var i, j, k = 1, l = 0, m = 0, n = 0;
console.log('parseXlsx cmpleted');
while (data[i] != undefined) {
if (data[i][j] != '' || data[i][k] != '' || data[i][l] != '') {
var query = connection.query('insert into IP values ("' + data[i][j] + '","' + data[i][k] + '","' + data[i][l] + '","' + data[i][m] + '")',
function(error, results, fields) {
});
}
i++;
}
});
r++;
console.log('rvalue' + r);
}
}
}
I (very quickly, so it probably has errors) rewrote this using async.forEachOfSeries to iterate over your attachments. I used async.forEachOf for the database writes as I don't see a need for them to be in series.
var async = require('async');
if (issue.fields.attachment != '') {
async.forEachOfSeries(issue.fields.attachment,function(attachment,r,callback){
if (typeof issue.fields.attachment[r].content != "undefined") {
var url = issue.fields.attachment[r].content;
var ws = fs.createWriteStream('file.xlsx');
request({ method: "GET", "url": url, "headers": { "Content-Type": "application/json" }
}, function(err, data, body) {
console.log('file downloading');
}).pipe(ws);
ws.on('finish',function() {
console.log('file downloaded');
parseXlsx('file.xlsx', function (err, data) {
var i, j, k = 1, l = 0, m = 0, n = 0;
for (i = 0; i < 15; i++) {
for (j = 0; j < 15; j++) {
if (regex.test(data[i][j])) {
k = 0;
break;
}
}
if (k == 0)
break;
}
for (k = 0; k < 15; k++) {
if (regex1.test(data[i][k])) {
break;
}
}
for (l = 0; l < 15; l++) {
if (regex2.test(data[i][l])) {
break;
}
}
for (m = 0; m < 15; m++) {
if (regex2.test(data[i][m])) {
break;
}
}
i = i + 1;
console.log('parseXlsx completed');
async.forEachOf(data,function(row,i,_callback){
if(i===0)return _callback();
if (data[i][j] != '' || data[i][k] != '' || data[i][l] != '') {
var query = connection.query('insert into IP values ("' + data[i][j] + '","' + data[i][k] + '","' + data[i][l] + '","' + data[i][m] + '")',
function (error, results, fields) {
if(error){
//Decide if you want to stop writing rows if one insert fails, if so uncomment next line
//return _callback(error);
}
return _callback();
});
}
},function(err){
if(err){
//decide if you want to stop the whole process if the database errored, if so, uncomment next line
//return callback(err);
}
callback();
});
});
});
ws.on('error',function(err) {
//There was an error writing the file to disk, but I assume you want to continue anyway so I'm calling callback()
//If you want to stop processing, call callback(new Error('Failed writing to disk'));
return callback();
});
}
});
}
What is wrong with
el.insertAdjacentHTML(hashVal[0], html);
where html is "<a title=\"\">1</a>" and hashVal[0] is "afterBegin".
This is related to a rating functionality. I think due to this error, the rating star is not displaying in ie 8. Other browsers are ok.
I have given the full flow of code below. I am using extjs.
var starLink = star.createChild({
tag: 'a',
html: this.values[i],
title: this.showTitles ? this.titles[i] : ''
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
createChild : function(config, insertBefore, returnDom) {
config = config || {tag:'div'};
if (insertBefore) {
return Ext.DomHelper.insertBefore(insertBefore, config, returnDom !== true);
}
else {
return Ext.DomHelper[!this.dom.firstChild ? 'insertFirst' : 'append'](this.dom, config, returnDom !== true);
}
},
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
insertFirst : function(el, o, returnElement){
return doInsert(el, o, returnElement, afterbegin, 'firstChild');
},
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function doInsert(el, o, returnElement, pos, sibling, append){
el = Ext.getDom(el);
var newNode;
if (pub.useDom) {
newNode = createDom(o, null);
if (append) {
el.appendChild(newNode);
} else {
(sibling == 'firstChild' ? el : el.parentNode).insertBefore(newNode, el[sibling] || el);
}
} else {
newNode = Ext.DomHelper.insertHtml(pos, el, Ext.DomHelper.createHtml(o));
}
return returnElement ? Ext.get(newNode, true) : newNode;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function createHtml(o){
var b = '',
attr,
val,
key,
cn,
i;
if(typeof o == "string"){
b = o;
} else if (Ext.isArray(o)) {
for (i=0; i < o.length; i++) {
if(o[i]) {
b += createHtml(o[i]);
}
}
} else {
b += '<' + (o.tag = o.tag || 'div');
for (attr in o) {
val = o[attr];
if(!confRe.test(attr)){
if (typeof val == "object") {
b += ' ' + attr + '="';
for (key in val) {
b += key + ':' + val[key] + ';';
}
b += '"';
}else{
b += ' ' + ({cls : 'class', htmlFor : 'for'}[attr] || attr) + '="' + val + '"';
}
}
}
if (emptyTags.test(o.tag)) {
b += '/>';
} else {
b += '>';
if ((cn = o.children || o.cn)) {
b += createHtml(cn);
} else if(o.html){
b += o.html;
}
b += '</' + o.tag + '>';
}
}
return b;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
insertHtml : function(where, el, html){
var hash = {},
hashVal,
range,
rangeEl,
setStart,
frag,
rs;
where = where.toLowerCase();
hash[beforebegin] = ['beforeBegin', 'previousSibling'];
hash[afterend] = ['afterEnd', 'nextSibling'];
if (el.insertAdjacentHTML) {
if(tableRe.test(el.tagName) && (rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html))){
return rs;
}
hash[afterbegin] = ['afterBegin', 'firstChild'];
hash[beforeend] = ['beforeEnd', 'lastChild'];
if ((hashVal = hash[where])) {
el.insertAdjacentHTML(hashVal[0], html);
return el[hashVal[1]];
}
} else {