Refactoring some stuff in the parser lib, moving functions out of headers
This commit is contained in:
parent
4580d68951
commit
fb3a2d94a0
19 changed files with 522 additions and 608 deletions
43
parser/src/length.c
Normal file
43
parser/src/length.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include "./length.h"
|
||||
#include "./point.h"
|
||||
|
||||
bool length_is_undefined(Length length)
|
||||
{
|
||||
return (length.bytes == 0 && length.extent.column != 0);
|
||||
}
|
||||
|
||||
Length length_min(Length len1, Length len2)
|
||||
{
|
||||
return ((len1.bytes < len2.bytes) ? len1 : len2);
|
||||
}
|
||||
|
||||
Length length_add(Length len1, Length len2)
|
||||
{
|
||||
Length result;
|
||||
|
||||
result.bytes = len1.bytes + len2.bytes;
|
||||
result.extent = point_add(len1.extent, len2.extent);
|
||||
return (result);
|
||||
}
|
||||
|
||||
Length length_sub(Length len1, Length len2)
|
||||
{
|
||||
Length result;
|
||||
|
||||
result.bytes = len1.bytes - len2.bytes;
|
||||
result.extent = point_sub(len1.extent, len2.extent);
|
||||
return (result);
|
||||
}
|
||||
|
||||
Length length_zero(void)
|
||||
{
|
||||
return ((Length){0, {0, 0}});
|
||||
}
|
||||
|
||||
Length length_saturating_sub(Length len1, Length len2)
|
||||
{
|
||||
if (len1.bytes > len2.bytes)
|
||||
return (length_sub(len1, len2));
|
||||
else
|
||||
return (length_zero());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue