Collection of themes/skins for the Fossil SCM

⌈⌋ ⎇ branch:  Fossil Skins Extra


Hex Artifact Content

Artifact a31d2c8db270ab76e81220db4863e0a1c3a0cc7e:

  • File features/str.th1 — part of check-in [82270c3d74] at 2015-02-09 01:52:44 on branch trunk — Split up th1x into individual sections (basic control structures, str, sql functions, and github-specific ui:: functions). Rename changelog to hooks. (user: mario size: 1407)

0000: 20 20 20 0a 23 2d 2d 20 72 65 74 75 72 6e 73 20     .#-- returns 
0010: 74 72 75 65 20 69 66 20 73 74 72 69 6e 67 20 63  true if string c
0020: 6f 6e 74 61 69 6e 65 64 20 69 6e 20 61 6e 6f 74  ontained in anot
0030: 68 65 72 20 73 74 72 69 6e 67 0a 70 72 6f 63 20  her string.proc 
0040: 73 74 72 3a 3a 63 6f 6e 74 61 69 6e 73 20 7b 6e  str::contains {n
0050: 65 65 64 6c 65 20 68 61 79 73 74 61 63 6b 7d 20  eedle haystack} 
0060: 7b 0a 20 20 20 72 65 74 75 72 6e 20 5b 65 78 70  {.   return [exp
0070: 72 20 7b 2d 31 20 21 3d 20 5b 73 74 72 69 6e 67  r {-1 != [string
0080: 20 66 69 72 73 74 20 24 6e 65 65 64 6c 65 20 24   first $needle $
0090: 68 61 79 73 74 61 63 6b 5d 7d 5d 0a 7d 0a 0a 23  haystack]}].}..#
00a0: 2d 2d 20 77 72 61 70 70 65 72 20 66 6f 72 20 5b  -- wrapper for [
00b0: 73 74 72 69 6e 67 20 66 69 72 73 74 20 2e 2e 2e  string first ...
00c0: 5d 20 74 6f 20 73 75 70 70 6f 72 74 20 73 74 61  ] to support sta
00d0: 72 74 69 6e 64 65 78 0a 70 72 6f 63 20 73 74 72  rtindex.proc str
00e0: 3a 3a 6e 65 78 74 20 7b 73 65 61 72 63 68 20 63  ::next {search c
00f0: 6f 6e 74 65 6e 74 20 73 74 61 72 74 7d 20 7b 0a  ontent start} {.
0100: 20 20 20 23 20 63 75 74 20 6f 75 74 20 24 63 6f     # cut out $co
0110: 6e 74 65 6e 74 20 61 74 20 24 73 74 61 72 74 20  ntent at $start 
0120: 62 65 66 6f 72 65 20 73 65 61 72 63 68 69 6e 67  before searching
0130: 0a 20 20 20 73 65 74 20 70 20 5b 73 74 72 69 6e  .   set p [strin
0140: 67 20 66 69 72 73 74 20 24 73 65 61 72 63 68 20  g first $search 
0150: 5b 73 74 72 69 6e 67 20 72 61 6e 67 65 20 24 63  [string range $c
0160: 6f 6e 74 65 6e 74 20 24 73 74 61 72 74 20 5b 73  ontent $start [s
0170: 74 72 69 6e 67 20 6c 65 6e 67 74 68 20 24 63 6f  tring length $co
0180: 6e 74 65 6e 74 5d 5d 5d 0a 20 20 20 69 66 20 5b  ntent]]].   if [
0190: 65 78 70 72 20 24 70 3e 3d 30 5d 20 7b 0a 20 20  expr $p>=0] {.  
01a0: 20 20 20 20 73 65 74 20 70 20 5b 65 78 70 72 20      set p [expr 
01b0: 24 73 74 61 72 74 2b 24 70 5d 0a 20 20 20 7d 0a  $start+$p].   }.
01c0: 20 20 20 72 65 74 75 72 6e 20 24 70 0a 7d 0a 0a     return $p.}..
01d0: 23 2d 2d 20 65 6e 63 6c 6f 73 65 20 73 74 72 69  #-- enclose stri
01e0: 6e 67 20 69 6e 20 65 2e 67 2e 20 68 74 6d 6c 20  ng in e.g. html 
01f0: 74 61 67 73 0a 70 72 6f 63 20 73 74 72 3a 3a 77  tags.proc str::w
0200: 72 61 70 20 7b 63 6f 6e 74 65 6e 74 20 73 65 61  rap {content sea
0210: 72 63 68 20 62 65 66 6f 72 65 20 61 66 74 65 72  rch before after
0220: 7d 20 7b 0a 20 20 20 73 65 74 20 6c 65 6e 20 5b  } {.   set len [
0230: 73 74 72 69 6e 67 20 6c 65 6e 67 74 68 20 24 73  string length $s
0240: 65 61 72 63 68 5d 0a 20 20 20 73 65 74 20 70 20  earch].   set p 
0250: 30 0a 20 20 20 77 68 69 6c 65 20 7b 5b 65 78 70  0.   while {[exp
0260: 72 20 5b 73 65 74 20 70 20 5b 73 74 72 3a 3a 6e  r [set p [str::n
0270: 65 78 74 20 24 73 65 61 72 63 68 20 24 63 6f 6e  ext $search $con
0280: 74 65 6e 74 20 24 70 5d 5d 3e 3d 30 5d 7d 20 7b  tent $p]]>=0]} {
0290: 0a 20 20 20 20 20 20 73 65 74 20 63 6f 6e 74 65  .      set conte
02a0: 6e 74 20 22 5b 73 74 72 69 6e 67 20 72 61 6e 67  nt "[string rang
02b0: 65 20 24 63 6f 6e 74 65 6e 74 20 30 20 5b 65 78  e $content 0 [ex
02c0: 70 72 20 24 70 2d 31 5d 5d 24 62 65 66 6f 72 65  pr $p-1]]$before
02d0: 24 73 65 61 72 63 68 24 61 66 74 65 72 5b 73 74  $search$after[st
02e0: 72 69 6e 67 20 72 61 6e 67 65 20 24 63 6f 6e 74  ring range $cont
02f0: 65 6e 74 20 5b 65 78 70 72 20 24 70 2b 24 6c 65  ent [expr $p+$le
0300: 6e 5d 20 32 30 30 30 5d 22 3b 0a 20 20 20 20 20  n] 2000]";.     
0310: 20 73 65 74 20 70 20 5b 65 78 70 72 20 24 70 2b   set p [expr $p+
0320: 5b 73 74 72 69 6e 67 20 6c 65 6e 67 74 68 20 22  [string length "
0330: 24 62 65 66 6f 72 65 2b 24 73 65 61 72 63 68 2b  $before+$search+
0340: 24 61 66 74 65 72 22 5d 5d 3b 20 23 20 73 6b 69  $after"]]; # ski
0350: 70 20 61 20 6c 69 74 74 6c 65 20 66 75 72 74 68  p a little furth
0360: 65 72 0a 20 20 20 7d 0a 20 20 20 72 65 74 75 72  er.   }.   retur
0370: 6e 20 24 63 6f 6e 74 65 6e 74 0a 7d 0a 0a 23 2d  n $content.}..#-
0380: 2d 20 53 70 6c 69 74 20 73 74 72 69 6e 67 20 69  - Split string i
0390: 6e 74 6f 20 6c 69 73 74 20 6f 6e 20 64 65 6c 69  nto list on deli
03a0: 6d 69 74 65 72 20 63 68 61 72 61 63 74 65 72 0a  miter character.
03b0: 23 20 28 62 61 73 69 63 61 6c 6c 79 20 6a 75 73  # (basically jus
03c0: 74 20 74 75 72 6e 73 20 64 65 6c 69 6d 69 74 65  t turns delimite
03d0: 72 20 69 6e 74 6f 20 73 70 61 63 65 29 0a 23 0a  r into space).#.
03e0: 70 72 6f 63 20 73 74 72 3a 3a 65 78 70 6c 6f 64  proc str::explod
03f0: 65 20 7b 64 65 6c 69 6d 20 73 74 72 7d 20 7b 0a  e {delim str} {.
0400: 20 20 20 73 65 74 20 72 20 22 22 0a 20 20 20 73     set r "".   s
0410: 65 74 20 6c 65 6e 20 5b 73 74 72 69 6e 67 20 6c  et len [string l
0420: 65 6e 67 74 68 20 24 73 74 72 5d 0a 20 20 20 77  ength $str].   w
0430: 68 69 6c 65 20 7b 2d 31 20 21 3d 20 5b 73 65 74  hile {-1 != [set
0440: 20 70 20 5b 73 74 72 69 6e 67 20 66 69 72 73 74   p [string first
0450: 20 24 64 65 6c 69 6d 20 24 73 74 72 5d 5d 7d 20   $delim $str]]} 
0460: 7b 0a 20 20 20 20 20 20 73 65 74 20 72 20 22 24  {.      set r "$
0470: 72 20 5b 73 74 72 69 6e 67 20 72 61 6e 67 65 20  r [string range 
0480: 24 73 74 72 20 30 20 5b 65 78 70 72 20 24 70 2d  $str 0 [expr $p-
0490: 31 5d 5d 22 0a 20 20 20 20 20 20 73 65 74 20 73  1]]".      set s
04a0: 74 72 20 5b 73 74 72 69 6e 67 20 72 61 6e 67 65  tr [string range
04b0: 20 24 73 74 72 20 5b 2b 2b 20 70 5d 20 24 6c 65   $str [++ p] $le
04c0: 6e 5d 0a 20 20 20 7d 0a 20 20 20 72 65 74 75 72  n].   }.   retur
04d0: 6e 20 5b 6c 69 73 74 20 5b 73 74 72 69 6e 67 20  n [list [string 
04e0: 74 72 69 6d 20 22 24 72 20 24 73 74 72 22 5d 5d  trim "$r $str"]]
04f0: 0a 7d 20 20 20 0a 0a 23 2d 2d 20 45 78 74 72 61  .}   ..#-- Extra
0500: 63 74 20 64 69 72 6e 61 6d 65 20 66 72 6f 6d 20  ct dirname from 
0510: 70 61 74 68 2f 66 69 6c 65 2f 6e 61 6d 65 0a 70  path/file/name.p
0520: 72 6f 63 20 73 74 72 3a 3a 64 69 72 6e 61 6d 65  roc str::dirname
0530: 20 7b 70 61 74 68 7d 20 7b 0a 20 20 20 72 65 74   {path} {.   ret
0540: 75 72 6e 20 5b 73 74 72 69 6e 67 20 72 61 6e 67  urn [string rang
0550: 65 20 24 70 61 74 68 20 30 20 5b 65 78 70 72 20  e $path 0 [expr 
0560: 5b 73 74 72 69 6e 67 20 6c 61 73 74 20 22 2f 22  [string last "/"
0570: 20 24 70 61 74 68 5d 2d 31 5d 5d 0a 7d 0a 0a      $path]-1]].}..