File: textencode.tf

package info (click to toggle)
tf5 5.0beta8-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,976 kB
  • sloc: ansic: 25,499; perl: 103; makefile: 79; sh: 70
file content (25 lines) | stat: -rw-r--r-- 688 bytes parent folder | download | duplicates (7)
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
;;;; $Id: textencode.tf,v 35000.2 2003/12/08 03:47:03 hawkeye Exp $
;;;; Encode/decode text to/from a form containing only letters, digits, and
;;;; underscores.

/loaded __TFLIB__/textencode.tf

/def -i textencode = \
    /let src=%; \
    /let dst=%; \
    /test src:={*}%; \
    /while (regmatch("[^a-zA-Z0-9]", src)) \
	/test dst := strcat(dst, {PL}, '_', ascii({P0}), '_')%; \
	/test src := {PR}%; \
    /done%; \
    /result strcat(dst, src)

/def -i textdecode = \
    /let src=%; \
    /let dst=%; \
    /test src:={*}%; \
    /while (regmatch("_([0-9]+)_", src)) \
	/test dst := strcat(dst, {PL}, char({P1}))%; \
	/test src := {PR}%; \
    /done%; \
    /result strcat(dst, src)