Ticket #5289: boost_filesystem.patch

File boost_filesystem.patch, 2.5 KB (added by artyomtnk@…, 12 years ago)
  • libs/filesystem/v3/src/path.cpp

    diff -ru boost_1_46_0_ref//libs/filesystem/v3/src/path.cpp boost_1_46_0//libs/filesystem/v3/src/path.cpp
    old new  
    2929#include <boost/assert.hpp>
    3030#include <cstddef>
    3131#include <cstring>
     32#include <cstdlib>
    3233#include <cassert>
    3334
    3435#ifdef BOOST_WINDOWS_API
    3536# include "windows_file_codecvt.hpp"
    3637# include <windows.h>
    37 #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
     38#else
    3839# include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
    3940#endif
    4041
     
    733734
    734735  std::locale default_locale()
    735736  {
    736 #   ifdef BOOST_WINDOWS_API
     737    try {
     738        // Best try use standard library's  locale
     739        // support if avalible
     740        return std::locale("");
     741    }
     742    catch(std::exception const &/*error*/) {
     743        // Not supported, GCC on non-Linux for example
     744    }
    737745    std::locale global_loc = std::locale();
     746
     747#   ifdef BOOST_WINDOWS_API
    738748    std::locale loc(global_loc, new windows_file_codecvt);
    739749    return loc;
    740750
     
    754764    // cases." http://lists.apple.com/archives/applescript-users/2002/Sep/msg00319.html
    755765    //
    756766    // Many thanks to Peter Dimov for digging out the above references!
    757     std::locale global_loc = std::locale();
    758767    std::locale loc(global_loc, new boost::filesystem::detail::utf8_codecvt_facet);
    759768    return loc;
    760769
    761770#   else
    762     // ISO C calls this "the locale-specific native environment":
    763     return std::locale("");
     771   
     772    // Get default OS encoding
     773    char const *plang = getenv("LC_CTYPE");
     774    if(!plang)
     775        plang = getenv("LC_ALL");
     776    if(!plang)
     777        plang = getenv("LANG");
     778    if(!plang)
     779        return global_loc;
     780   
     781    std::string lang = plang;
     782    size_t charset_start = lang.find('.');
     783    if(charset_start == std::string::npos)
     784        return global_loc;
     785    charset_start ++;
     786    size_t end_of_charset = lang.find(charset_start,'@');
     787    std::string encoding = lang.substr(charset_start,end_of_charset - charset_start);
     788    for(size_t i=0;i<encoding.size();i++) {
     789        if('a' <= encoding[i] && encoding[i]<='z') {
     790            encoding[i]=encoding[i]-'a' + 'A';
     791        }
     792    }
     793    //
     794    // Support at least the most popular and widely used encoding
     795    //
     796    if(encoding!="UTF-8" && encoding!="UTF8")
     797        return global_loc;
     798    std::locale loc(global_loc, new boost::filesystem::detail::utf8_codecvt_facet);
     799    return loc;
    764800
    765801#   endif
    766802  }