Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Commit

Permalink
Merge 6fdb5b9 into d2f181a
Browse files Browse the repository at this point in the history
  • Loading branch information
scouten committed Oct 13, 2019
2 parents d2f181a + 6fdb5b9 commit 4d9c0c7
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions lib/xgit/core/person_ident.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ defmodule Xgit.Core.PersonIdent do

alias Xgit.Util.ParseCharlist
alias Xgit.Util.ParseDecimal
alias Xgit.Util.RawParseUtils

import Xgit.Util.ForceCoverage

Expand Down Expand Up @@ -89,19 +88,16 @@ defmodule Xgit.Core.PersonIdent do
`b` should be a charlist of an "author" or "committer" line pointing to the
character after the header name and space.
The functions `Xgit.Util.RawParseUtils.author/1` and `Xgit.Util.RawParseUtils.committer/1`
will return suitable charlists.
## Return Value
Returns a `PersonIdent` struct or `nil` if the charlist did not point to a
properly-formatted identity.
"""
@spec from_byte_list(b :: [byte]) :: t() | nil
def from_byte_list(b) when is_list(b) do
with [?< | email_start] <- RawParseUtils.next_lf(b, ?<),
with {_, [?< | email_start]} <- Enum.split_while(b, &(&1 != ?<)),
true <- has_closing_angle_bracket?(email_start),
email <- RawParseUtils.until_next_lf(email_start, ?>),
{email, _} <- Enum.split_while(email_start, &(&1 != ?>)),
name <- parse_name(b),
{time, tz} <- parse_tz(email_start) do
%__MODULE__{
Expand All @@ -119,7 +115,7 @@ defmodule Xgit.Core.PersonIdent do

defp parse_name(b) do
b
|> RawParseUtils.until_next_lf(?<)
|> Enum.take_while(&(&1 != ?<))
|> Enum.reverse()
|> drop_first_if_space()
|> Enum.reverse()
Expand All @@ -133,12 +129,7 @@ defmodule Xgit.Core.PersonIdent do
# another name-email pair may occur. We will ignore all kinds of
# "junk" following the first email.

# We've to use (emailE - 1) for the case that raw[email] is LF,
# otherwise we would run too far. "-2" is necessary to position
# before the LF in case of LF termination resp. the penultimate
# character if there is no trailing LF.

[?> | first_email_end] = RawParseUtils.next_lf(first_email_start, ?>)
[?> | first_email_end] = Enum.drop_while(first_email_start, &(&1 != ?>))
rev = Enum.reverse(first_email_end)

{tz, rev} = trim_word_and_rev(rev)
Expand Down

0 comments on commit 4d9c0c7

Please sign in to comment.