home *** CD-ROM | disk | FTP | other *** search
- It seems to me that since we can make a Class have anything we want, and we
- know that people love to argue about the merits of C-style, null terminated
- strings vs. Pascal-style "counted" strings, the Obj-C String class ought to
- be both. That way we've got the flexiblity of null-termination, and
- the efficiency of knowing the string length up front. The fact that it's an
- object should relieve problems with Pascal-style counted strings: we can use
- any size representation of the string length we want, not just the initial
- byte.
-
- So, keeping length of string around in an instance var should minimize calls
- to strlen(), which are bound to get expensive. It should also allow the
- use of bcopy() instead of strcpy(). Hopefully, vendors C library bcopy()
- will be cognizant of cache blocking, loop unrolling and so forth, and will
- be faster than strcpy().
-
- The other thing that's really expensive about both C and Pascal style strings
- is memory allocation/deallocation. The obvious solution to that is "refence
- counting." Reference counting makes the object 'copy-on-write', I guess.
- It should minimize calls to bcopy(), malloc() and free().
-
- Here's my String class wish list:
- -------------------------------------------------------------------------------
- reqs:
- speedy
- memory efficient
- convenient
- dynamically allocate/deallocate memory for string usage
- robust (in face of programmer errors)
-
- methods:
-
- new
- new from another String object
- new from ASCIIZ string
- new filled with arbitrary number of arbitrary char
-
- free
-
- get pointer to real data
-
- empty out the real data
-
- get string length (printing size or memory allocated?)
-
- test for null string
-
- uppercase String
- lowercase String
-
- replace with a new ASCIIZ string
- replace with a new String object
-
- lexicographical comparison with another String object
- lexicographical comparison with ASCIIZ string
- case sensitive/case insensitive versions?
-
- append/prepend/insert another String object
- append/prepend/insert ASCIIZ string
-
- retrieve substring at arbitrary position
- retrieve substring matching a regexp
- replace substring matching a regexp with ASCIIZ string
- replace substring matching a regexp with another String object
-
- retrieve a char at arbitrary position
- substitute a char at arbitrary position
- insert a char at arbitrary position
-
- find index location of arbitrary char (from beginning and end of String)
-
- (BOOLEAN)matches a regexp or not
-
-