Kaydet (Commit) 62358316 authored tarafından Skip Montanaro's avatar Skip Montanaro

revert semantics of commonprefix to work character-by-character

üst 6424524f
......@@ -3,7 +3,6 @@
import os
import stat
import string
import re
def normcase(s):
......@@ -103,23 +102,18 @@ def dirname(p):
return split(p)[0]
# Return the longest prefix of all list elements.
def commonprefix(m):
"Given a list of pathnames, returns the longest common leading component"
"""Return the longest prefix of all list elements."""
if not m: return ''
n = map(string.lower, m)
for i in range(len(n)):
n[i] = re.split(r"[/\\]", n[i])
prefix = n[0]
for item in n:
prefix = m[0]
for item in m:
for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]:
prefix = prefix[:i]
if i == 0: return ''
break
return "\\".join(prefix)
return prefix
# Get size, mtime, atime of files.
......
......@@ -8,7 +8,6 @@ module as os.path.
import os
import stat
import string
import re
# Normalize the case of a pathname and map slashes to backslashes.
......@@ -159,18 +158,14 @@ def dirname(p):
def commonprefix(m):
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
n = map(string.lower, m)
for i in range(len(n)):
n[i] = re.split(r"[/\\]", n[i])
prefix = n[0]
for item in n:
prefix = m[0]
for item in m:
for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]:
prefix = prefix[:i]
if i == 0: return ''
break
return "\\".join(prefix)
return prefix
# Get size, mtime, atime of files.
......
......@@ -118,18 +118,14 @@ def dirname(p):
def commonprefix(m):
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
n = m[:]
for i in range(len(n)):
n[i] = n[i].split("/")
prefix = n[0]
for item in n:
prefix = m[0]
for item in m:
for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]:
prefix = prefix[:i]
if i == 0: return ''
break
return "/".join(prefix)
return prefix
# Get size, mtime, atime of files.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment