{"id":6264,"date":"2022-12-20T18:58:04","date_gmt":"2022-12-20T21:58:04","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/prefix-mann\/"},"modified":"2022-12-20T18:58:04","modified_gmt":"2022-12-20T21:58:04","slug":"prefix-mann","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/prefix-mann\/","title":{"rendered":"prefix (mann)"},"content":{"rendered":"<h1 align=\"center\">prefix<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#KEYWORDS\">KEYWORDS<\/a> <\/p>\n<hr>\n<p>______________________________________________________________________________<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">tcl::prefix \u2212 facilities for prefix matching<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>::tcl::prefix all<\/b> <i>table string<\/i> <b><br \/> ::tcl::prefix longest<\/b> <i>table string<\/i> <b><br \/> ::tcl::prefix match<\/b> <i>?option &#8230;? table string<\/i> ______________________________________________________________________________<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This document describes commands looking up a prefix in a list of strings. The following commands are supported: <b><br \/> ::tcl::prefix all<\/b> <i>table string<\/i><\/p>\n<p style=\"margin-left:22%;\">Returns a list of all elements in <i>table<\/i> that begin with the prefix <i>string<\/i>.<\/p>\n<p style=\"margin-left:11%;\"><b>::tcl::prefix longest<\/b> <i>table string<\/i><\/p>\n<p style=\"margin-left:22%;\">Returns the longest common prefix of all elements in <i>table<\/i> that begin with the prefix <i>string<\/i>.<\/p>\n<p style=\"margin-left:11%;\"><b>::tcl::prefix match<\/b> ?<i>options<\/i>? <i>table string<\/i><\/p>\n<p style=\"margin-left:22%;\">If <i>string<\/i> equals one element in <i>table<\/i> or is a prefix to exactly one element, the matched element is returned. If not, the result depends on the <b>\u2212error<\/b> option. (It is recommended that the <i>table<\/i> be sorted before use with this subcommand, so that the list of matches presented in the error message also becomes sorted, though this is not strictly necessary for the operation of this subcommand itself.) <b><br \/> \u2212exact<\/b><\/p>\n<p style=\"margin-left:32%;\">Accept only exact matches.<\/p>\n<p style=\"margin-left:22%;\"><b>\u2212message<\/b> <i>string<\/i><\/p>\n<p style=\"margin-left:32%;\">Use <i>string<\/i> in the error message at a mismatch. Default is \u201coption\u201d.<\/p>\n<p style=\"margin-left:22%;\"><b>\u2212error<\/b> <i>options<\/i><\/p>\n<p style=\"margin-left:32%;\">The <i>options<\/i> are used when no match is found. If <i>options<\/i> is empty, no error is generated and an empty string is returned. Otherwise the <i>options<\/i> are used as <b>return<\/b> options when generating the error message. The default corresponds to setting \u201c\u2212level 0\u201d. Example: If \u201c<b>\u2212error<\/b> {\u2212errorcode MyError \u2212level 1}\u201d is used, an error would be generated as:<\/p>\n<p style=\"margin-left:43%; margin-top: 1em\">return \u2212errorcode MyError \u2212level 1 \u2212code error  <br \/> &#8220;ambiguous option &#8230;&#8221;<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Basic use:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">namespace import ::tcl::prefix <b><br \/> prefix match<\/b> {apa bepa cepa} apa <i><br \/> \u2192 apa<\/i> <b><br \/> prefix match<\/b> {apa bepa cepa} a <i><br \/> \u2192 apa<\/i> <b><br \/> prefix match<\/b> \u2212exact {apa bepa cepa} a <i><br \/> \u2192 bad option &#8220;a&#8221;: must be apa, bepa, or cepa<\/i> <b><br \/> prefix match<\/b> \u2212message &#8220;switch&#8221; {apa ada bepa cepa} a <i><br \/> \u2192 ambiguous switch &#8220;a&#8221;: must be apa, ada, bepa, or cepa<\/i> <b><br \/> prefix longest<\/b> {fblocked fconfigure fcopy file fileevent flush} fc <i><br \/> \u2192 fco<\/i> <b><br \/> prefix all<\/b> {fblocked fconfigure fcopy file fileevent flush} fc <i><br \/> \u2192 fconfigure fcopy<\/i><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Simplifying option matching:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">array set opts {\u2212apa 1 \u2212bepa &#8220;&#8221; \u2212cepa 0} <br \/> foreach {arg val} $args { <br \/> set opts([<b>prefix match<\/b> {\u2212apa \u2212bepa \u2212cepa} $arg]) $val <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Creating a <b>switch<\/b> that supports prefixes:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">switch [<b>prefix match<\/b> {apa bepa cepa} $arg] { <br \/> apa { } <br \/> bepa { } <br \/> cepa { } <br \/> }<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">lsearch(n), namespace(n), string(n), Tcl_GetIndexFromObj(3)<\/p>\n<h2>KEYWORDS <a name=\"KEYWORDS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">prefix, table lookup<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  tcl::prefix \u2212 facilities for prefix matching <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3783,1],"tags":[2635,2878],"class_list":["post-6264","post","type-post","status-publish","format-standard","hentry","category-n-comandos-tcl-tk","category-sin-categoria","tag-mann","tag-tcl_prefix"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6264"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6264\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}