examples/historyBuff/src/wikipedia.js
function parseJson(inputText) {
    // sizeOf (/nEvents/n) is 10
    var text = inputText.substring(inputText.indexOf("\\nEvents\\n")+10, inputText.indexOf("\\n\\n\\nBirths")),
        retArr = [],
        retString = "",
        endIndex,
        startIndex = 0;

    if (text.length == 0) {
        return retArr;
    }

    while(true) {
        endIndex = text.indexOf("\\n", startIndex+delimiterSize);
        var eventText = (endIndex == -1 ? text.substring(startIndex) : text.substring(startIndex, endIndex));
        // replace dashes returned in text from Wikipedia's API
        eventText = eventText.replace(/\\u2013\s*/g, '');
        // add comma after year so Alexa pauses before continuing with the sentence
        eventText = eventText.replace(/(^\d+)/,'$1,');
        eventText = 'In ' + eventText;
        startIndex = endIndex+delimiterSize;
        retArr.push(eventText);
        if (endIndex == -1) {
            break;
        }
    }
    if (retString != "") {
        retArr.push(retString);
    }
    retArr.reverse();
    return retArr;
}
function parseJson(inputText) {
    // sizeOf (/nEvents/n) is 10
    var text = inputText.substring(inputText.indexOf("\\nEvents\\n")+10, inputText.indexOf("\\n\\n\\nBirths")),
        retArr = [],
        retString = "",
        endIndex,
        startIndex = 0;

    if (text.length == 0) {
        return retArr;
    }

    while(true) {
        endIndex = text.indexOf("\\n", startIndex+delimiterSize);
        var eventText = (endIndex == -1 ? text.substring(startIndex) : text.substring(startIndex, endIndex));
        // replace dashes returned in text from Wikipedia's API
        eventText = eventText.replace(/\\u2013\s*/g, '');
        // add comma after year so Alexa pauses before continuing with the sentence
        eventText = eventText.replace(/(^\d+)/,'$1,');
        eventText = 'In ' + eventText;
        startIndex = endIndex+delimiterSize;
        retArr.push(eventText);
        if (endIndex == -1) {
            break;
        }
    }
    if (retString != "") {
        retArr.push(retString);
    }
    retArr.reverse();
    return retArr;
}
function parseJson ( inputText ) { // sizeOf (/nEvents/n) is 10 var text = inputText . substring ( inputText . indexOf ( "\\nEvents\\n" ) + 10 , inputText . indexOf ( "\\n\\n\\nBirths" ) ) , retArr = [ ] , retString = "" , endIndex , startIndex = 0 ; if ( text . length == 0 ) { return retArr ; } while ( true ) { endIndex = text . indexOf ( "\\n" , startIndex + delimiterSize ) ; var eventText = ( endIndex == - 1 ? text . substring ( startIndex ) : text . substring ( startIndex , endIndex ) ) ; // replace dashes returned in text from Wikipedia's API eventText = eventText . replace ( / \\u2013\s* / g , '' ) ; // add comma after year so Alexa pauses before continuing with the sentence eventText = eventText . replace ( / (^\d+) / , '$1,' ) ; eventText = 'In ' + eventText ; startIndex = endIndex + delimiterSize ; retArr . push ( eventText ) ; if ( endIndex == - 1 ) { break ; } } if ( retString != "" ) { retArr . push ( retString ) ; } retArr . reverse ( ) ; return retArr ; }
TODO refactor this terribleness
TODO refactor this terribleness