diff mercurial/util.py @ 16360:e5788269741a

templates/filters: extracting the user portion of an email address Currently, the 'user' filter is using util.shortuser(text) (which clearly doesn't extract only the user portion of an email address, even though the help text says it does). The new 'emailuser' filter uses the new util.emailuser(text) function which, instead, does exactly that. The help text on the 'user' filter has been modified accordingly.
author Matteo Capobianco <m.capobianco@gmail.com>
date Wed, 28 Mar 2012 16:06:20 +0200
parents 3bcfea777efc
children f5dd179bfa4a
line wrap: on
line diff
--- a/mercurial/util.py	Thu Apr 05 19:23:04 2012 +0200
+++ b/mercurial/util.py	Wed Mar 28 16:06:20 2012 +0200
@@ -1125,6 +1125,16 @@
         user = user[:f]
     return user
 
+def emailuser(user):
+    """Return the user portion of an email address."""
+    f = user.find('@')
+    if f >= 0:
+        user = user[:f]
+    f = user.find('<')
+    if f >= 0:
+        user = user[f + 1:]
+    return user
+
 def email(author):
     '''get email of author.'''
     r = author.find('>')