Ultra-Groovy LString Class
Volume Number: 15
Issue Number: 1
Column Tag: PowerPlant Workshop
The Ultra-Groovy LString Class
by John C. Daub, Austin, Texas, USA
An introduction to the PowerPlant-way of working
with strings
Hello, World!
Most software developers have been working with strings since they wrote their first
program - that's what "Hello World!" is all about. To facilitate working with strings
many libraries of utility functions have been written. Some people have their
home-brewed string libraries, while others utilize third party libraries or use the
libraries provided in Standard C and C++. These solutions are well and good, but they
do not always translate very effectively into the world of Mac OS. Many of these
offerings, like the Standard C and C++ libraries, are written to work with C-style
strings - a sequence of characters terminated by a null character. But due to the Mac
OS Toolbox's Pascal heritage, strings on the Mac are Pascal-style strings - a sequence
of characters preceeded by a length byte which stores the length of the string.
Consequently, a string library designed to work with Pascal-style strings is more
valuable to the Mac OS software developer. Enter PowerPlant's LString class.
LString is a C++ abstract base class for working with Pascal-style strings. It
provides means for converting strings to numbers and numbers to strings; obtain
strings from numerous sources (characters, other strings, resources); copy, append,
and compare strings; find, insert, remove, and replace substrings; and does so in a
manner that respects the boundaries of Pascal-style strings, takes advantage of the
C++ language, makes your code easier to read and understand, and most of all is easy
and logical to use. The inherited classes LStr255, TString, and LStringRef provide the
concrete means for working with strings in a manner very familiar to Mac OS
software developers, so the learning curve for LString is not a steep one. And although
LString is a PowerPlant class it can be used independent of the rest of PowerPlant; feel
free to use it in all of your Mac OS software development efforts.
If LString sounds good to you, then please read on. In this article I hope to provide you
with a good overview of what LString provides, and illustrate how it will make your