BVB Source Codes

mars Show portability.cpp Source code

Return Download mars: download portability.cpp Source code - Download mars Source code - Type:.cpp
  1. //  portability.cpp  -------------------------------------------------------------------//
  2.  
  3. //  Copyright 2002-2005 Beman Dawes
  4. //  Use, modification, and distribution is subject to the Boost Software
  5. //  License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
  6. //  at http://www.boost.org/LICENSE_1_0.txt)
  7.  
  8. //  See library home page at http://www.boost.org/libs/filesystem
  9.  
  10. //--------------------------------------------------------------------------------------//
  11.  
  12. // define BOOST_FILESYSTEM_SOURCE so that <boost/filesystem/config.hpp> knows
  13. // the library is being built (possibly exporting rather than importing code)
  14. #define BOOST_FILESYSTEM_SOURCE
  15.  
  16. #ifndef BOOST_SYSTEM_NO_DEPRECATED
  17. # define BOOST_SYSTEM_NO_DEPRECATED
  18. #endif
  19.  
  20. #include <boost/filesystem/config.hpp>
  21. #include <boost/filesystem/path.hpp>
  22.  
  23. namespace fs = mars_boost::filesystem;
  24.  
  25. #include <cstring> // SGI MIPSpro compilers need this
  26.  
  27. # ifdef BOOST_NO_STDC_NAMESPACE
  28.     namespace std { using ::strerror; }
  29. # endif
  30.  
  31. //--------------------------------------------------------------------------------------//
  32.  
  33. namespace
  34. {
  35.   const char invalid_chars[] =
  36.     "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
  37.     "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
  38.     "<>:\"/\\|";
  39.   // note that the terminating '\0' is part of the string - thus the size below
  40.   // is sizeof(invalid_chars) rather than sizeof(invalid_chars)-1.  I
  41.   const std::string windows_invalid_chars(invalid_chars, sizeof(invalid_chars));
  42.  
  43.   const std::string valid_posix(
  44.     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
  45.  
  46. } // unnamed namespace
  47.  
  48. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost
  49. {
  50.   namespace filesystem
  51.   {
  52.  
  53.     //  name_check functions  ----------------------------------------------//
  54.  
  55. #   ifdef BOOST_WINDOWS
  56.     BOOST_FILESYSTEM_DECL bool native(const std::string & name)
  57.     {
  58.       return windows_name(name);
  59.     }
  60. #   else
  61.     BOOST_FILESYSTEM_DECL bool native(const std::string & name)
  62.     {
  63.       return  name.size() != 0
  64.         && name[0] != ' '
  65.         && name.find('/') == std::string::npos;
  66.     }
  67. #   endif
  68.  
  69.     BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string & name)
  70.     {
  71.       return name.size() != 0
  72.         && name.find_first_not_of(valid_posix) == std::string::npos;    
  73.     }
  74.  
  75.     BOOST_FILESYSTEM_DECL bool windows_name(const std::string & name)
  76.     {
  77.       return name.size() != 0
  78.         && name[0] != ' '
  79.         && name.find_first_of(windows_invalid_chars) == std::string::npos
  80.         && *(name.end()-1) != ' '
  81.         && (*(name.end()-1) != '.'
  82.           || name.length() == 1 || name == "..");
  83.     }
  84.  
  85.     BOOST_FILESYSTEM_DECL bool portable_name(const std::string & name)
  86.     {
  87.       return
  88.         name.size() != 0
  89.         && (name == "."
  90.           || name == ".."
  91.           || (windows_name(name)
  92.             && portable_posix_name(name)
  93.             && name[0] != '.' && name[0] != '-'));
  94.     }
  95.  
  96.     BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string & name)
  97.     {
  98.       return
  99.         name == "."
  100.         || name == ".."
  101.         || (portable_name(name)
  102.           && name.find('.') == std::string::npos);
  103.     }
  104.  
  105.     BOOST_FILESYSTEM_DECL bool portable_file_name(const std::string & name)
  106.     {
  107.       std::string::size_type pos;
  108.       return
  109.          portable_name(name)
  110.          && name != "."
  111.          && name != ".."
  112.          && ((pos = name.find('.')) == std::string::npos
  113.              || (name.find('.', pos+1) == std::string::npos
  114.                && (pos + 5) > name.length()))
  115.         ;
  116.     }
  117.  
  118.   } // namespace filesystem
  119. } // namespace mars_boost
  120.  
downloadportability.cpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top