Titlecase function

Discuss any 3rd-party tools and code that may be of interest to other Juce users

Titlecase function

Postby justin » Thu Mar 04, 2010 12:32 pm

Hoping Julian add's to the String class...

(Useful for CamelCase)

Code: Select all
const String String::toTitleCase () const throw()
{
   
   String result (*this);
   result.dupeInternalIfMultiplyReferenced();
   tchar* t = result.text->text;
   
   bool wordStart=true;
   while (*t != 0)
   {
      
      if (CharacterFunctions::isWhitespace(*t) || !CharacterFunctions::isLetterOrDigit(*t))
      {
         wordStart = true;
      }
      else if (wordStart == true)
      {
         CharacterFunctions::toUpperCase(t);
         wordStart = false;
      }
      else
      {
         CharacterFunctions::toLowerCase(t);
      }
      ++t;
   }
   
   return result;
}
User avatar
justin
JUCE UberWeenie
 
Posts: 297
Joined: Mon May 19, 2008 1:37 pm
Location: Canada

Re: Titlecase function

Postby jules » Sun Mar 07, 2010 9:22 pm

Can't quite decide if that's a good candidate for the String class or not... It feels a bit too language-specific really..
User avatar
jules
Fearless Leader
 
Posts: 17364
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: Titlecase function

Postby justin » Tue Mar 09, 2010 11:22 pm

True... but toUppercase and toLowercase are in there!

:wink:
User avatar
justin
JUCE UberWeenie
 
Posts: 297
Joined: Mon May 19, 2008 1:37 pm
Location: Canada


Return to Useful Tools and Components

Who is online

Users browsing this forum: No registered users and 2 guests