The titlecaps
package (http://ctan.org/pkg/titlecaps, but note that CTAN is hosed in that it doesn't show in a search, but is actually there) does this. Having written the "horrendously time-expensive" stringstrings package (as Geoffrey correctly notes), I endeavored to do better for the situation of titling. The titlecaps
package is the result.
An example in the documentation shows how the fully lower-cased source:
\documentclass{article}
\usepackage{titlecaps}
\parskip 1em
\parindent 0em
\def\bs{$\backslash$}
\begin{document}
\Resetlcwords
\Addlcwords{for a is but and with of in as the etc on to if}
\titlecap{%
to know that none of the words typed in this paragraph were initially
upper cased might be of interest to you. it is done to demonstrate the
behavioral features of this package. first, you should know the words
that i have pre-designated as lower case. they are: ``for a is but and
with of in as the etc on to if.'' you can define your own list. note
that punctuation, like the period following the word ``if'' did not mess
up the search for lower case (nor did the quotation marks just now).
punctuation which is screened out of the lower-cased word search pattern
include . , : ; ( ) [ ] ? ! ` ' however, I cannot screen text braces;
\{for example in\} is titled, versus (for example in), since the braces
are not screened out in the search for pre-designated lower-case words
like for and in. However, \texttt{\bs textnc} provides a workaround:
\{\textnc{for example in}\}. titlecap will consider capitalizing
following a (, [, \{, or - symbol, such as (abc-def). you can use your
text\textit{\relax xx} commands, like i just did here with the prior xx,
but if you want the argument of that command to not be titled, you
either need, in this example, to add \textit{xx} to the lowercase word
list, which you can see i did not. instead, i put ``\bs relax~xx'' as
the argument, so that, in essence, the \bs relax was capitalized, not
the x. Or you could use \texttt{\bs textnc} . here i demonstrate that
text boldface, \textbf{as in the \bs textbf command}, also works fine,
as do \texttt{texttt}, \textsl{textsl}, \textsc{textsc},
\textsf{textsf}, \textit{etc}. titlecap will work on diacritical marks,
such as \"apfel, \c cacao \textit{etc.}, \scriptsize fontsize \LARGE
changing commands\normalsize\unskip, as well as national symbols such as
\o laf, \ae gis, and \oe dipus. unfortunately, i could not get it to
work on the \aa~nor the \l~symbols. the method will work with some
things in math mode, capitalizing symbols if there is a leading space,
$x^2$ can become $ x^2$, and it can process but it will not capitalize
the greek symbols, such as $\alpha$, and will choke on most macros, if
they are not direct character expansions. Additionally,
\textsf{titlecaps} also works with font changing declarations, for
example, \bs itshape\bs sffamily. \itshape\sffamily you can see that it
works fine. likewise, any subsequent \bs textxx command will, upon
completion, return the font to its prior state, such as this
\textbf{textbf of some text}. you can see that i have returned to the
prior font, which was italic sans-serif. now I will return to upright
roman\upshape\rmfamily. a condition that will not behave well is inner
braces, such as \ttfamily \bs titlecap\{blah \{inner brace material\}
blah-blah\}. \rmfamily see the section on quirks and limitations for a
workaround involving \texttt{\bs textnc}. titlecap will always
capitalize the first word of the argument (\textbf{even if it is on the
lower-case word list}), unless \texttt{\bs titlecap} is invoked with an
optional argument that is anything other than a capital p. in that case,
the first word will be titled \textit{unless} it is on the lowercase
word list. for example, i will do a \bs titlecap[\relax s]\{\relax
a~big~man\} and get ``\titlecap[s]\textnc{a big man}'' with the ``a''
not titled. i hope this package is useful to you, but as far as using
\textsf{titlecaps} on such large paragraphs\ldots \textbf{do not try
this at home!}}
\end{document}
can become, in just a few quick seconds of execution time, this:

of
orin
are not supposed to be capitalized in title case. So you will need to either maintain a very nice list of exceptions, or just ignore them. If you want to implement something like this, you may want to take a look at ctan.org/tex-archive/help/Catalogue/entries/mfirstuc.html for some ideas. – Willie Wong Nov 2 '10 at 0:14:)
– Will Robertson Nov 2 '10 at 10:32