2323
2424#include " log.h"
2525
26+ namespace {
27+
28+ // Converts a string to ASCII lower case.
29+ std::string ToLower (std::string_view const s) {
30+ std::string r (s);
31+ for (char & c : r) {
32+ if (' A' <= c && c <= ' Z' ) {
33+ c += ' a' - ' A' ;
34+ }
35+ }
36+
37+ return r;
38+ }
39+
40+ } // namespace
41+
2642bool Path::redact = false ;
2743
2844std::ostream& operator <<(std::ostream& out, const Path path) {
@@ -67,7 +83,7 @@ Path Path::WithoutTrailingSeparator() const {
6783Path::size_type Path::FinalExtensionPosition () const {
6884 const size_type last_dot = find_last_of (" /. " );
6985 if (last_dot == npos || at (last_dot) != ' .' || last_dot == 0 ||
70- last_dot == size () - 1 || size () - last_dot > 6 ) {
86+ last_dot == size () - 1 || size () - last_dot > 8 ) {
7187 return size ();
7288 }
7389
@@ -87,17 +103,16 @@ Path::size_type Path::ExtensionPosition() const {
87103
88104 // Extract extension without dot and in ASCII lowercase.
89105 assert (at (last_dot) == ' .' );
90- std::string ext (substr (last_dot + 1 ));
91- for (char & c : ext) {
92- if (' A' <= c && c <= ' Z' ) {
93- c += ' a' - ' A' ;
94- }
95- }
106+ const std::string ext = ToLower (substr (last_dot + 1 ));
96107
97108 // Is it a special extension?
98109 static const std::unordered_set<std::string_view> special_exts = {
99- " z" , " gz" , " bz" , " bz2" , " xz" , " zst" , " lz" , " lzma" };
100- if (special_exts.count (ext)) {
110+ " asc" , " b64" , " base64" , " br" , " brotli" , " bz" , " bz2" ,
111+ " bzip2" , " gpg" , " grz" , " grzip" , " gz" , " gzip" , " lrz" ,
112+ " lrzip" , " lz" , " lzip" , " lz4" , " lzma" , " lzo" , " lzop" ,
113+ " pgp" , " uu" , " xz" , " z" , " zst" , " zstd" };
114+
115+ if (special_exts.contains (ext)) {
101116 return Path (substr (0 , last_dot)).FinalExtensionPosition ();
102117 }
103118
0 commit comments