[476] | 1 | { **************************************************************
|
---|
| 2 | Package: XWB - Kernel RPCBroker
|
---|
| 3 | Date Created: Sept 18, 1997 (Version 1.1)
|
---|
| 4 | Site Name: Oakland, OI Field Office, Dept of Veteran Affairs
|
---|
| 5 | Developers: Danila Manapsal, Don Craven, Joel Ivey
|
---|
| 6 | Description: Functions that emulate MUMPS functions.
|
---|
| 7 | Current Release: Version 1.1 Patch 40 (January 7, 2005))
|
---|
| 8 | *************************************************************** }
|
---|
| 9 |
|
---|
| 10 | unit MFunStr;
|
---|
| 11 |
|
---|
| 12 | interface
|
---|
| 13 |
|
---|
| 14 | uses SysUtils, Dialogs;
|
---|
| 15 |
|
---|
| 16 | {procedure and function prototypes}
|
---|
| 17 | function Piece(x: string; del: string; piece1: integer = 1; piece2: integer=0): string;
|
---|
| 18 | function Translate(passedString, identifier, associator: string): string;
|
---|
| 19 |
|
---|
| 20 | const
|
---|
| 21 | U: string = '^';
|
---|
| 22 |
|
---|
| 23 | implementation
|
---|
| 24 |
|
---|
| 25 | function Translate(passedString, identifier, associator: string): string;
|
---|
| 26 | {TRANSLATE(string,identifier,associator)
|
---|
| 27 | Performs a character-for-character replacement within a string.}
|
---|
| 28 | var
|
---|
| 29 | index, position: integer;
|
---|
| 30 | newString: string;
|
---|
| 31 | substring: string;
|
---|
| 32 |
|
---|
| 33 | begin
|
---|
| 34 | newString := ''; {initialize NewString}
|
---|
| 35 | for index := 1 to length(passedString) do begin
|
---|
| 36 | substring := copy(passedString,index,1);
|
---|
| 37 | position := pos(substring,identifier);
|
---|
| 38 | if position > 0 then
|
---|
| 39 | newString := newString + copy(associator,position,1)
|
---|
| 40 | else
|
---|
| 41 | newString := newString + copy(passedString,index,1)
|
---|
| 42 | end;
|
---|
| 43 | result := newString;
|
---|
| 44 | end;
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | function Piece(x: string; del: string; piece1: integer = 1; piece2: integer=0) : string;
|
---|
| 48 | {PIECE(string,delimiter,piece number)
|
---|
| 49 | Returns a field within a string using the specified delimiter.}
|
---|
| 50 | var
|
---|
| 51 | delIndex,pieceNumber: integer;
|
---|
| 52 | Resval: String;
|
---|
| 53 | Str: String;
|
---|
| 54 | begin
|
---|
| 55 | {initialize variables}
|
---|
| 56 | pieceNumber := 1;
|
---|
| 57 | Str := x;
|
---|
| 58 | {delIndex :=1;}
|
---|
| 59 | if piece2 = 0 then
|
---|
| 60 | piece2 := piece1;
|
---|
| 61 | Resval := '';
|
---|
| 62 | repeat
|
---|
| 63 | delIndex := Pos(del,Str);
|
---|
| 64 | if (delIndex > 0) or ((pieceNumber > Pred(piece1)) and (pieceNumber < (piece2+1))) then begin
|
---|
| 65 | if (pieceNumber > Pred(piece1)) and (pieceNumber < (piece2+1)) then
|
---|
| 66 | begin
|
---|
| 67 | if (pieceNumber > piece1) and (Str <> '') then
|
---|
| 68 | Resval := Resval + del;
|
---|
| 69 | if delIndex > 0 then
|
---|
| 70 | begin
|
---|
| 71 | Resval := Resval + Copy(Str,1,delIndex-1);
|
---|
| 72 | Str := Copy(Str,delIndex+Length(del),Length(Str));
|
---|
| 73 | end
|
---|
| 74 | else
|
---|
| 75 | begin
|
---|
| 76 | Resval := Resval + Str;
|
---|
| 77 | Str := '';
|
---|
| 78 | end;
|
---|
| 79 | end
|
---|
| 80 | else
|
---|
| 81 | Str := Copy(Str,delIndex+Length(del),Length(Str));
|
---|
| 82 | end
|
---|
| 83 | else if Str <> '' then
|
---|
| 84 | Str := '';
|
---|
| 85 | inc(pieceNumber);
|
---|
| 86 | until (pieceNumber > piece2);
|
---|
| 87 | Result := Resval;
|
---|
| 88 | end;
|
---|
| 89 | end.
|
---|