string - Factor Documentation (original) (raw)
Class description
The class of fixed-length character strings. See Character and string syntax for syntax and Strings for general information.
BUILTIN: string
{ length array-capacity read-only initial: 0 } aux ;
USING: help.markup io strings ;
USING: core-foundation.strings core-foundation.utilities strings
;
USING: kernel strings yaml.private ;
M: string (deref-aliases) nip ;
M: string (parse-factor-quotation) ast-string boa ;
USING: kernel strings yaml.private ;
M: string (replace-aliases) nip ;
USING: kernel strings yaml.private ;
M: string (replace-anchors) nip ;
USING: combinators kernel namespaces strings vocabs
vocabs.loader vocabs.loader.private ;
M: string (require)
dup check-vocab-hook get ( vocab -- ) call-effect
create-vocab (require) ;
USING: io io.encodings.string io.encodings.utf8 kernel sequences
serialize serialize.private strings ;
M: string (serialize)
[
115 write1
[ add-object ]
[ utf8 encode [ length serialize-cell ] [ write ] bi ]
bi
] serialize-shared ;
USING: accessors assocs kernel mongodb.tuple.collection
mongodb.tuple.collection.private strings ;
M: string
collection-map [ ] [ key? ] 2bi
[ at ] [
[ mdb-tuple-collection new dup ] 2dip
[ [ >>name ] keep ] dip set-at
] if ; inline
USING: help.lint.coverage help.lint.coverage.private strings ;
USING: bencode kernel math.parser sequences strings ;
M: string >bencode [ length number>string ":" ] keep 3append ;
USING: accessors arrays asn1 byte-arrays kernel namespaces pack
sequences strings ;
M: string >ber
tagnum get value>> 1array "C" pack-native
swap dup length >ber-length-encoding swapd append
swap >byte-array append ;
USING: ascii poker.private sequences strings ;
M: string >ckf >upper 1 cut (>ckf) ;
USING: arrays io.servers io.servers.private strings ;
M: string >insecure internet-server 1array ;
USING: ip-parser kernel math.parser splitting strings ;
M: string >ipv4-network
"/" split1 [ ipv4-aton ] [ string>number ] bi*
ipv4-network boa ;
USING: ip-parser kernel math.parser splitting strings ;
M: string >ipv6-network
"/" split1 [ ipv6-aton ] [ string>number ] bi*
ipv6-network boa ;
USING: strings ui.gadgets.labels ;
USING: accessors command-line.parser command-line.parser.private
kernel strings ;
M: string >option option new swap >>name ;
USING: accessors http http.client.post-data io.encodings.string
io.encodings.utf8 kernel strings ;
M: string >post-data
utf8 encode
"application/octet-stream" swap >>data ;
USING: python python.errors python.ffi strings ;
M: string >py PyUnicode_FromString check-new-ref ;
USING: combinators.short-circuit kernel math math.parser semver
sequences splitting strings ;
M: string >semver
dup "+" split1 [ "-" split1 ] dip [
"." split [ string>number ] map dup
{ [ length 3 = ] [ [ integer? ] all? ] } 1&&
[ nip first3 ] [ drop malformed-semver ] if
] 2dip semver boa ;
USING: strings txon txon.private ;
M: string >txon encode-value ;
USING: accessors ascii combinators kernel sequences
sequences.generalizations strings urls urls.private ;
M: string >url
[ ] dip parse-url 5 firstn {
[ >lower >>protocol ]
[
[
[
first
[ first2 ~quotation~ ~quotation~ bi* ] when*
] [
second
[ first2 ~quotation~ ~quotation~ bi* ] when*
] bi
] when*
]
[ >>path ]
[ >>query ]
[ >>anchor ]
} spread dup host>> [ [ "/" or ] change-path ] when ;
USING: inverse kernel strings xml.syntax.inverse ;
M: string [undo-xml] [ =/fail ] curry ;
USING: combinators io.pathnames namespaces splitting strings ;
M: string absolute-path
{
{
[ "resource:" ?head ]
[ trim-head-separators resource-path absolute-path ]
}
{
[ "vocab:" ?head ]
[ trim-head-separators vocab-path absolute-path ]
}
{
[ "~" ?head ]
[
trim-head-separators home prepend-path
absolute-path
]
}
[ current-directory get prepend-path ]
} cond ;
USING: strings tools.coverage ;
M: string add-coverage [ add-coverage ] each-word ;
USING: kernel strings tools.scaffold.private ;
USING: furnace.utilities strings ;
M: string adjust-redirect-url ;
USING: furnace.utilities strings ;
USING: accessors irc.client.internals kernel strings ;
M: string annotate-message [ name>> ] dip strings>privmsg ;
USING: kernel strings yaml.private ;
M: string apply-merge-keys nip ;
USING: accessors generic io.encodings.ascii.private
io.encodings.private kernel strings ;
M: string ascii>
dup aux>>
[ M\ string ascii> (call-next-method) ]
[ string>byte-array-fast ] if ; inline
USING: bencode io.streams.string strings ;
M: string bencode> [ read-bencode ] with-string-reader ;
USING: kernel sequences.deep strings ;
USING: html.templates io strings ;
M: string call-template* write ;
USING: cbor io.streams.string strings ;
M: string cbor> [ read-cbor ] with-string-reader ;
USING: math.functions sequences strings
ui.gadgets.tables.private ui.text ;
M: string cell-dim single-line text-dim first2 ceiling 0 ;
USING: irc.client.base irc.client.chats irc.client.internals
kernel strings ;
M: string chat-put chat> +server-chat+ or chat-put ;
USING: accessors assocs irc.client.base strings ;
M: string chat> irc> chats>> at ;
USING: accessors kernel strings ;
M: string clone (clone) [ clone ] change-aux ; inline
USING: generic kernel sequences strings ;
M: string clone-like
over string?
[ drop clone ] [ M\ string clone-like (call-next-method) ]
if ; inline
USING: sequences strings tools.coverage tools.coverage.private ;
M: string count-callables [ count-callables ] map-words sum ;
USING: arrays kernel strings tools.coverage ;
M: string coverage [ dup coverage 2array ] map-words ;
USING: strings tools.coverage ;
M: string coverage. [ coverage. ] each-word ;
USING: mongodb.driver strings ;
M: string create-collection create-collection ;
M: string deck-and-sideboard.
parse-mtga-deck deck-and-sideboard. ;
M: string deck. parse-mtga-deck deck. ;
M: string deps get-npm-json deps ;
M: string dev-deps get-npm-json dev-deps ;
M: string dispatch-message
"unhandled string: " gwrite gwrite g... ;
USING: arrays kernel strings tools.dns ;
M: string dns-host [ 1array ] dip dns-host ;
USING: docker kernel sequences strings ;
M: string docker-pull { "pull" } swap suffix docker-command ;
USING: formatting graphviz.dot.private strings ;
M: string dot. quote-string "%s " printf ;
USING: http.download strings urls ;
M: string download-to-temporary-file
>url download-to-temporary-file ;
USING: strings ui.gadgets.tables.private ui.text ;
M: string draw-cell single-line draw-text ;
USING: strings ui.text ui.text.private ;
M: string draw-text draw-string ;
USING: drunken-bishop hex-strings strings ;
M: string drunken-bishop. hex-string>bytes drunken-bishop. ;
M: string emit-value emit-scalar ;
USING: accessors generic io.encodings.utf16.private kernel
strings ;
M: string encode-string-utf16be
over aux>>
[ M\ string encode-string-utf16be (call-next-method) ]
[ ascii-string>utf16be ] if ; inline
USING: accessors generic io.encodings.utf16.private kernel
strings ;
M: string encode-string-utf16le
over aux>>
[ M\ string encode-string-utf16le (call-next-method) ]
[ ascii-string>utf16le ] if ; inline
USING: accessors generic io io.encodings.private
io.encodings.utf8.private kernel strings ;
M: string encode-string-utf8
over aux>>
[ M\ string encode-string-utf8 (call-next-method) ]
[ [ string>byte-array-fast ] dip stream-write ] if ; inline
USING: kernel sequences strings ;
M: string equal?
over string? [
over hashcode over hashcode eq?
[ sequence= ] [ 2drop f ] if
] [ 2drop f ] if ;
USING: io.files.info.unix.private kernel math.bitwise strings ;
M: string file-mode? [ stat-mode ] dip mask? ;
USING: destructors pcre2 pcre2.private strings ;
M: string findall [ findall ] with-disposal ;
M: string fjsc-parse expression-parser parse ;
USING: fuel.pprint prettyprint strings ;
M: string fuel-pprint pprint ; inline
USING: accessors io.sockets random strings tftp ;
M: string get-tftp-host resolve-host random host>> 69 ;
USING: kernel strings unix unix.ffi unix.groups
unix.groups.private ;
M: string group-struct
(group-struct) [ [ getgrnam_r ] unix-system-call drop ] keep
check-group-struct ;
USING: irc.client.internals irc.messages.parser strings ;
M: string handle-input
string>irc-message handle-reader-message t ;
USING: kernel strings strings.private ;
M: string hashcode*
nip
[ string-hashcode ] [ dup rehash-string string-hashcode ]
?unless ;
USING: io.encodings.string io.encodings.utf8 strings
tools.hexdump ;
M: string hexdump. utf8 encode hexdump. ;
USING: io.encodings.utf8 io.files kernel sequences strings
xmode.catalog xmode.highlight ;
M:: string highlight. ( path -- )
path utf8 file-lines
[ path over first find-mode highlight-lines ] unless-empty ;
USING: math.order sorting.quick strings ;
M: string inv-sort! [ <=> ] inv-sort-with! ;
USING: strings xml-rpc xml.data xml.syntax.private ;
M: string item>xml
1 nenum T{ xml-chunk
{ seq
V{
""
T{ tag { name ~name~ } { children ~vector~ } }
""
}
}
} interpolate-xml ;
USING: io.streams.string json json.private strings ;
M: string json> [ read-jsons get-json ] with-string-reader ;
USING: io.streams.string json strings ;
M: string jsonlines> [ read-jsonlines ] with-string-reader ;
USING: accessors sequences strings ;
M: string length length>> ; inline
USING: alien.libraries strings ;
M: string library-dll lookup-library library-dll ;
USING: accessors kernel sbufs sequences strings strings.private
;
M: string like
drop dup string? [
dup sbuf? [
[ length ] [ underlying>> ] bi 2dup length eq?
[ nip dup reset-string-hashcode ] [ resize-string ]
if
] [ >string ] if
] unless ; inline
USING: html.components strings ;
USING: html.components strings ;
USING: accessors kernel strings ui.gadgets ui.gadgets.editors
ui.tools.listener ;
M: string listener-input
get-listener input>>
[ set-editor-string ] [ request-focus ] bi ;
USING: images.loader io.encodings.binary io.files kernel strings
;
M: string load-image*
[ binary ] dip stream>image ;
USING: bittorrent io.pathnames kernel sequences strings urls ;
M: string load-metainfo
dup "http" head? [ >url ] [ ] if load-metainfo ;
USING: game.models.loader game.models.loader.private kernel
strings ;
M: string load-models* [ open-models-file ] dip stream>models ;
USING: help.lint.coverage.private kernel strings vocabs ;
M: string loaded-vocab? lookup-vocab >boolean ;
USING: geo-ip ip-parser strings ;
M: string lookup-ip ipv4-aton lookup-ip ;
USING: accessors kernel slots strings ;
M: string make-slot swap >>name ;
USING: assocs formatting kernel math math.parser sequences
strings ui.tools.inspector unicode ;
M: string make-slot-descriptions
[
swap [ dup number>string ] dip dup dup printable?
[ 1string ] [
dup 255 <= [
H{
{ 0 "\\0" }
{ 7 "\\a" }
{ 8 "\\b" }
{ 9 "\\t" }
{ 10 "\\n" }
{ 27 "\\e" }
{ 12 "\\f" }
{ 13 "\\r" }
{ 11 "\\v" }
} ?at [ "\\x%02x" sprintf ] unless
] [ "\\u{%x}" sprintf ] if
] if slot-description boa
] { } map-index-as ;
USING: formatting http.client kernel metar strings ;
M: string metar
"https://tgftp.nws.noaa.gov/data/observations/metar/stations/%..."
sprintf http-get nip ;
USING: continuations formatting kernel metar metar.private
strings ;
M: string metar.
[ metar metar-report. ]
[ drop "%s METAR not found\n" printf ] recover ;
USING: io.streams.string msgpack strings ;
M: string msgpack> [ read-msgpack ] with-string-reader ;
USING: kernel sbufs sequences strings ;
M: string new-resizable drop ; inline
USING: kernel sequences strings ;
M: string new-sequence drop 0 ; inline
USING: kernel math sequences.private strings strings.private ;
M: string nth-unsafe [ integer>fixnum ] dip string-nth ; inline
USING: math.combinatorics.private strings ;
M: string nths-unsafe (nths-unsafe) ;
USING: crontab splitting strings ;
M: string parse-crontab split-lines parse-crontab ;
USING: strings syndication xml xml.entities.html ;
M: string parse-feed
[ string>xml xml>feed ] with-html-entities ;
USING: gitignore splitting strings ;
M: string parse-gitignore split-lines parse-gitignore ;
USING: pdf.values pdf.values.private sequences strings ;
M: string pdf-value escape-string "(" ")" surround ;
USING: elevate.unix.private splitting strings ;
M: string posix-replace-process
" " split posix-replace-process ;
USING: kernel prettyprint.backend prettyprint.custom strings ;
M: string pprint* dup "\"" "\"" pprint-string ;
USING: json json.prettyprint.private strings ;
M: string pprint-json* write-json ;
USING: prettyprint.sections see.private strings ;
M: string pprint-slot-name text ;
USING: bootstrap.image.private strings ;
M: string prepare-object [ emit-string ] cache-eql-object ;
USING: elevate.private kernel sequences strings ;
M: string prepend-command swap " " glue ;
USING: help.markup io strings ;
M: string print-element [ write ] ($span) ;
USING: make strings xml.syntax.private ;
USING: http.server.redirection strings ;
M: string relative-to-request ;
USING: strings tools.coverage ;
M: string remove-coverage [ remove-coverage ] each-word ;
USING: strings yaml.conversion ;
USING: combinators kernel namespaces sets splitting strings
vocabs vocabs.private ;
M: string require
[ ".private" ?tail ] 1check [ lookup-vocab not ] when [
[
dupd ?adjoin
[ require-hook get ( name -- ) call-effect ]
[ drop ] if
] with-requiring
] [ drop ] if ;
USING: strings tools.coverage ;
M: string reset-coverage [ reset-coverage ] each-word ;
USING: sequences.private strings ;
M: string resize resize-string ; inline
USING: alien.c-types alien.data classes.struct io.sockets
io.sockets.private kernel math strings unix.ffi ;
M:: string resolve-host ( host -- seq )
host f prepare-addrinfo f void* [
getaddrinfo
[ dup addrinfo-error-string host addrinfo-error ]
unless-zero
] keep void* deref addrinfo memory>struct
[ parse-addrinfo-list ] keep freeaddrinfo ;
USING: kernel strings tools.scaffold tools.scaffold.private ;
M: string scaffold-docs
ensure-vocab-exists [
dup "-docs.factor" vocab/suffix>path scaffolding?
[ set-scaffold-docs-file ] [ 2drop ] if
] with-scaffold ;
USING: strings unix.groups unix.groups.private ;
M: string set-effective-group ?group-id (set-effective-group) ;
USING: strings unix.users unix.users.private ;
M: string set-effective-user ?user-id (set-effective-user) ;
USING: io.files.info.unix kernel strings unix.groups ;
M: string set-file-group group-id f swap set-file-ids ;
USING: io.files.info.unix strings unix.users ;
M: string set-file-user user-id f set-file-ids ;
USING: accessors combinators.short-circuit images.http
images.loader images.viewer kernel sequences strings ;
M: string set-image
dup { [ "https://" head? ] [ "https://" head? ] } 1||
[ load-http-image ] [ load-image ] if >>image ;
USING: kernel math sequences.private strings strings.private ;
M: string set-nth-unsafe
dup reset-string-hashcode
[ integer>fixnum ] [ integer>fixnum ] [ ] tri*
set-string-nth ; inline
USING: strings unix.groups unix.groups.private ;
M: string set-real-group ?group-id (set-real-group) ;
USING: strings unix.users unix.users.private ;
M: string set-real-user ?user-id (set-real-user) ;
USING: escape-strings splitting strings ;
M: string sha1-escape-strings split-lines sha1-escape-strings ;
USING: kernel make sequences smalltalk.printer strings ;
M: string smalltalk>string
[ "'" % [ dup 39 = [ dup , , ] [ , ] if ] each "'" % ] ""
make ;
USING: math.order sorting.quick strings ;
M: string sort! [ <=> ] sort-with! ;
USING: kernel math sequences sequences.private splitting
splitting.private strings ;
M:: string split-lines ( seq -- seq' )
seq length :> len V{ } clone 0
[ dup len < ] [
dup seq [ linebreak? ] find-from
[ len or [ seq subseq-unsafe suffix! ] [ 1 + ] bi ]
[ 13 eq? [ dup seq ?nth 10 eq? [ 1 + ] when ] when ] bi*
] while drop { } like ; inline
USING: combinators io json json.private kernel namespaces
sequences strings ;
M: string stream-write-json
34 over stream-write1 swap [
{
{ 34 [ "\\\"" over stream-write ] }
{ 92 [ "\\\\" over stream-write ] }
{
47
[
json-escape-slashes? get
[ "\\/" over stream-write ]
[ 47 over stream-write1 ] if
]
}
{ 8 [ "\\b" over stream-write ] }
{ 12 [ "\\f" over stream-write ] }
{ 10 [ "\\n" over stream-write ] }
{ 13 [ "\\r" over stream-write ] }
{ 9 [ "\\t" over stream-write ] }
{ 8232 [ "\\u2028" over stream-write ] }
{ 8233 [ "\\u2029" over stream-write ] }
[
{
{ ~quotation~ ~quotation~ }
{ ~quotation~ ~quotation~ }
[ json-escape-unicode? get ]
} cond
[ write-json-generic-escape ]
[ over stream-write1 ] if
]
} case
] each 34 swap stream-write1 ;
USING: alien.strings alien.strings.private kernel strings ;
M: string string>alien
over check-c-string 2dup fast-string?
[ string>alien-fast ] [ string>alien-slow ] if ;
USING: alien.strings io.encodings.utf8 strings ;
M: string string>symbol utf8 string>alien ;
USING: kernel sequences strings summary ;
M: string summary dup length "code points" container-summary ;
USING: formatting http.client kernel metar strings ;
M: string taf
"https://tgftp.nws.noaa.gov/data/forecasts/taf/stations/%s.TXT"
sprintf http-get nip ;
USING: continuations formatting kernel metar metar.private
strings ;
M: string taf.
[ taf taf-report. ]
[ drop "%s TAF not found\n" printf ] recover ;
USING: strings ui.text ui.text.private ;
M: string text-dim string-dim ;
USING: strings unix.groups unix.groups.private ;
M: string user-groups (user-groups) ;
USING: kernel strings unix.ffi unix.users ;
M: string user-passwd getpwnam dup [ passwd>new-passwd ] when ;
USING: assocs io kernel mongodb.cmd mongodb.connection
mongodb.driver strings ;
M: string validate.
[ validate-cmd make-cmd ] dip "validate" set-cmd-opt
send-cmd [ check-ok nip ] keep [ [ "result" ] ] dip
[ at print ] curry compose [ ] if ;
USING: combinators io.pathnames kernel sequences strings
vocabs.loader.private ;
M: string vocab-path
dup find-root-for
[ prepend-path ] [
{
{
[ dup ?last path-separator? ]
[ find-root-for-vocab-pathname ]
}
{
[ dup has-file-extension? ]
[
[
ensure-parent-directory-is-not-dot
find-root-for-vocab-pathname
] [ file-name ] bi append-path
]
}
[ find-root-for-vocab-pathname ]
} cond
] if* ;
USING: io.pathnames namespaces sequences strings
tools.scaffold.private vocabs.loader ;
M: string vocab-root?
trim-tail-separators vocab-roots get member? ;
USING: combinators modern.html strings ;
M: string walk-html ( obj -- ) call-effect ;
M: string where object-where ;
USING: cbor cbor.private io io.encodings.string
io.encodings.utf8 kernel sequences strings ;
M: string write-cbor
dup length 3 write-integer utf8 encode write ;
USING: csexp io kernel math.parser sequences strings ;
M: string write-csexp
dup length number>string write 58 write1 write ;
USING: gml.printer io strings ;
M: string write-gml "\"" write write "\"" write ;
USING: make modern.html strings ;
USING: combinators endian io io.encodings io.encodings.utf8
kernel math msgpack namespaces sequences strings ;
M: string write-msgpack
dup length {
{ [ dup 31 <= ] [ 160 bitor write1 ] }
{ [ dup 255 <= ] [ 217 write1 write1 ] }
{ [ dup 65535 <= ] [ 218 write1 2 >be write ] }
{ [ dup 4294967295 <= ] [ 219 write1 4 >be write ] }
[ cannot-convert ]
} cond output-stream get utf8 encode-string ;
USING: html.components.private io strings ;
M: string write-nested write ;
USING: help.lint.coverage.private io strings ;
M: string write-object* write ;
M: string write-ptx-operand write ;
USING: formatting kernel redis.command-writer.private sequences
strings ;
M: string write-resp [ length ] keep "$%s\r\n%s\r\n" printf ;
USING: make modern.html sequences strings unicode ;
M: string write-string [ blank? ] trim [ % ] unless-empty ;
USING: io kernel namespaces sequences strings unicode
wrap.strings xml.entities xml.writer xml.writer.private ;
M: string write-xml
escape-string xml-pprint? get [
dup [ blank? ] all?
[ drop "" ] [ nl 80 indent-string wrap-indented-string ]
if
] when write ;
USING: combinators kernel modern.html strings ;
M: string xml-find-by
2dup ( obj -- ? ) call-effect [ drop ] [ 2drop f ] if ;