(:~ handle textDocument 
 : @author andy bunce
 :)
module namespace text = 'text';

declare record text:rec(
  lines as xs:string+,
  separator? as xs:string:=file:line-separator(),
  text? as  fn() as xs:string:= %method fn () { string-join(?lines,?separator) },
  line?  :=  %method fn($line) {?lines[$line]},
  length? as xs:integer   
);

(:~ json numbers :)
declare type text:num as (xs:integer|xs:double); 

(:~ 
@param line Line position in a document (zero-based).
@param character Character offset on a line in a document (zero-based).
:)
declare record text:Position(
	line as text:num,
	character as text:num
);

(:~ 
@param line Line position in a document (zero-based).
@param character Character offset on a line in a document (zero-based).
:)
declare record text:Range(
	start as text:Position,
	end as text:Position
);

(: create new text from string :)
declare function text:build($text as xs:string){
   let $lines:=tokenize($text, '(\r\n?|\n\r?)')
   return text:rec($lines)
};