summaryrefslogtreecommitdiff
path: root/support/tcltexed/lib/backslash.tcl
blob: 032db6ade30243e65013c6c20a3d43b88c0b6b91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright (C) 1999 - Martin Strauss - under terms of GPL
####################################################################
# Setzt backslash's fuer eine Stringuebergabe ein
proc backslash {s} {
 set begin_s ""
 set end_s $s
 set pos 0
 while {$pos != 10000} {
 set key ""
  set pos "10000"
  set kpos [string first "\"" $end_s]
  if {$pos > $kpos} then {
   if {$kpos != -1} then {
    set pos $kpos
    set key "\\\""
  }}
  set kpos [string first "\\" $end_s]
  if {$pos > $kpos} then {
   if {$kpos != -1} then {
    set pos $kpos
    set key "\\\\"
  }}
  set kpos [string first "\n" $end_s]
  if {$pos > $kpos} then {
   if {$kpos != -1} then {
    set pos $kpos
    set key "\\n"
  }}
  set kpos [string first "\t" $end_s]
  if {$pos > $kpos} then {
   if {$kpos != -1} then {
    set pos $kpos
    set key "\\t"
  }}
  set kpos [string first "\[" $end_s]
  if {$pos > $kpos} then {
   if {$kpos != -1} then {
    set pos $kpos
    set key "\\\["
  }}

  set kpos [string first "\]" $end_s]
  if {$pos > $kpos} then {
   if {$kpos != -1} then {
    set pos $kpos
    set key "\\\]"
  }}
  set kpos [string first "\{" $end_s]
  if {$pos > $kpos} then {
   if {$kpos != -1} then {
    set pos $kpos
    set key "\\\{"
  }}

  set kpos [string first "\}" $end_s]
  if {$pos > $kpos} then {
   if {$kpos != -1} then {
    set pos $kpos
    set key "\\\}"
  }}

  if {$pos != 10000} then {
   set begin_s $begin_s[string range $end_s 0 [expr $pos - 1]]$key
   set end_s "[string range $end_s [expr $pos + 1] end]"
  } else {return "$begin_s$end_s"}
}}