// Display document or selection statistics. // last modified 2004.12.22 function displayStatistics(str, title) { var nc=0; // chars var nnc=0; // chars without \r and \n var nsc=0; // chars without \s var nw=0; // words var nl=0; // lines var nbl=0; // lines without blank lines nc = str.length // convert to unix line endings for simplicity str=str.replace(/\r\n/g, "\n").replace(/\r/g, "\n"); // make sure selection ends with newline if (! /\n$/.test(str)) str=str+"\n"; nnc = str.replace(/\n/g, "").length; nsc = str.replace(/\s/g, "").length; nw = str.split(/\s+/).length; nl = str.replace( /[^\n]/g, "").length; noBlanks = str.replace(/[ \t]/g, "").replace(/^\n+/, "").replace(/\n{2,}/g, "\n"); nbl=noBlanks.replace( /[^\n]/g, "" ).length; alert( title + "\n" + "Words: " + nw + "\n" + "Lines: " +nl + "\n" + "Lines w/o blanks: " + nbl + "\n" + "Chars: " + nc + "\n" + "Chars w/o newlines: " + nnc + "\n" + "Chars w/o whitespace: " + nsc ); } if (document.selection.IsEmpty) { xPos = document.selection.GetActivePointX(eePosLogical); yPos = document.selection.GetActivePointY(eePosLogical); document.selection.SelectAll(); string = document.selection.Text; document.selection.SetActivePoint(eePosLogical, xPos, yPos, false); displayStatistics(string, "---Document Statistics---"); } else { string = document.selection.Text; displayStatistics(string, "---Selection Statistics---"); }