All pastes #75314 Raw Edit

Sato1

public text v1 · immutable
#75314 ·published 2006-06-30 01:21 UTC
rendered paste body
 array set latin {
  a \[àáâãäåÀÁÂÃÄÅa\]
  e \[èéêëÈÉÊËe\]
  i \[ìíîïÌÍÎÏi\]
  o \[òóôõöÒÓÔÕÖo\]
  u \[ùúûüÙÚÛÜu\]
  n \[ñnÑ\]
  y \[ýÿÝy\]
  b \[ßb\]
 }

proc textbold {pattern text} {
  # no pattern no text process
  if {[join $pattern] == ""} {
    return $text
  }

  # find and avoid duplicities in the pattern
  array set v {}
  foreach x [join [join $pattern]] {
    set v($x) ""
  }
  set pattern [array names v]

  global latin

  # lets switch spetial chars for the normal one
  foreach x [array names latin] {
    regsub -all $latin($x) $pattern $x pattern
  }

  # now prepare for re process
  set pattern [string map [array get latin] $pattern]
  foreach x $pattern {
    regsub -all -nocase "\\y$x\\y" $text "<b>&</b>" text
  }

  # and deliever the result
  return $text
}