/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
var FileIndex=function(utils){this._displacements=[];this._lastDisp=null;this._utils=utils};FileIndex.prototype.getRowCol=function(data,index,fileType){var start,end,datalen,disp,lastDisp,c,inStart=false,latest,temp,initIndex,i;if(index.line){return{row:index.line,col:index.col}}if(!data){return{row:0,col:0}}start=index.start;end=index.end;datalen=data.length;lastDisp=null;latest=0;for(i=0;i<this._displacements.length;i++){disp=this._displacements[i];if(start>=disp.index&&disp.index>latest){lastDisp=disp;latest=disp.index}}if(lastDisp){if(start===lastDisp.index){return{row:lastDisp.line,col:lastDisp.col}}temp={index:lastDisp.index,line:lastDisp.line,col:lastDisp.col};lastDisp=temp}else{lastDisp={index:0,line:1,col:1}}initIndex=lastDisp.index;for(i=initIndex;i<datalen;i++){c=data.charAt(i);if(i===start){inStart=true;lastDisp.index=start;break}if(c==="\n"){lastDisp.line++;lastDisp.col=1;continue}if(c==="\r"){continue}if(!inStart){if(c!=="\t"){lastDisp.col++}else{lastDisp.col=this._tabs.getTabCol(lastDisp.col,fileType)}continue}}this._displacements.push(lastDisp);return{row:lastDisp.line,col:lastDisp.col}};FileIndex.prototype.clear=function(){this._displacements.length=0};FileIndex.prototype.setTabHandler=function(oTabs){this._tabs=oTabs};module.exports=FileIndex;