:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: : method ENCODE.PHONE: Determine phone number encodings. change Map..Heap..string :Dictionary map from number -> {code, ...} entry Number string, &Original phone number for display. Digit string, &Phone number digits before the prefix. Encode string, &Encoded name so far. Index word :Index past the the prefix. exit Partial Bit :Set if any partial matches. local Tail string, &Remaining digits to match I word :Index past encoded digits, : :............................................................................... Tail = chop( Digit, Index - 1 ); Remaining digits to match. DO @Pair from Partial( $, Tail ): DO over partial matches to the digits, DO Code from Pair`Tag: DO over code word encodings, IF Encode$: IF any prior encoding, Code = Encode$ ! " " ! Code; Add a code word. . I = Index + length( Pair`Key ); Index past digits consumed. IF I > length( Digit ): IF all consumed, PRINT Number ! ":", Code; Phone number with encoding ELSE: ELSE more trailing digits, ENCODE.PHONE $, Number, Digit, &Encode with trailing digits. Code, I, Partial IF Partial = 0: IF no encoding, Code != " " ! string{ Digit, I }; Encode with lead digit. IF I = length( Digit ): IF one last digit, PRINT Number ! ":", Code; Phone numbers with encoding ELSE: ELSE no full encoding, ENCODE.PHONE $, Number, Digit, &Encode with a lead digit. Code, I + 1, Partial - . . . Partial = 1; Exact encoding also covers partial. - return