From 34c0cf61113ee18a774b48d599048210fb69e215 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 9 Jul 2008 19:43:46 -0500 Subject: [PATCH] Use tr instead of substitute in a few places --- extra/io/windows/nt/files/files.factor | 6 ++++-- extra/json/writer/writer.factor | 7 ++----- extra/sequences/lib/lib.factor | 3 --- extra/tools/disassembler/disassembler.factor | 5 ++--- extra/tools/vocabs/monitor/monitor.factor | 10 +++++++--- extra/ui/commands/commands.factor | 6 ++++-- extra/unicode/data/data.factor | 2 +- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/extra/io/windows/nt/files/files.factor b/extra/io/windows/nt/files/files.factor index 2a39cea479..6a890f6392 100755 --- a/extra/io/windows/nt/files/files.factor +++ b/extra/io/windows/nt/files/files.factor @@ -4,7 +4,7 @@ io.windows.nt.backend windows windows.kernel32 kernel libc math threads system alien.c-types alien.arrays alien.strings sequences combinators combinators.short-circuit ascii splitting alien strings -assocs namespaces io.files.private accessors ; +assocs namespaces io.files.private accessors tr ; IN: io.windows.nt.files M: winnt cwd @@ -40,9 +40,11 @@ ERROR: not-absolute-path ; unicode-prefix prepend ] unless ; +TR: normalize-separators "/" "\\" ; + M: winnt normalize-path ( string -- string' ) (normalize-path) - { { CHAR: / CHAR: \\ } } substitute + normalize-separators prepend-prefix ; M: winnt CreateFile-flags ( DWORD -- DWORD ) diff --git a/extra/json/writer/writer.factor b/extra/json/writer/writer.factor index a68c65087e..0d22494b13 100644 --- a/extra/json/writer/writer.factor +++ b/extra/json/writer/writer.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: kernel io.streams.string io strings splitting sequences math math.parser assocs classes words namespaces prettyprint - hashtables mirrors ; + hashtables mirrors tr ; IN: json.writer #! Writes the object out to a stream in JSON format @@ -24,10 +24,7 @@ M: number json-print ( num -- ) M: sequence json-print ( array -- ) CHAR: [ write1 [ >json ] map "," join write CHAR: ] write1 ; -: jsvar-encode ( string -- string ) - #! Convert the string so that it contains characters usable within - #! javascript variable names. - { { CHAR: - CHAR: _ } } substitute ; +TR: jsvar-encode "-" "_" ; : tuple>fields ( object -- seq ) [ diff --git a/extra/sequences/lib/lib.factor b/extra/sequences/lib/lib.factor index 90bca7cef9..0049320b94 100755 --- a/extra/sequences/lib/lib.factor +++ b/extra/sequences/lib/lib.factor @@ -210,9 +210,6 @@ PRIVATE> : nths ( seq indices -- seq' ) swap [ nth ] curry map ; -: replace ( str oldseq newseq -- str' ) - zip >hashtable substitute ; - : remove-nth ( seq n -- seq' ) cut-slice rest-slice append ; diff --git a/extra/tools/disassembler/disassembler.factor b/extra/tools/disassembler/disassembler.factor index a7d9da4840..4a345e2345 100755 --- a/extra/tools/disassembler/disassembler.factor +++ b/extra/tools/disassembler/disassembler.factor @@ -3,7 +3,7 @@ USING: io.files io words alien kernel math.parser alien.syntax io.launcher system assocs arrays sequences namespaces qualified system math generator.fixup io.encodings.ascii accessors -generic ; +generic tr ; IN: tools.disassembler : in-file ( -- path ) "gdb-in.txt" temp-file ; @@ -36,8 +36,7 @@ M: method-spec make-disassemble-cmd try-process out-file ascii file-lines ; -: tabs>spaces ( str -- str' ) - { { CHAR: \t CHAR: \s } } substitute ; +TR: tabs>spaces "\t" "\s" ; : disassemble ( obj -- ) make-disassemble-cmd run-gdb diff --git a/extra/tools/vocabs/monitor/monitor.factor b/extra/tools/vocabs/monitor/monitor.factor index ee5198a8f4..12b2e41d36 100755 --- a/extra/tools/vocabs/monitor/monitor.factor +++ b/extra/tools/vocabs/monitor/monitor.factor @@ -2,12 +2,16 @@ ! See http://factorcode.org/license.txt for BSD license. USING: threads io.files io.monitors init kernel vocabs vocabs.loader tools.vocabs namespaces continuations -sequences splitting assocs command-line concurrency.messaging io.backend sets ; +sequences splitting assocs command-line concurrency.messaging +io.backend sets tr ; IN: tools.vocabs.monitor +TR: convert-separators "/\\" ".." ; + : vocab-dir>vocab-name ( path -- vocab ) - left-trim-separators right-trim-separators - { { CHAR: / CHAR: . } { CHAR: \\ CHAR: . } } substitute ; + left-trim-separators + right-trim-separators + convert-separators ; : path>vocab-name ( path -- vocab ) dup ".factor" tail? [ parent-directory ] when ; diff --git a/extra/ui/commands/commands.factor b/extra/ui/commands/commands.factor index 6a5a4d2c42..39eed24ada 100755 --- a/extra/ui/commands/commands.factor +++ b/extra/ui/commands/commands.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays definitions kernel sequences strings math assocs words generic namespaces assocs quotations splitting -ui.gestures unicode.case unicode.categories ; +ui.gestures unicode.case unicode.categories tr ; IN: ui.commands SYMBOL: +nullary+ @@ -50,8 +50,10 @@ GENERIC: command-word ( command -- word ) swap pick commands set-at update-gestures ; +TR: convert-command-name "-" " " ; + : (command-name) ( string -- newstring ) - { { CHAR: - CHAR: \s } } substitute >title ; + convert-command-name >title ; M: word command-name ( word -- str ) name>> diff --git a/extra/unicode/data/data.factor b/extra/unicode/data/data.factor index f74e2e0473..fdcf495307 100755 --- a/extra/unicode/data/data.factor +++ b/extra/unicode/data/data.factor @@ -125,7 +125,7 @@ VALUE: properties : process-names ( data -- names-hash ) 1 swap (process-data) [ ascii-lower { { CHAR: \s CHAR: - } } substitute swap - ] assoc-map >hashtable ; + ] H{ } assoc-map-as ; : multihex ( hexstring -- string ) " " split [ hex> ] map sift ;