#
# patch "ChangeLog"
# from [c8932647b57835f8d2cd3cd776d7616d66083aaf]
# to [2bf5d46d3636d44d7913bb30c40b4ecd9744129d]
#
# patch "paths.cc"
# from [fb1083363850a4916aebf9078ebdd12c07565c46]
# to [adbd7ec83e52a8c0a7da240e6ecdf7b36a7db4e6]
#
# patch "paths.hh"
# from [633cc834953d8ce843f7df06548b01268f89f046]
# to [220e9bcce99b4025b4aed3e9f2c97c58a91fbd76]
#
# patch "transforms.cc"
# from [0faca837b3bfbe8a8db6f1ee3d3901dbaf7aade4]
# to [4c0c80f47a736a45e4825212305604ed1414bc69]
#
# patch "transforms.hh"
# from [89eac835c660c0f18f5e894c41d33d6b46b0870e]
# to [138f60ebea73d73425b0d4db26bac9cbee6e2e2d]
#
========================================================================
--- ChangeLog c8932647b57835f8d2cd3cd776d7616d66083aaf
+++ ChangeLog 2bf5d46d3636d44d7913bb30c40b4ecd9744129d
@@ -1,5 +1,12 @@
2005-08-23 Nathaniel Smith
+ * paths.cc (any_path): New base class.
+ (file_path, bookkeeping_path, system_path): Inherit from it.
+ * transforms.{hh,cc} (utf8_to_system): Actually, always take a
+ utf8 after all (but still have two return types).
+
+2005-08-23 Nathaniel Smith
+
* transforms.cc: Convert to paths.hh.
2005-08-23 Nathaniel Smith
========================================================================
--- paths.cc fb1083363850a4916aebf9078ebdd12c07565c46
+++ paths.cc adbd7ec83e52a8c0a7da240e6ecdf7b36a7db4e6
@@ -217,18 +217,20 @@
// this code must be superfast when there is no conversion needed
///////////////////////////////////////////////////////////////////////////
-static inline
-localized_path_str(std::string const & path, std::string & out)
+std::string
+any_path::as_external() const
{
#ifdef __APPLE__
// on OS X paths for the filesystem/kernel are UTF-8 encoded, regardless of
// locale.
- out = path;
+ return data();
#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);
+ external out;
+ utf8_to_system(data, out);
+ return out();
#endif
}
========================================================================
--- paths.hh 633cc834953d8ce843f7df06548b01268f89f046
+++ paths.hh 220e9bcce99b4025b4aed3e9f2c97c58a91fbd76
@@ -25,9 +25,24 @@
return pc == the_null_component;
}
-class file_path
+class any_path
{
public:
+ // converts to native charset and path syntax
+ std::string as_external() const;
+protected:
+ utf8 data;
+private:
+ any_path();
+ any_path(any_path const & other);
+ any_path & operator=(any_path const & other);
+}
+
+std::ostream & operator<<(ostream & o, any_path const & a);
+
+class file_path : public any_path
+{
+public:
typedef enum { internal, external } source_type;
// input is always in utf8, because everything in our world is always in
// utf8 (except interface code itself).
@@ -44,10 +59,10 @@
file_path(std::vector const & pieces);
// returns raw normalized path string
+ // the string is always stored in normalized etc. form; so the generated
+ // copy constructor and assignment operator are fine.
std::string const & as_internal() const
- { return data; }
- // converts to native charset and path syntax
- std::string as_external() const;
+ { return data(); }
void split(std::vector & pieces) const;
@@ -59,44 +74,28 @@
bool operator <(const file_path & other) const
{ return data < other.data; }
-
-private:
- // this string is always stored in normalized etc. form; so the generated
- // copy constructor and assignment operator are fine.
- std::string data;
};
-std::ostream & operator<<(ostream & o, file_path const & a);
-
-class bookkeeping_path
+class bookkeeping_path : public any_path
{
public:
// path should _not_ contain the leading MT/
// and _should_ look like an internal path
bookkeeping_path(std::string const & path);
std::string as_external() const;
-private:
- std::string data;
};
-std::ostream & operator<<(ostream & o, bookkeeping_path const & a);
-
-class system_path
+ // this will always be an absolute path
+class system_path : public any_path
{
public:
// this path can contain anything, and it will be absolutified and
// 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 as_external() const;
bool empty() const;
-private:
- std::string data;
};
-std::ostream & operator<<(ostream & o, system_path const & a);
-
void
save_initial_path();
========================================================================
--- transforms.cc 0faca837b3bfbe8a8db6f1ee3d3901dbaf7aade4
+++ transforms.cc 4c0c80f47a736a45e4825212305604ed1414bc69
@@ -596,22 +596,22 @@
// this function must be fast. do not make it slow.
void
-utf8_to_system(std::string const & utf, std::string & ext)
+utf8_to_system(utf8 const & utf, std::string & ext)
{
if (system_charset_is_utf8())
- utf = ext;
+ ext = utf();
else if (system_charset_is_ascii_extension()
&& is_all_ascii(utf))
- utf = ext;
+ ext = utf();
else
- charset_convert("UTF-8", system_charset(), utf, ext);
+ charset_convert("UTF-8", system_charset(), utf(), ext);
}
void
utf8_to_system(utf8 const & utf, external & ext)
{
string out;
- utf8_to_system(utf(), out);
+ utf8_to_system(utf, out);
ext = out;
}
========================================================================
--- transforms.hh 89eac835c660c0f18f5e894c41d33d6b46b0870e
+++ transforms.hh 138f60ebea73d73425b0d4db26bac9cbee6e2e2d
@@ -174,7 +174,7 @@
std::string const & src, std::string & dst);
void system_to_utf8(external const & system, utf8 & utf);
void utf8_to_system(utf8 const & utf, external & system);
-void utf8_to_system(std::string const & utf, std::string & system);
+void utf8_to_system(utf8 const & utf, std::string & system);
void ace_to_utf8(ace const & ac, utf8 & utf);
void utf8_to_ace(utf8 const & utf, ace & a);