runtime_error in older boost when locales are not set

due to a bug in older boost versions oF will crash when using file operations in oF0.9 and if the locales are not set properly (if LC_ALL is not set)

here a ticket about this issue:
https://svn.boost.org/trac/boost/ticket/4688

i just came across this on a rpi where we have boost in version 1.50 via the package manager (oF require boost 1.49)

in case this affects somebody: to make it work just set LC_ALL like this:
export LC_ALL="C"

testing on a ubuntu desktop with boost-filesystem1.55 it works also without LC_ALL being set.

in ofAppRunner line 111 there’s:

#ifdef TARGET_LINUX
    if(std::locale().name() == "C"){
        try{
            std::locale::global(std::locale("C.UTF-8"));
        }catch(...){
            if(ofToLower(std::locale("").name()).find("utf-8")==std::string::npos){
                ofLogWarning("ofInit") << "Couldn't set UTF-8 locale, string manipulation functions\n"
                        "won't work correctly for non ansi characters unless you specify a UTF-8 locale\n"
                        "manually using std::locale::global(std::locale(\"locale\"))\n"
                        "available locales can be queried with 'locale -a' in a terminal.";
            }
        }
    }
#endif

we can add a small fix for that by checking if the locale is empty and try to set it too like:

#ifdef TARGET_LINUX
    if(std::locale().name() == "C" || std::locale().name().empty()){
        try{
            std::locale::global(std::locale("C.UTF-8"));
        }catch(...){
            if(ofToLower(std::locale("").name()).find("utf-8")==std::string::npos){
                ofLogWarning("ofInit") << "Couldn't set UTF-8 locale, string manipulation functions\n"
                        "won't work correctly for non ansi characters unless you specify a UTF-8 locale\n"
                        "manually using std::locale::global(std::locale(\"locale\"))\n"
                        "available locales can be queried with 'locale -a' in a terminal.";
            }
        }
    }
#endif

i don’t have an rpi with me right now but if you can give it a try and send a PR?

I tried, but it still makes problems.

it fails when calling of::priv::setWorkingDirectoryToDefault(); so its better to first try to set the locale and then set the working directory.

#ifdef TARGET_LINUX
    if(std::locale().name() == "C" || std::locale().name().empty()){
        try{
            std::locale::global(std::locale("C.UTF-8"));
        }catch(...){
            if(ofToLower(std::locale("").name()).find("utf-8")==std::string::npos){
                ofLogWarning("ofInit") << "Couldn't set UTF-8 locale, string manipulation functions\n"
                        "won't work correctly for non ansi characters unless you specify a UTF-8 locale\n"
                        "manually using std::locale::global(std::locale(\"locale\"))\n"
                        "available locales can be queried with 'locale -a' in a terminal.";
            }
        }
    }
#endif

ofSeedRandom();
ofResetElapsedTimeCounter();
of::priv::setWorkingDirectoryToDefault();

it does successfully set the locale, but then still crashes when setting the working-directory.