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
|
|
29 | 29 | #include <boost/assert.hpp> |
30 | 30 | #include <cstddef> |
31 | 31 | #include <cstring> |
| 32 | #include <cstdlib> |
32 | 33 | #include <cassert> |
33 | 34 | |
34 | 35 | #ifdef BOOST_WINDOWS_API |
35 | 36 | # include "windows_file_codecvt.hpp" |
36 | 37 | # include <windows.h> |
37 | | #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) |
| 38 | #else |
38 | 39 | # include <boost/filesystem/detail/utf8_codecvt_facet.hpp> |
39 | 40 | #endif |
40 | 41 | |
… |
… |
|
733 | 734 | |
734 | 735 | std::locale default_locale() |
735 | 736 | { |
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 | } |
737 | 745 | std::locale global_loc = std::locale(); |
| 746 | |
| 747 | # ifdef BOOST_WINDOWS_API |
738 | 748 | std::locale loc(global_loc, new windows_file_codecvt); |
739 | 749 | return loc; |
740 | 750 | |
… |
… |
|
754 | 764 | // cases." http://lists.apple.com/archives/applescript-users/2002/Sep/msg00319.html |
755 | 765 | // |
756 | 766 | // Many thanks to Peter Dimov for digging out the above references! |
757 | | std::locale global_loc = std::locale(); |
758 | 767 | std::locale loc(global_loc, new boost::filesystem::detail::utf8_codecvt_facet); |
759 | 768 | return loc; |
760 | 769 | |
761 | 770 | # 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; |
764 | 800 | |
765 | 801 | # endif |
766 | 802 | } |