changeset 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 d23197e08d05
children 6097ede2be4d
files mercurial/templatefilters.py mercurial/util.py
diffstat 2 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatefilters.py	Thu Apr 05 19:23:04 2012 +0200
+++ b/mercurial/templatefilters.py	Wed Mar 28 16:06:20 2012 +0200
@@ -336,9 +336,14 @@
     return urllib.quote(text)
 
 def userfilter(text):
-    """:user: Any text. Returns the user portion of an email address."""
+    """:user: Any text. Returns a short representation of a user name or email
+    address."""
     return util.shortuser(text)
 
+def emailuser(text):
+    """:emailuser: Any text. Returns the user portion of an email address."""
+    return util.emailuser(text)
+
 def xmlescape(text):
     text = (text
             .replace('&', '&amp;')
@@ -382,6 +387,7 @@
     "tabindent": tabindent,
     "urlescape": urlescape,
     "user": userfilter,
+    "emailuser": emailuser,
     "xmlescape": xmlescape,
 }
 
--- 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('>')