home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
-
- STRLINK OBJECT
- Version 1.00
- 28 August 1989
-
- Rob Rosenberger
- Barn Owl Software
- P.O. Box 74
- O'Fallon, IL 66269
- (618) 632-7345
-
-
- This Turbo Pascal v5.5 OOP object implements a linked list
- of strings. You no longer have to read a text file more than one
- time: you can now let an OOP variable of StrLinkList type read it
- into memory. You can sort text files based on varying criteria,
- remove redundant strings, etc.
-
- This link list of strings offers an extra added bonus. Each
- string on the list takes up only as much space as it absolutely
- requires. This is true even if you change the size of the string
- after putting it on the list. (You can always inspect the code
- if you want to see how it was accomplished.)
-
- And because it's OOP, you can create a descendent object if
- you have special needs. If any of the code is ever updated, you
- can simply upgrade to the version ── you'll never have to change
- a line of your descendent code.
-
-
- UNIT NAME
-
-
- The name of the main unit is "StrLink". You should put this
- in any program or unit of your own that needs access to variables
- of type StrLinkList.
-
-
- CONDITIONAL DIRECTIVES
-
-
- {$IFDEF TPRO5}
-
- The StrLink and StrObj units can optionally use TurboPower
- Software's TPRO5 toolkit. TPRO5 offers some extra efficiency &
- speed for string link lists. If you do NOT have TPRO5, you must
- change the '$' to a '.' so the proper code will compile.
- I encourage you to write or call TurboPower for a brochure
- about their products. I actually pity you if you aren't using
- their toolkits. TPRO5 contains 50,000+ lines of source code in
- over 30 units, and TurboPower is coming out soon with OPRO, the
- Object Professional Toolkit. You can contact TurboPower at P.O.
- Box 66747, Scotts Valley, CA 95066, or call (408) 438-8608. Be
- sure to tell them I said hi.
-
- STRLINK OBJECT Page 2 of 7
-
-
-
- USES
-
-
- The StrLink unit USES the following units:
-
- {$IFDEF TPRO5}
- TpString,
- {$ENDIF}
- Objects,
- ObjectA,
- StrObj;
-
- The TpString unit is supplied with the TurboPower Software
- TPRO5 toolkit. Please see the section on conditional compilation
- directives for more information about this powerful toolkit.
- The Objects unit is on Turbo Pascal v5.5 disk #3. It imple-
- ments the foundation of a singly linked list object.
- The ObjectA unit is included in this file IF this was pulled
- down from a BBS. If it was pulled down from CompuServe, then you
- must also download OBJA.ARC from BPROGA forum LIBrary 1. ObjectA
- builds on the Objects unit by offering a more powerful descendent
- object for singly linked lists.
- The StrObj unit is included with StrLink. It implements the
- foundation for a string object.
-
-
- TYPES
-
-
- SortedOrderType = (ForwardOrder,
- ReverseOrder,
- AscendingOrder,
- DescendingOrder);
-
- StrLinkList
- = OBJECT(LinkList)
- CurrentStrPtr : StrObjectPtr;
- UniqueStringsOnly : BOOLEAN;
- SortedOrder : SortedOrderType;
- CaseMatters : BOOLEAN;
-
- CONSTRUCTOR Init(UniqueStrings : BOOLEAN;
- SortSpecifier : SortedOrderType;
- IgnoreCase : BOOLEAN);
-
- FUNCTION GetSpecificString(NodePos : LONGINT) : STRING;
- PROCEDURE DeleteSpecificString(NodePos : LONGINT);
-
- FUNCTION ReadStrings(TheFilename : STRING) : BYTE;
- FUNCTION WriteStrings(TheFilename : STRING;
- AppendFile : BOOLEAN) : BYTE;
-
- PROCEDURE AddString(TheStr : STRING);
- PROCEDURE DeleteString(TheStr : STRING);
-
- STRLINK OBJECT Page 3 of 7
-
-
-
- FUNCTION Exists(TheStr : STRING) : BOOLEAN;
- FUNCTION ExistsSubstring(TheSubStr : STRING) : BOOLEAN;
- PROCEDURE DeleteStringsWithoutSubstring(TheSubStr : STRING;
- IgnoreCase : BOOLEAN);
- PROCEDURE DeleteStringsWithSubstring(TheSubStr : STRING;
- IgnoreCase : BOOLEAN);
- PROCEDURE DeleteDuplicates;
- PROCEDURE DeleteLeadNullStrings;
- PROCEDURE DeleteNullStrings;
- PROCEDURE DeleteTrailNullStrings;
-
- PROCEDURE InitCurrent;
- FUNCTION CurrentString : STRING;
- PROCEDURE ChangeCurrentString(NewStr : STRING);
- FUNCTION FirstString : STRING;
- FUNCTION LastString : STRING;
- PROCEDURE Advance;
- PROCEDURE Retreat;
- FUNCTION MoreStrings : BOOLEAN;
- FUNCTION NoMoreStrings : BOOLEAN
- END;
-
-
- PROCEDURES & FUNCTIONS
-
-
- CONSTRUCTOR Init(UniqueStrings : BOOLEAN;
- SortSpecifier : SortedOrderType;
- IgnoreCase : BOOLEAN);
-
- Initializes the StrLinkList instantiation. UniqueStrings
- dictates if the list should ignore duplicate strings. IgnoreCase
- dictates if the strings should be viewed as all uppercase, even
- though they will be stored as upper/lowercase.
- SortSpecifier dictates how the list is sorted. ForwardOrder
- means strings will be added to the END of the list. This is the
- same as reading a regular text file. ReverseOrder means strings
- will be added to the BEGINNING of the list. This would be like
- reading a text file backwards. AscendingOrder dictates that the
- list will be sorted in ascending order. DescendingOrder dictates
- that the list will be sorted in descending order.
- The IgnoreCase boolean is important if you choose to sort
- the list in ascending/descending order. If IgnoreCase is FALSE,
- "BBBB" will come before "aaaa". When IgnoreCase is TRUE, all
- strings are viewed as uppercase. But don't worry, they're stored
- exactly as they are. IgnoreCase is important only during string
- comparisons.
-
- STRLINK OBJECT Page 4 of 7
-
-
-
- DESTRUCTOR Done;
-
- This destructor is INHERITED from an ancestral object. It
- completely removes all strings from the list and frees up their
- associated memory. You must call this destructor/procedure when
- you're finished with the list. (You can "flush" the list for a
- new purpose by calling Done, then calling Init once more.)
-
- FUNCTION GetSpecificString(NodePos : LONGINT) : STRING;
-
- This function returns a string from the StrLinkList based on
- the position of a particular string in the list. This is useful
- for people who use TurboPower Software's TPRO5 TpPick unit, for
- example. The position is represented by NodePos. This function
- returns a null string if NodePos is <= 0 or if it is > the last
- node on the list. The CurrentString function will return this
- string after you use this function.
-
- PROCEDURE DeleteSpecificString(NodePos : LONGINT);
-
- This procedure deletes a string from the StrLinkList based on
- the position of the string in the list, represented by NodePos.
- It does nothing if NodePos is <= 0 or if it is > the last string
- position on the list. The CurrentString function points to NO
- string after this call.
-
- FUNCTION ReadStrings(TheFilename : STRING) : BYTE;
-
- Reads strings from TheFilename and adds them to the list. The
- IORESULT value is returned as the result of this function.
-
- FUNCTION WriteStrings(TheFilename : STRING;
- AppendFile : BOOLEAN) : BYTE;
-
- Writes all strings on the list to TheFilename. The IORESULT
- value is returned as the result of this function. AppendFile
- dictates if the strings should be appended to the end of a file
- if it already exists. NOTE: the file must exist if AppendFile is
- set to TRUE.
-
- PROCEDURE AddString(TheStr : STRING);
-
- Adds a string to the list. It does nothing if the string is
- redundant AND UniqueStrings was TRUE when you called Init. The
- CurrentString function is undefined after calling this routine.
- (It may, or may not, point to the newly added string.)
-
- PROCEDURE DeleteString(TheStr : STRING);
-
- This procedure deletes the given string from the list. It
- does nothing if the string doesn't exist. The CurrentString
- function points to NO string after this call.
-
- STRLINK OBJECT Page 5 of 7
-
-
-
- FUNCTION Exists(TheStr : STRING) : BOOLEAN;
-
- Determines if the given string is on the list.
-
- FUNCTION ExistsSubstring(TheSubStr : STRING) : BOOLEAN;
-
- Similar to the Exists function, this routine determines if a
- given substring is on the StrLinkList. It searches every string
- on the list until it either finds the substring inside one of the
- strings, or it runs out of strings to search. This function is
- TRUE if TheSubStr is a null string and at least one string exists
- on the list.
- If the result is TRUE, CurrentString will return the first
- string on the list containing the given substring.
-
- PROCEDURE DeleteStringsWithoutSubstring(TheSubStr : STRING;
- IgnoreCase : BOOLEAN);
-
- This procedure deletes any string from the list that doesn't
- contain the given substring. No strings will be deleted if the
- substring is a null string. The IgnoreCase variable dictates
- whether upper/lower case is relevant during the search. (This
- overrides the string comparison check you specified when you
- called Init.)
-
- PROCEDURE DeleteStringsWithSubstring(TheSubStr : STRING;
- IgnoreCase : BOOLEAN);
-
- This procedure deletes any string from the list that DOES
- contain the given substring. No strings will be deleted if the
- substring is a null string. The IgnoreCase variable dictates
- whether upper/lower case is relevant during the search. (This
- overrides the string comparison check you specified when you
- called Init.)
-
- PROCEDURE DeleteDuplicates;
-
- This procedure deletes duplicate strings from the list. It
- does nothing if you specified unique strings during the call to
- the Init procedure.
-
- PROCEDURE DeleteLeadNullStrings;
-
- This procedure deletes leading null strings from the list.
- It's an easy way to strip out any leading blank lines from a text
- file. Null strings that exist past the first non-null string in
- the list are left alone.
-
- PROCEDURE DeleteNullStrings;
-
- This procedure deletes all null strings from the list. It's
- an easy way to delete all the blank lines from a text file you
- just read from disk.
-
- STRLINK OBJECT Page 6 of 7
-
-
-
- PROCEDURE DeleteTrailNullStrings;
-
- This procedure deletes trailing null strings from the list.
- It's an easy way to delete blank lines from the end of a text
- file you just read from disk.
-
- PROCEDURE InitCurrent;
-
- This function initializes the CurrentString so it returns
- the first first string on the list (assuming there is at least
- one string on the list).
-
- FUNCTION CurrentString : STRING;
-
- This function returns the current string pointed to in the
- list. You must use the InitCurrent procedure to set the current
- string to the first string in the list. CurrentString returns a
- null string if it points to no string. (Use the MoreStrings and
- NoMoreStrings functions to determine if CurrentString points to a
- string.)
-
- PROCEDURE ChangeCurrentString(NewStr : STRING);
-
- Changes the current string to the new string.
-
- FUNCTION FirstString : STRING;
-
- Returns the first String in the list. It returns a null
- string if there are no strings in the list. The CurrentString
- function will also return the first string after you call this
- function.
-
- FUNCTION LastString : STRING;
-
- Returns the last String in the list. It returns a null
- string if there are no strings in the list. The CurrentString
- function will also return the last string after you call this
- function.
-
- PROCEDURE Advance;
-
- This procedure simply moves the current string pointer to
- the next string in the list. You should use the MoreStrings or
- NoMoreStrings functions to see if there is another string on the
- list after making this call.
-
- PROCEDURE Retreat;
-
- This procedure simply moves the current string pointer to
- the previous string in the list. You should use the MoreStrings
- or NoMoreStrings functions to see if there is another string on
- the list after making this call.
-
- STRLINK OBJECT Page 7 of 7
-
-
-
- FUNCTION MoreStrings : BOOLEAN;
-
- Returns TRUE or FALSE, explaining if CurrentString points to
- a valid string in the list. Should be used with the Advance and
- Retreat procedures.
-
- FUNCTION NoMoreStrings : BOOLEAN;
-
- The opposite of the MoreStrings function. See above.
-