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

Link to this function

after_prefix(b, prefix)

View Source
after_prefix(b :: charlist(), prefix :: charlist()) :: charlist() | nil

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.

Link to this function

author(b)

View Source
author(b :: charlist()) :: charlist() | 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.

Link to this function

committer(b)

View Source
committer(b :: charlist()) :: charlist() | nil

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.

Link to this function

decode(b)

View Source
decode(b :: [byte()]) :: String.t()

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.

Link to this function

encoding(b)

View Source
encoding(b :: charlist()) :: charlist() | nil

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).

Link to this function

header_end(b)

View Source
header_end(b :: charlist()) :: charlist()

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.

Link to this function

header_start(header_name, b)

View Source
header_start(header_name :: charlist(), b :: charlist()) :: charlist() | nil

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.

Link to this function

next(b, char)

View Source
next(b :: charlist(), char :: char()) :: charlist()

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.

Link to this function

next_lf(b, char)

View Source
next_lf(b :: charlist(), char :: char()) :: charlist()

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.

Link to this function

parse_base_10(b)

View Source
parse_base_10(b :: charlist()) :: {integer(), charlist()}

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.

Link to this function

parse_encoding(b)

View Source
parse_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.

Link to this function

parse_encoding_name(b)

View Source
parse_encoding_name(b :: charlist()) :: String.t() | nil

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.

Link to this function

parse_hex_int16(b)

View Source
parse_hex_int16(b :: charlist()) :: {integer(), charlist()}

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.

Link to this function

parse_hex_int32(b)

View Source
parse_hex_int32(b :: charlist()) :: {integer(), charlist()}

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.

Link to this function

parse_hex_int4(b)

View Source
parse_hex_int4(b :: charlist()) :: {integer(), charlist()}

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.

Link to this function

parse_hex_int64(b)

View Source
parse_hex_int64(b :: charlist()) :: {integer(), charlist()}

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.

Link to this function

parse_timezone_offset(b)

View Source
parse_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.

Link to this function

tagger(b)

View Source
tagger(b :: charlist()) :: charlist() | nil

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.

Link to this function

until_end_of_paragraph(b)

View Source
until_end_of_paragraph(b :: [byte()]) :: [byte()]

Return the contents of the charlist up to, but not including, the next end-of-paragraph sequence.

Link to this function

until_last_instance_of_trim(b, ch)

View Source
until_last_instance_of_trim(b :: [byte()], ch :: char()) :: [byte()]

Return the portion of the byte array up to, but not including the last instance of ch, disregarding any trailing spaces.

Link to this function

until_next_lf(b)

View Source
until_next_lf(b :: charlist()) :: charlist()

Return the contents of the charlist up to, but not including, the next LF.

Link to this function

until_next_lf(b, char)

View Source
until_next_lf(b :: charlist(), char :: char()) :: charlist()

Return the contents of the charlist up to, but not including, the next instance of the given character or LF.