From 2a7a93bb9e6f828ea0d4b59b400fbb2e16657c9c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 3 Jun 2019 12:55:14 +0300 Subject: Rename traits alias to traits_type for basic_path, basic_url, and string_table class templates --- libbutl/filesystem.cxx | 4 ++-- libbutl/path-map.mxx | 9 +++++---- libbutl/path.ixx | 52 ++++++++++++++++++++++++++---------------------- libbutl/path.mxx | 26 ++++++++++++++---------- libbutl/path.txx | 22 ++++++++++---------- libbutl/process.cxx | 2 +- libbutl/project-name.cxx | 4 ++-- libbutl/string-table.mxx | 2 +- libbutl/string-table.txx | 7 +++---- libbutl/url.mxx | 10 +++++----- libbutl/url.txx | 46 +++++++++++++++++++++--------------------- tests/process/driver.cxx | 2 +- tests/url/driver.cxx | 14 ++++++------- 13 files changed, 106 insertions(+), 94 deletions(-) diff --git a/libbutl/filesystem.cxx b/libbutl/filesystem.cxx index 40b4304..dad256e 100644 --- a/libbutl/filesystem.cxx +++ b/libbutl/filesystem.cxx @@ -1630,8 +1630,8 @@ namespace butl // The name doesn't match the pattern if it is of a different type than the // pattern is. // - bool pd (pi != pe && path::traits::is_separator (*pi)); - bool nd (ni != ne && path::traits::is_separator (*ni)); + bool pd (pi != pe && path::traits_type::is_separator (*pi)); + bool nd (ni != ne && path::traits_type::is_separator (*ni)); if (pd != nd) return false; diff --git a/libbutl/path-map.mxx b/libbutl/path-map.mxx index 1cd4ab0..2325723 100644 --- a/libbutl/path-map.mxx +++ b/libbutl/path-map.mxx @@ -52,7 +52,7 @@ LIBBUTL_MODEXPORT namespace butl typedef C delimiter_type; typedef typename key_type::string_type string_type; typedef typename key_type::size_type size_type; - typedef typename key_type::traits traits_type; + typedef typename key_type::traits_type traits_type; explicit compare_prefix (delimiter_type) {} @@ -129,7 +129,7 @@ LIBBUTL_MODEXPORT namespace butl static bool root (const string_type& p) { - return p.size () == 1 && key_type::traits::is_separator (p[0]); + return p.size () == 1 && key_type::traits_type::is_separator (p[0]); } }; @@ -137,9 +137,10 @@ LIBBUTL_MODEXPORT namespace butl // path_traits is used instead). // template - using path_map = prefix_map; + using path_map = + prefix_map; template using dir_path_map = - prefix_map; + prefix_map; } diff --git a/libbutl/path.ixx b/libbutl/path.ixx index 578db81..9622a81 100644 --- a/libbutl/path.ixx +++ b/libbutl/path.ixx @@ -58,28 +58,29 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. simple () const { return empty () || - traits::rfind_separator (this->path_, _size () - 1) == string_type::npos; + traits_type::rfind_separator (this->path_, _size () - 1) == + string_type::npos; } template inline bool basic_path:: absolute () const { - return traits::absolute (this->path_); + return traits_type::absolute (this->path_); } template inline bool basic_path:: current () const { - return traits::current (this->path_); + return traits_type::current (this->path_); } template inline bool basic_path:: parent () const { - return traits::parent (this->path_); + return traits_type::parent (this->path_); } template @@ -87,14 +88,14 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. normalized (bool sep) const { return (!sep || this->tsep_ <= 1) && - traits::normalized (this->path_, sep); + traits_type::normalized (this->path_, sep); } template inline bool basic_path:: root () const { - return traits::root (this->path_); + return traits_type::root (this->path_); } template @@ -116,10 +117,10 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. // The second condition guards against the /foo-bar vs /foo case. // return n >= pn && - traits::compare (s.c_str (), pn, ps.c_str (), pn) == 0 && - (traits::is_separator (ps.back ()) || // p ends with a separator + traits_type::compare (s.c_str (), pn, ps.c_str (), pn) == 0 && + (traits_type::is_separator (ps.back ()) || // p ends with a separator n == pn || // *this == p - traits::is_separator (s[pn])); // next char is a separator + traits_type::is_separator (s[pn])); // next char is a separator } template @@ -141,9 +142,12 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. // The second condition guards against the /foo-bar vs bar case. // return n >= pn && - traits::compare (s.c_str () + n - pn, pn, ps.c_str (), pn) == 0 && - (n == pn || // *this == p - traits::is_separator (s[n - pn - 1])); // previous char is a separator + traits_type::compare (s.c_str () + n - pn, pn, ps.c_str (), pn) == 0 && + (n == pn || // *this == p + // + // Previous char is a separator. + // + traits_type::is_separator (s[n - pn - 1])); } template @@ -158,7 +162,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. size_type n (_size ()); size_type p (n != 0 - ? traits::rfind_separator (s, n - 1) + ? traits_type::rfind_separator (s, n - 1) : string_type::npos); return p != string_type::npos @@ -174,7 +178,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. size_type n (_size ()); size_type p (n != 0 - ? traits::rfind_separator (s, n - 1) + ? traits_type::rfind_separator (s, n - 1) : string_type::npos); if (p != string_type::npos) @@ -202,7 +206,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. size_type n (_size ()); size_type p (n != 0 - ? traits::rfind_separator (s, n - 1) + ? traits_type::rfind_separator (s, n - 1) : string_type::npos); return p != string_type::npos @@ -218,7 +222,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. size_type n (_size ()); size_type p (n != 0 - ? traits::rfind_separator (s, n - 1) + ? traits_type::rfind_separator (s, n - 1) : string_type::npos); s.resize (p != string_type::npos ? p + 1 : 0); // Include trailing slash. @@ -234,7 +238,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. const string_type& s (this->path_); size_type b (s.empty () ? string_type::npos : 0); - size_type e (b == 0 ? traits::find_separator (s) : b); + size_type e (b == 0 ? traits_type::find_separator (s) : b); return iterator (this, b, e); } @@ -266,7 +270,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. inline basic_path& basic_path:: canonicalize () { - traits::canonicalize (this->path_); + traits_type::canonicalize (this->path_); if (this->tsep_ > 1) // Non-canonical trailing separator. this->tsep_ = 1; @@ -296,7 +300,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. complete (); normalize (true); #else - traits::realize (this->path_); // Note: we retain the trailing slash. + traits_type::realize (this->path_); // Note: we retain the trailing slash. #endif return *this; } @@ -333,7 +337,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. // of the small string optimization). // const string_type& s (this->path_); - size_type p (traits::find_extension (s)); + size_type p (traits_type::find_extension (s)); return p != string_type::npos ? basic_path (data_type (string_type (s, 0, p), this->tsep_)) @@ -345,7 +349,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. make_base () { string_type& s (this->path_); - size_type p (traits::find_extension (s)); + size_type p (traits_type::find_extension (s)); if (p != string_type::npos) { @@ -365,7 +369,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. extension () const { const string_type& s (this->path_); - size_type p (traits::find_extension (s)); + size_type p (traits_type::find_extension (s)); return p != string_type::npos ? string_type (s.c_str () + p + 1) : string_type (); @@ -376,7 +380,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. extension_cstring () const { const string_type& s (this->path_); - size_type p (traits::find_extension (s)); + size_type p (traits_type::find_extension (s)); return p != string_type::npos ? s.c_str () + p + 1 : nullptr; } @@ -445,7 +449,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. // For now we won't allow the slash and will always add the canonical one // for dir_path (via cast()). // - if (traits::find_separator (r, rn) != nullptr) + if (traits_type::find_separator (r, rn) != nullptr) throw invalid_basic_path (r); combine (r, rn, 0); diff --git a/libbutl/path.mxx b/libbutl/path.mxx index 1b1513a..d5dde59 100644 --- a/libbutl/path.mxx +++ b/libbutl/path.mxx @@ -655,7 +655,7 @@ LIBBUTL_MODEXPORT namespace butl using string_type = std::basic_string; using size_type = typename string_type::size_type; using difference_type = typename string_type::difference_type; - using traits = path_traits; //@@ TODO: rename to traits_type. + using traits_type = path_traits; struct iterator; using reverse_iterator = std::reverse_iterator; @@ -717,7 +717,8 @@ LIBBUTL_MODEXPORT namespace butl // underlying OS errors. // static dir_type - current_directory () {return dir_type (traits::current_directory ());} + current_directory () { + return dir_type (traits_type::current_directory ());} static void current_directory (basic_path const&); @@ -726,13 +727,13 @@ LIBBUTL_MODEXPORT namespace butl // underlying OS errors. // static dir_type - home_directory () {return dir_type (traits::home_directory ());} + home_directory () {return dir_type (traits_type::home_directory ());} // Return the temporary directory. Throw std::system_error to report // underlying OS errors. // static dir_type - temp_directory () {return dir_type (traits::temp_directory ());} + temp_directory () {return dir_type (traits_type::temp_directory ());} // Return a temporary path. The path is constructed by starting with the // temporary directory and then appending a path component consisting of @@ -744,7 +745,7 @@ LIBBUTL_MODEXPORT namespace butl temp_path (const string_type& prefix) { basic_path r (temp_directory ()); - r /= traits::temp_name (prefix); + r /= traits_type::temp_name (prefix); return r; } @@ -935,7 +936,9 @@ LIBBUTL_MODEXPORT namespace butl // Find next trailing separator. // - e_ = b_ != string_type::npos ? traits::find_separator (s, b_) : b_; + e_ = b_ != string_type::npos + ? traits_type::find_separator (s, b_) + : b_; return *this; } @@ -947,8 +950,8 @@ LIBBUTL_MODEXPORT namespace butl // Find the new end. // - e_ = b_ == string_type::npos // Past end? - ? (traits::is_separator (s.back ()) // Have trailing slash? + e_ = b_ == string_type::npos // Past end? + ? (traits_type::is_separator (s.back ()) // Have trailing slash? ? s.size () - 1 : string_type::npos) : b_ - 1; @@ -957,7 +960,10 @@ LIBBUTL_MODEXPORT namespace butl // b_ = e_ == 0 // Empty component? ? string_type::npos - : traits::rfind_separator (s, e_ != string_type::npos ? e_ - 1 : e_); + : traits_type::rfind_separator (s, + e_ != string_type::npos + ? e_ - 1 + : e_); b_ = b_ == string_type::npos // First component? ? 0 @@ -1101,7 +1107,7 @@ LIBBUTL_MODEXPORT namespace butl template int compare (const basic_path& x) const { - return traits::compare (this->path_, x.path_);} + return traits_type::compare (this->path_, x.path_);} public: // Path string and representation. The string does not contain the diff --git a/libbutl/path.txx b/libbutl/path.txx index bb2ab79..e407a16 100644 --- a/libbutl/path.txx +++ b/libbutl/path.txx @@ -158,9 +158,9 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. { size_type n (_size ()); - for (size_type b (0), e (traits::find_separator (s, 0, n)); + for (size_type b (0), e (traits_type::find_separator (s, 0, n)); ; - e = traits::find_separator (s, b, n)) + e = traits_type::find_separator (s, b, n)) { ps.push_back ( string_type (s, b, (e == string_type::npos ? n : e) - b)); @@ -172,7 +172,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. // Skip consecutive directory separators. // - while (e != n && traits::is_separator (s[e])) + while (e != n && traits_type::is_separator (s[e])) ++e; if (e == n) @@ -186,7 +186,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. if (!tsep) { const string_type& l (ps.back ()); - if (traits::current (l) || traits::parent (l)) + if (traits_type::current (l) || traits_type::parent (l)) tsep = true; } } @@ -199,12 +199,14 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. { string_type& s (*i); - if (traits::current (s)) + if (traits_type::current (s)) continue; // If '..' then pop the last directory from r unless it is '..'. // - if (traits::parent (s) && !r.empty () && !traits::parent (r.back ())) + if (traits_type::parent (s) && + !r.empty () && + !traits_type::parent (r.back ())) { // Cannot go past the root directory. // @@ -235,7 +237,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. // what getcwd() returns. // p = *i; - p[0] = traits::toupper (p[0]); + p[0] = traits_type::toupper (p[0]); } else { @@ -251,7 +253,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. p += *i; if (++i != e) - p += traits::directory_separator; + p += traits_type::directory_separator; } if (tsep) @@ -262,7 +264,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. // if (abs) { - p += traits::directory_separator; + p += traits_type::directory_separator; ts = -1; } else if (!cur_empty) // Collapse to canonical current directory. @@ -292,7 +294,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. if (s.empty ()) throw invalid_basic_path (s); - traits::current_directory (s); + traits_type::current_directory (s); } template diff --git a/libbutl/process.cxx b/libbutl/process.cxx index 618c2aa..d7cabf1 100644 --- a/libbutl/process.cxx +++ b/libbutl/process.cxx @@ -254,7 +254,7 @@ namespace butl { // Note that there is a similar version for Win32. - typedef path::traits traits; + typedef path::traits_type traits; size_t fn (strlen (f)); diff --git a/libbutl/project-name.cxx b/libbutl/project-name.cxx index 43da5a7..4c04e5f 100644 --- a/libbutl/project-name.cxx +++ b/libbutl/project-name.cxx @@ -85,7 +85,7 @@ namespace butl { using std::string; - size_t p (path::traits::find_extension (value_)); + size_t p (path::traits_type::find_extension (value_)); if (e != nullptr && p != string::npos && @@ -100,7 +100,7 @@ namespace butl { using std::string; - size_t p (path::traits::find_extension (value_)); + size_t p (path::traits_type::find_extension (value_)); return p != string::npos ? string (value_, p + 1) : string (); } diff --git a/libbutl/string-table.mxx b/libbutl/string-table.mxx index e684567..5807921 100644 --- a/libbutl/string-table.mxx +++ b/libbutl/string-table.mxx @@ -104,7 +104,7 @@ LIBBUTL_MODEXPORT namespace butl using key_type = butl::map_key; using value_type = string_table_element; using map_type = std::unordered_map; - using traits = string_table_traits; // @@ TODO: rename traits_type; + using traits_type = string_table_traits; map_type map_; std::vector vec_; diff --git a/libbutl/string-table.txx b/libbutl/string-table.txx index 3ee710a..77079b2 100644 --- a/libbutl/string-table.txx +++ b/libbutl/string-table.txx @@ -12,15 +12,14 @@ namespace butl // Note: move(d) would be tricky since the key still points to it. // - auto r (map_.emplace ( - key_type (&traits::key (d)), - value_type {static_cast (i), d})); + auto r (map_.emplace (key_type (&traits_type::key (d)), + value_type {static_cast (i), d})); if (r.second) { assert (i <= std::numeric_limits::max ()); - r.first->first.p = &traits::key (r.first->second.d); // Update key. + r.first->first.p = &traits_type::key (r.first->second.d); // Update key. vec_.push_back (r.first); } diff --git a/libbutl/url.mxx b/libbutl/url.mxx index d50ae55..ea01725 100644 --- a/libbutl/url.mxx +++ b/libbutl/url.mxx @@ -255,14 +255,14 @@ LIBBUTL_MODEXPORT namespace butl class basic_url { public: - using traits = T; //@@ TODO: rename traits_type. + using traits_type = T; - using string_type = typename traits::string_type; + using string_type = typename traits_type::string_type; using char_type = typename string_type::value_type; - using path_type = typename traits::path_type; + using path_type = typename traits_type::path_type; - using scheme_type = typename traits::scheme_type; - using authority_type = typename traits::authority_type; + using scheme_type = typename traits_type::scheme_type; + using authority_type = typename traits_type::authority_type; using host_type = typename authority_type::host_type; scheme_type scheme; diff --git a/libbutl/url.txx b/libbutl/url.txx index 3f07eb8..10d1fab 100644 --- a/libbutl/url.txx +++ b/libbutl/url.txx @@ -335,7 +335,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. throw invalid_argument ("invalid path"); } - path = traits::translate_path (string_type (i, j)); + path = traits_type::translate_path (string_type (i, j)); i = j; } @@ -372,13 +372,13 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. // Translate the scheme string representation to its type. // - optional s (traits::translate_scheme (u, - move (sc), - authority, - path, - query, - fragment, - rootless)); + optional s (traits_type::translate_scheme (u, + move (sc), + authority, + path, + query, + fragment, + rootless)); assert (s); scheme = *s; } @@ -395,13 +395,13 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. rootless = false; optional s ( - traits::translate_scheme (u, - string_type () /* scheme */, - authority, - path, - query, - fragment, - rootless)); + traits_type::translate_scheme (u, + string_type () /* scheme */, + authority, + path, + query, + fragment, + rootless)); if (!s) throw; @@ -417,13 +417,13 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. return string_type (); string_type u; - string_type r (traits::translate_scheme (u, - scheme, - authority, - path, - query, - fragment, - rootless)); + string_type r (traits_type::translate_scheme (u, + scheme, + authority, + path, + query, + fragment, + rootless)); // Return the custom URL pbject representation if provided. // @@ -451,7 +451,7 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason. if (!rootless) r += '/'; - r += traits::translate_path (*path); + r += traits_type::translate_path (*path); } if (query) diff --git a/tests/process/driver.cxx b/tests/process/driver.cxx index e3c8e4a..ee946ca 100644 --- a/tests/process/driver.cxx +++ b/tests/process/driver.cxx @@ -381,7 +381,7 @@ main (int argc, const char* argv[]) string paths (fp.directory ().string ()); if (optional p = getenv ("PATH")) - paths += string (1, path::traits::path_separator) + *p; + paths += string (1, path::traits_type::path_separator) + *p; setenv ("PATH", paths); diff --git a/tests/url/driver.cxx b/tests/url/driver.cxx index 8160d7d..5d6069f 100644 --- a/tests/url/driver.cxx +++ b/tests/url/driver.cxx @@ -349,13 +349,13 @@ try if (!u.empty ()) { wstring s; - wcout << wurl::traits::translate_scheme (s, - u.scheme, - nullopt, - nullopt, - nullopt, - nullopt, - false) << endl; + wcout << wurl::traits_type::translate_scheme (s, + u.scheme, + nullopt, + nullopt, + nullopt, + nullopt, + false) << endl; } else wcout << L"[null]" << endl; -- cgit v1.1