RosettaCodeData/Task/Abbreviations-simple/00-TASK.txt

91 lines
5.2 KiB
Plaintext

The use of   abbreviations   (also sometimes called synonyms, nicknames, AKAs, or aliases)   can be an
<br>easy way to add flexibility when specifying or using commands, sub─commands, options, etc.
<!--
(AKA = also known as)
!-->
For this task, the following &nbsp; ''command table'' &nbsp; will be used:
add 1 alter 3 backup 2 bottom 1 Cappend 2 change 1 Schange Cinsert 2 Clast 3
compress 4 copy 2 count 3 Coverlay 3 cursor 3 delete 3 Cdelete 2 down 1 duplicate
3 xEdit 1 expand 3 extract 3 find 1 Nfind 2 Nfindup 6 NfUP 3 Cfind 2 findUP 3 fUP 2
forward 2 get help 1 hexType 4 input 1 powerInput 3 join 1 split 2 spltJOIN load
locate 1 Clocate 2 lowerCase 3 upperCase 3 Lprefix 2 macro merge 2 modify 3 move 2
msg next 1 overlay 1 parse preserve 4 purge 3 put putD query 1 quit read recover 3
refresh renum 3 repeat 3 replace 1 Creplace 2 reset 3 restore 4 rgtLEFT right 2 left
2 save set shift 2 si sort sos stack 3 status 4 top transfer 3 type 1 up 1
<!--
The unsorted list (above) was constructed to help ensure that program entries don't get tripped up by performing a straight left-to-right string comparison.
!-->
<!--
For the curious amongst you (and pack-rats of old publications, this is an old XEDIT command table; the sub-commands were extracted from:
Virtual Machine/
System Product
System Product
SP Editor
Command
Language
Reference
Summary
Release 4
SX24-5122-3
Fourth Edition (December 1984)
Information herein is extracted from
Virtual Machine/System Product System Product Editor Command and Macro Reference, SC24-5221.
This old version does not have some of the newer commands like QQuit and PQUIT, for instance,
and those commands that deal with DBCS (double-byte character set).
!-->
Notes concerning the above &nbsp; ''command table'':
::* &nbsp; it can be thought of as one long literal string &nbsp; (with blanks at end-of-lines)
::* &nbsp; it may have superfluous blanks
::* &nbsp; it may be in any case (lower/upper/mixed)
::* &nbsp; the order of the words in the &nbsp; ''command table'' &nbsp; must be preserved as shown
::* &nbsp; the user input(s) may be in any case (upper/lower/mixed)
::* &nbsp; commands will be restricted to the Latin alphabet &nbsp; (A ──► Z, &nbsp; a ──► z)
::* &nbsp; a command is followed by an optional number, which indicates the minimum abbreviation
::* &nbsp; A valid abbreviation is a word that has:
:::* &nbsp; at least the minimum length of the word's minimum number in the ''command table''
:::* &nbsp; compares equal (regardless of case) to the leading characters of the word in the ''command table''
:::* &nbsp; a length <u>not</u> longer than the word in the ''command table''
::::* &nbsp; '''ALT''', &nbsp; '''aLt''', &nbsp; '''ALTE''', &nbsp; and &nbsp; '''ALTER''' &nbsp; are all abbreviations of &nbsp; '''ALTER 3'''
::::* &nbsp; '''AL''', &nbsp; '''ALF''', &nbsp; '''ALTERS''', &nbsp; '''TER''', &nbsp; and &nbsp; '''A''' &nbsp; <u>aren't</u> valid abbreviations of &nbsp; '''ALTER 3'''
::::* &nbsp; The &nbsp; '''3''' &nbsp; indicates that any abbreviation for &nbsp; '''ALTER''' &nbsp; must be at least three characters
::::* &nbsp; Any word longer than five characters <u>can't</u> be an abbreviation for &nbsp; '''ALTER'''
::::* &nbsp; '''o''', &nbsp; '''ov''', &nbsp; '''oVe''', &nbsp; '''over''', &nbsp; '''overL''', &nbsp; '''overla''' &nbsp; are all acceptable abbreviations for &nbsp; '''overlay 1'''
::* &nbsp; if there isn't a number after the command, &nbsp; then there isn't an abbreviation permitted
<!--
::* &nbsp; a Latin alphabet is used for this Rosetta Code task because it behaves well when letters are uppercased
!-->
;Task:
::* &nbsp; The command table needn't be verified/validated.
::* &nbsp; Write a function to validate if the user "words" &nbsp; (given as input) &nbsp; are valid &nbsp; (in the ''command table'').
::* &nbsp; If the word &nbsp; is &nbsp; valid, &nbsp; then return the full uppercase version of that "word".
::* &nbsp; If the word isn't valid, &nbsp; then return the lowercase string: &nbsp; <big> '''*error*''' </big> &nbsp; &nbsp; &nbsp; (7 characters).
::* &nbsp; A blank input &nbsp; (or a null input) &nbsp; should return a null string.
::* &nbsp; Show all output here.
;An example test case to be used for this task:
For a user string of:
riG rePEAT copies put mo rest types fup. 6 poweRin
the computer program should return the string:
RIGHT REPEAT *error* PUT MOVE RESTORE *error* *error* *error* POWERINPUT
{{Template:Strings}}
<br><br>