
# Here are some spell check filters


# Quoted strings... the selected area must span the whole string
#
# first a helper...
#
# rquote searches for the next quote string
#
#  qt is a list with two elements, the start quote string and the end string
#  se is a bool 0 -> look for start, 1 -> look for end
#
#  returns  -1 if not found
#           index if found
#
proc rquote {qt se s} {
  set st 0
  set qts [lindex $qt $se]
  while {[set r [string first $qts [string range $s $st end]]] != -1} {
    #puts "rq $r $st $s [string length $s]"
    set lc [expr $st + $r]
    if {[string range $s $lc-1 $lc-1] != {\\} } {
      return $lc
    }
    set st [incr lc]
  }
  #puts "rq -1 on $s"
  return -1
}

# Using the above, this will do two types of strings
# Ones that are quoted like "this"
# and comments that start with a fixed string passed as <flag>
#
#  qt is a two entry list with the begining and ending quote char.
#  flag is the begining only quote string (# or // for example)
#  s is the line
#  line is the line number so we can handle multiple line quotes
#       
proc qstrings {qt flag s line} {
  global qstringLine
  global qstringchar
  if {![info exists qstringline]} {
    set qstringline 0
    set qstringchar 0
  }
  if {[incr qstringLine] != $line} {
    set qstringchar 0
  }
  set qstringLine $line

  if {$flag != {} && [regexp "^\[ \t]*$flag" $s]} {
    set qstringchar 0
    #puts "rtn [list 0 end]"
    return [list [list 0 end]]
  }
  set st 0
  set rt {}
  while {[set fq [rquote $qt $qstringchar [string range $s $st end]]] != -1} {
    set nx [expr $st + $fq]
    #puts "main $st $fq $nx"
    if {$qstringchar} {
      lappend rt [list $st $nx]
    }
    set st [incr nx [string length [lindex $qt $qstringchar]]]
    set qstringchar [expr ! $qstringchar]
  }
  if {$qstringchar} {
    lappend rt [list $st end]
  }
  #puts "returning $rt"
  return $rt
}
  
proc thisstr {which script s line} {
  set rt [lindex [{*}$script $s $line] $which]
  if {$rt == {}} {
    return {}
  }
  return [list $rt]
}
