diff options
-rw-r--r-- | build/cxx/rule.cxx | 4 | ||||
-rw-r--r-- | build/parser.cxx | 12 | ||||
-rw-r--r-- | build/path | 27 | ||||
-rw-r--r-- | build/path.ixx | 16 | ||||
-rw-r--r-- | build/path.txx | 56 | ||||
-rw-r--r-- | build/prerequisite.cxx | 2 | ||||
-rw-r--r-- | build/target.cxx | 2 |
7 files changed, 55 insertions, 64 deletions
diff --git a/build/cxx/rule.cxx b/build/cxx/rule.cxx index 8d2c0b2..26ad213 100644 --- a/build/cxx/rule.cxx +++ b/build/cxx/rule.cxx @@ -208,6 +208,10 @@ namespace build // extension. Here we can assume the name part is a valid // filesystem name. // + // Note that if the file has no extension, we record an empty + // extension rather than NULL (which would signify that the + // extension needs to be added). + // path d (file.directory ()); string n (file.leaf ().base ().string ()); const char* es (file.extension ()); diff --git a/build/parser.cxx b/build/parser.cxx index 1cb0684..d1f3d8a 100644 --- a/build/parser.cxx +++ b/build/parser.cxx @@ -242,12 +242,12 @@ namespace build // Extract extension. // - string::size_type j (n.rfind ('.')); + string::size_type j (path::traits::find_extension (n)); if (j != string::npos) { - e = &extension_pool.find (n.c_str () + j + 1); - n.resize (j); + e = &extension_pool.find (n.c_str () + j); + n.resize (j - 1); } } @@ -318,12 +318,12 @@ namespace build // Extract extension. // - string::size_type j (n.rfind ('.')); + string::size_type j (path::traits::find_extension (n)); if (j != string::npos) { - e = &extension_pool.find (n.c_str () + j + 1); - n.resize (j); + e = &extension_pool.find (n.c_str () + j); + n.resize (j - 1); } } @@ -74,6 +74,33 @@ namespace build return string_type::npos; } + static size_type + find_extension (string_type const& s) + { + size_type i (s.size ()); + + for (; i > 0; --i) + { + C c (s[i - 1]); + + if (c == '.') + break; + + if (is_separator (c)) + { + i = 0; + break; + } + } + + // Weed out paths like ".txt" (and "/.txt") and "txt.". + // + if (i > 1 && !is_separator (s[i - 2]) && i != s.size ()) + return i - 1; + else + return string_type::npos; + } + static int compare (string_type const& l, string_type const& r) { diff --git a/build/path.ixx b/build/path.ixx index f742060..60d3bc3 100644 --- a/build/path.ixx +++ b/build/path.ixx @@ -57,6 +57,22 @@ namespace build return *this; } + template <typename C> + inline basic_path<C> basic_path<C>:: + base () const + { + size_type p (traits::find_extension (path_)); + return p != string_type::npos ? basic_path (path_.c_str (), p) : *this; + } + + template <typename C> + inline const C* basic_path<C>:: + extension () const + { + size_type p (traits::find_extension (path_)); + return p != string_type::npos ? path_.c_str () + p + 1 : nullptr; + } + #ifndef _WIN32 template <typename C> inline typename basic_path<C>::string_type basic_path<C>:: diff --git a/build/path.txx b/build/path.txx index f576870..881dc17 100644 --- a/build/path.txx +++ b/build/path.txx @@ -34,62 +34,6 @@ namespace build : basic_path (); } - template <typename C> - basic_path<C> basic_path<C>:: - base () const - { - size_type i (path_.size ()); - - for (; i > 0; --i) - { - if (path_[i - 1] == '.') - break; - - if (traits::is_separator (path_[i - 1])) - { - i = 0; - break; - } - } - - // Weed out paths like ".txt" and "/.txt" - // - if (i > 1 && !traits::is_separator (path_[i - 2])) - { - return basic_path (path_.c_str (), i - 1); - } - else - return *this; - } - - template <typename C> - const C* basic_path<C>:: - extension () const - { - size_type i (path_.size ()); - - for (; i > 0; --i) - { - if (path_[i - 1] == '.') - break; - - if (traits::is_separator (path_[i - 1])) - { - i = 0; - break; - } - } - - // Weed out paths like ".txt" and "/.txt" - // - if (i > 1 && !traits::is_separator (path_[i - 2])) - { - return path_.c_str () + i; - } - else - return nullptr; - } - #ifdef _WIN32 template <typename C> typename basic_path<C>::string_type basic_path<C>:: diff --git a/build/prerequisite.cxx b/build/prerequisite.cxx index 8d86392..71bde5f 100644 --- a/build/prerequisite.cxx +++ b/build/prerequisite.cxx @@ -46,7 +46,7 @@ namespace build os << p.name; - if (p.ext != nullptr) + if (p.ext != nullptr && !p.ext->empty ()) os << '.' << *p.ext; os << '}'; diff --git a/build/target.cxx b/build/target.cxx index 31a7f59..7a40c61 100644 --- a/build/target.cxx +++ b/build/target.cxx @@ -38,7 +38,7 @@ namespace build os << t.name; - if (t.ext != nullptr) + if (t.ext != nullptr && !t.ext->empty ()) os << '.' << *t.ext; os << '}'; |