Skip to content

Commit

Permalink
mu-priority: implement priority_from_name
Browse files Browse the repository at this point in the history
  • Loading branch information
djcb committed Aug 21, 2023
1 parent bd17c21 commit b2918e2
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions lib/message/mu-priority.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ to_char(Priority prio)
}

/**
* Get the priority for some character; unknown onws
* Get the priority for some character; unknown ones
* become Normal.
*
* @param c some character
Expand All @@ -80,6 +80,28 @@ priority_from_char(char c)
}
}

/**
* Get the priority from their (internal) name, i.e., low/normal/high
* or shortcut.
*
* @param pname
*
* @return the priority or none
*/
static inline Option<Priority>
priority_from_name(std::string_view pname)
{
if (pname == "low" || pname == "l")
return Priority::Low;
else if (pname == "high" || pname == "h")
return Priority::High;
else if (pname == "normal" || pname == "n")
return Priority::Normal;
else
return Nothing;
}


/**
* Get the name for a given priority
*
Expand Down Expand Up @@ -108,10 +130,13 @@ constexpr const char*
priority_name_c_str(Priority prio)
{
switch (prio) {
case Priority::Low: return "low";
case Priority::High: return "high";
case Priority::Low:
return "low";
case Priority::High:
return "high";
case Priority::Normal:
default: return "normal";
default:
return "normal";
}
}

Expand Down

0 comments on commit b2918e2

Please sign in to comment.