# # patch "ChangeLog" # from [681fccb33bb7bd34e90a6077c0c0eb2bfa2b631e] # to [9dae3a5baf5ca4cd891eb1dc4cb807e64157f6e2] # # patch "paths.cc" # from [1da5513341ff15b2887ebd5040934405aa5d4e00] # to [fb1083363850a4916aebf9078ebdd12c07565c46] # # patch "paths.hh" # from [d1545b2288da082ff04bde7e36760748079f9053] # to [633cc834953d8ce843f7df06548b01268f89f046] # ======================================================================== --- ChangeLog 681fccb33bb7bd34e90a6077c0c0eb2bfa2b631e +++ ChangeLog 9dae3a5baf5ca4cd891eb1dc4cb807e64157f6e2 @@ -1,5 +1,10 @@ 2005-08-23 Nathaniel Smith + * paths.cc (localized_path_str): New function. + Fix some tests. + +2005-08-23 Nathaniel Smith + * commands.cc: Convert to paths.hh. * mkstemp.cc (monotone_mkstemp): Likewise. ======================================================================== --- paths.cc 1da5513341ff15b2887ebd5040934405aa5d4e00 +++ paths.cc fb1083363850a4916aebf9078ebdd12c07565c46 @@ -212,6 +212,26 @@ } } +/////////////////////////////////////////////////////////////////////////// +// localizing file names (externalizing them) +// this code must be superfast when there is no conversion needed +/////////////////////////////////////////////////////////////////////////// + +static inline +localized_path_str(std::string const & path, std::string & out) +{ +#ifdef __APPLE__ + // on OS X paths for the filesystem/kernel are UTF-8 encoded, regardless of + // locale. + out = path; +#else + // on normal systems we actually have some work to do, alas. + // not much, though, because utf8_to_system does all the hard work. it is + // carefully optimized. do not screw it up. + utf8_to_system(path, out); +#endif +} + #ifdef BUILD_UNIT_TESTS #include "unit_tests.hh" @@ -305,7 +325,7 @@ "c:/foo", 0 }; for (char const ** c = baddies; *c; ++c) - BOOST_CHECK_THROW(file_path(internal, *c), logic_error); + BOOST_CHECK_THROW(file_path(external, *c), informative_failure); check_fp_normalizes_to("", ""); check_fp_normalizes_to("foo", "foo"); @@ -340,11 +360,11 @@ "c:\\foo", "c:foo", "c:/foo", + "", 0 }; for (char const ** c = baddies; *c; ++c) - BOOST_CHECK_THROW(file_path(internal, *c), logic_error); + BOOST_CHECK_THROW(file_path(external, *c), informative_failure); - check_fp_normalizes_to("", "a/b"); check_fp_normalizes_to("foo", "a/b/foo"); check_fp_normalizes_to("foo/bar", "a/b/foo/bar"); check_fp_normalizes_to("foo/bar/baz", "a/b/foo/bar/baz"); @@ -451,6 +471,8 @@ std::string initial_path_saved = initial_path; initial_path = "/a/b"; + BOOST_CHECK_THROW(system_path(""), informative_failure); + check_system_normalizes_to("foo", "/a/b/foo"); check_system_normalizes_to("foo/bar", "/a/b/foo/bar"); check_system_normalizes_to("/foo/bar", "/foo/bar"); ======================================================================== --- paths.hh d1545b2288da082ff04bde7e36760748079f9053 +++ paths.hh 633cc834953d8ce843f7df06548b01268f89f046 @@ -44,9 +44,10 @@ file_path(std::vector const & pieces); // returns raw normalized path string - std::string const & as_internal() const; + std::string const & as_internal() const + { return data; } // converts to native charset and path syntax - std::string const & as_external() const; + std::string as_external() const; void split(std::vector & pieces) const; @@ -73,7 +74,7 @@ // path should _not_ contain the leading MT/ // and _should_ look like an internal path bookkeeping_path(std::string const & path); - std::string const & as_external() const; + std::string as_external() const; private: std::string data; }; @@ -87,7 +88,7 @@ // tilde-expanded. it should be in utf8. system_path(std::string const & path); // this will always be an absolute path, in the local character set - std::string const & as_external() const; + std::string as_external() const; bool empty() const; private: std::string data;