/**
 * File:	include/users/routines.ycp
 * Package:	Configuration of users and groups
 * Summary:	various routines
 * Authors:	Jiri Suchomel <jsuchome@suse.cz>
 *
 * $Id: routines.ycp 15654 2004-03-08 16:02:34Z jsuchome $
 *
 */
{
textdomain "users";

/**
 * Split cn (fullname) in forename and surname.
 * @param what `surname or `forename
 * @param cn fullname
 * @param type user type
 * @return string selected part of user name
 */
define string SplitFullName(symbol what,string cn) ``{

    if( cn == nil )
        cn = "";

    // if cn is to be substituted, do not try to resolve givenName/sn
    if (issubstring (cn, "%"))
	return "";

    list<string> strs    = splitstring(cn , " ");
    integer i       = 1;
    string sn  = "";
    string givenName = "";

    foreach(string str, strs, ``{
        if ( i < size( strs) )
        {
        if( givenName == "" ) givenName = str;
        else givenName = givenName + " " + str;
        }
        else  sn = str;
        i = i + 1;
    });
    if ( what == `sn  ) return sn;
    if ( what == `givenName ) return givenName;
}


} // EOF
