Xgit v0.2.5 Xgit.Util.RawParseUtils View Source
Handy utility functions to parse raw object contents.
Link to this section Summary
Functions
Return the portion of the charlist b
that starts with the prefix prefix
.
Locate the author
header line data.
Locate the committer
header line data.
Convert a list of bytes to an Elixir (UTF-8) string when the encoding is not definitively known. Try parsing as a UTF-8 byte array first, then try ISO-8859-1.
Locate the encoding
header line data.
Locate the end of the header. Note that headers may be more than one line long.
Find the start of the contents of a given header in the given charlist.
Locate the first position after a given character.
Locate the first position after the next LF.
Locate the first position of either the given character or LF.
Parse a base-10 numeric value from a charlist of ASCII digits into a number.
Parse the encoding
header into a character set reference.
Parse the encoding
header as a string.
Parse 4 hex digits from a byte list to an integer.
Parse 8 hex digits from a byte list to an integer.
Parse a single hex digit from a byte list to an integer.
Parse 16 hex digits from a byte list to an integer.
Parse a git-style timezone string.
Locate the tagger
header line data.
Return the contents of the charlist up to, but not including, the next end-of-paragraph sequence.
Return the portion of the byte array up to, but not including the last instance of
ch
, disregarding any trailing spaces.
Return the contents of the charlist up to, but not including, the next LF.
Return the contents of the charlist up to, but not including, the next instance of the given character or LF.
Link to this section Functions
Return the portion of the charlist b
that starts with the prefix prefix
.
Return Values
If b
does in fact start with prefix
, return the portion of the charlist
that follows prefix
.
If not, return nil
.
Locate the author
header line data.
Returns a charlist beginning just after the space in author
which should be
the first character of the author's name. If no author header can be located,
nil
is returned.
Locate the committer
header line data.
Returns a charlist beginning just after the space in committer
which should be
the first character of the committer's name. If no committer header can be located,
nil
is returned.
Convert a list of bytes to an Elixir (UTF-8) string when the encoding is not definitively known. Try parsing as a UTF-8 byte array first, then try ISO-8859-1.
PORTING NOTE: A lot of the simplification of this compared to jgit's implementation of RawParseUtils.decode comes from the observation that the only character set ever passed to jgit's decode was UTF-8. We've baked that assumption into this implementation. Should other character sets come into play, this will necessarily become more complicated.
Locate the encoding
header line data.
Returns a charlist beginning just after the space in encoding
which should be
the first character of the encoding's name. If no encoding header can be located,
nil
is returned (and UTF-8 should be assumed).
Locate the end of the header. Note that headers may be more than one line long.
Returns charlist beginning just after the header. This is either []
or the
charlist beginning with the \n
character that terminates the header.
Find the start of the contents of a given header in the given charlist.
Returns charlist beginning at the start of the header's contents or nil
if not found.
PORTING NOTE: Unlike the jgit version of this function, it does not advance
to the beginning of the next line. Because the API speaks in charlists, we cannot
differentiate between the beginning of the initial string buffer and a subsequent
internal portion of the buffer. Clients may need to add their own call to next_lf/1
where it would not have been necessary in jgit.
Locate the first position after a given character.
Locate the first position after the next LF.
This method stops on the first \n
it finds.
Locate the first position of either the given character or LF.
This method stops on the first match it finds from either char
or \n
.
Parse a base-10 numeric value from a charlist of ASCII digits into a number.
Similar to Integer.parse/2
but uses charlist instead.
Digit sequences can begin with an optional run of spaces before the
sequence, and may start with a +
or a -
to indicate sign position.
Any other characters will cause the method to stop and return the current
result to the caller.
Returns {number, new_buffer}
where number
is the integer that was
found (or 0 if no number found there) and new_buffer
is the charlist
following the number that was parsed.
parse_encoding(b)
View Sourceparse_encoding(b :: charlist()) :: :utf8 | :latin1
Parse the encoding
header into a character set reference.
Returns :utf8
or :latin1
.
Raises ArgumentError
if the character set is unknown.
WARNING: Compared to jgit, the character set support in xgit is limited.
Parse the encoding
header as a string.
Returns the encoding header as specified in the commit or nil
if the header
was not present and UTF-8 should be assumed.
Parse 4 hex digits from a byte list to an integer.
The number is read in network byte order, that is, most significant nybble first.
Return Value
Returns {number, new_buffer}
where number
is the integer that was
found (or 0 if no number found there) and new_buffer
is the charlist
following the number that was parsed.
Parse 8 hex digits from a byte list to an integer.
The number is read in network byte order, that is, most significant nybble first.
Return Value
Returns {number, new_buffer}
where number
is the integer that was
found (or 0 if no number found there) and new_buffer
is the charlist
following the number that was parsed.
Parse a single hex digit from a byte list to an integer.
The number is read in network byte order, that is, most significant nybble first.
Return Value
Returns {number, new_buffer}
where number
is the integer that was
found (or 0 if no number found there) and new_buffer
is the charlist
following the number that was parsed.
Parse 16 hex digits from a byte list to an integer.
The number is read in network byte order, that is, most significant nybble first.
Return Value
Returns {number, new_buffer}
where number
is the integer that was
found (or 0 if no number found there) and new_buffer
is the charlist
following the number that was parsed.
parse_timezone_offset(b)
View Sourceparse_timezone_offset(b :: charlist()) :: {Xgit.Core.PersonIdent.tz_offset(), charlist()}
Parse a git-style timezone string.
The sequence -0315
will be parsed as the numeric value -195, as the
lower two positions count minutes, not 100ths of an hour.
Return Value
Returns {number, new_buffer}
where number
is the time zone offset in minutes
that was found (or 0 if no number found there) and new_buffer
is the charlist
following the number that was parsed.
Locate the tagger
header line data.
Returns a charlist beginning just after the space in tagger
which should be
the first character of the tagger's name. If no tagger header can be located,
nil
is returned.
Return the contents of the charlist up to, but not including, the next end-of-paragraph sequence.
Return the portion of the byte array up to, but not including the last instance of
ch
, disregarding any trailing spaces.
Return the contents of the charlist up to, but not including, the next LF.
Return the contents of the charlist up to, but not including, the next instance of the given character or LF.