aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/string.tes
blob: 93568e131de00992ee73689e5b476aaa1d96093d (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
! String utility macros !

! <pos1,pos2>M[symcasecmp] - Compare symbol at pos1 with symbol at pos2 (caseless) !
@[symcasecmp]{
  U.2U.1 -.%.1 -.%.2
  @.#lo{
    U.v Q.v"W a-A%.v | Q.v"CQ.v|0' '
  }
  <Q.1A:M.#loU.a Q.2A:M.#loU.b
    Q.a-Q.bU.c Q.c"N1;' -Q.a;
  %.1%.2>
  Q.c
}

! <i,j>M[exchange] - Exchange line at I with line at J (I < J), returning new J !
@[exchange]{
  U.jU.i
  Q.jJ X.xK
  Q.iJ G.x .-Q.i%.j .-(X.xL.)%.j -K
  Q.jJ G.x
  Q.j
}

! <i,j>M[qsort] - Sort lines beginning at I until J using Quicksort algorithm !
@[qsort]{
  U.rU.l

  Q.l-Q.r"<
    Q.lU.i Q.rJB .U.j

    <
      Q.iJ <.,Q.rM[symcasecmp]-1; .-Q.r;    L> .U.i
      Q.jJ <.,Q.rM[symcasecmp]:;  .-Q.l-1:; B> .U.j

      Q.i-Q.j;

      Q.i,Q.jM[exchange]U.j
    >

    Q.i,Q.rM[symcasecmp]"> Q.i,Q.rM[exchange]U.r '

    Q.l-Q.i"< Q.iJB Q.l,.M[qsort] '
    Q.i-Q.r"< Q.iJL .,Q.rM[qsort] '
  '
}