/*********************************************************
***   Author: Tim O'Brien
***   Company: Netlegger Systems Inc.
***   Date: July 14, 2006
***   Copyright 2006 Netlegger Systems Inc.
**********************************************************
***   Unit: distinctlistwithcounts.js
***   Purpose:  Extract data using a regular expression and report a dintinct
***             count based on the first group in the expression
**********************************************************
***   Copyright (C) 2006  Netlegger Systems Inc.

***   This program is free software; you can redistribute it and/or
***   modify it under the terms of the GNU General Public License
***   as published by the Free Software Foundation; version 2
***   of the License.

***   The code can be used\modified without any limitation,
***   however, this copyright notice can not be removed.

***   This program is distributed in the hope that it will be useful,
***   but WITHOUT ANY WARRANTY; without even the implied warranty of
***   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
***   GNU General Public License for more details.

***   You should have received a copy of the GNU General Public License
***   along with this program; if not, write to the Free Software
***   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**********************************************************/

function Run() {
    LargeEdit.ResultLog(' Regular Expression Search');

    var inpStr = LargeEdit.CurrentFile.Text; //Text inside the editor window

    var oRe;
    oRe = new RegExp("[GET|POST]\\s+(.*)500", "g"); //Regular Expression object
    var arr; //Array to hold results of expression search

    var cntarray = new Array(); //Count array to hold counts assoicated with items found
    var idxarray = new Array(); //Items array to hold all items found

    var idx;
    var cnt = 0;
    var distinct = 0;
    var retStr = '';

    //Begin searching text using regular expression
    while ((arr = oRe.exec(inpStr)) != null) {
      retStr += arr[1];
      cnt++;
      idx = idxarray.indexOf(arr[1]); //Has item already been found?
      if (idx < 0) {
         // Item not found, add to item array and start count at 1
         idxarray.push(arr[1]);
         cntarray.push(1);
         distinct++;
      } else {
        //Item found, increment the count by 1
        cntarray[idx]++;
      }
      retStr = '';
    }

    //Report information to results window
    LargeEdit.ResultLog('');
    LargeEdit.ResultLog('Total matches found ' + cnt)
    LargeEdit.ResultLog('Total distinct matches found ' + distinct)
    LargeEdit.ResultLog('');
    LargeEdit.ResultLog('List of distinct matches with counts');
    LargeEdit.ResultLog('');
    for (var i = 0; i < idxarray.length; i++) {
        LargeEdit.ResultLog( idxarray[i] + ' = ' + cntarray[i] );
    }

}

  //Extend existing JScript array object with an indexOf method
  function Array_indexOf(text) {
    var res = -1;
    for (var i = 0; i < this.length; i++) {
      if (text.toUpperCase() == this[i].toUpperCase()) {
        res = i;
        break;
      }
    }
    return res;
  }
  Array.prototype.indexOf = Array_indexOf;


//copyright 2006 All rights reserved

