After some minor reformatting of data from a textarea, from a loop I look at it with a variety of regular expressions. When I find one with an index of zero I create an appropriate entry in a work table, remove the length of that construct from the beginning of the string and loop again. A variable "maxOffset" is initialized to the length of the data and, if a found construct has an index > zero, that index will replace maxOffset if it is less that that current value. If I fall through to the end of the loop I will know how long the garbage is, create an error message, and remove it from the string.
Each of these constructs ends with the same (colored) lines. Is there a way to eliminate the need for this? switch and case seems close to the structure, but it can't do regular expressions.Code:while (lines.length > 0) { var strLength, maxOffset = lines.length; ... if ((result = lines.match(/\|\|/))) { //Found double bar line if (result.index == 0) { lastfound = "double bar"; strLength = result[0].length; genWorkEntry("Bar|Style:Double"); lines = lines.substr(strLength); continue; } else maxOffset = (result.index < maxOffset)? result.index : maxOffset; } if ((result = lines.match(/:\|(\d)/))) { //Found Repeat Close and Special ending if (result.index == 0) { lastfound = "repclose special"; strLength = result[0].length; genWorkEntry("Bar|Style:MasterRepeatClose"); genWorkEntry("Ending|Endings:" + result[1]); lines = lines.substr(strLength); continue; } else maxOffset = (result.index < maxOffset)? result.index : maxOffset; } ... errText += "Unable to process: " + lines.substr(0,maxOffset) + " length: " + maxOffset + " last: " + lastfound + "\n"; genWorkEntry("Text|Text:\"" + lines.substr(0,maxOffset) + "\"|Font:StaffBold|Pos:-8|Wide:Y|Justify:Left|Placement:BestFit|Color:3|Visibility:Default"); lines = lines.substr(maxOffset); } //End main parsing loop
The website is abcnwc.htm and this code is on lines 541-819.
TIA


Reply With Quote

Bookmarks