Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › std/ › SemanticVersion.zig › order
order
SemanticVersion.order
pub fn order (lhs : Version , rhs : Version ) std .math .Order
File
Code
pub fn order (lhs : Version , rhs : Version ) std .math .Order {
if (lhs .major < rhs .major ) return .lt ;
if (lhs .major > rhs .major ) return .gt ;
if (lhs .minor < rhs .minor ) return .lt ;
if (lhs .minor > rhs .minor ) return .gt ;
if (lhs .patch < rhs .patch ) return .lt ;
if (lhs .patch > rhs .patch ) return .gt ;
if (lhs .pre != null and rhs .pre == null ) return .lt ;
if (lhs .pre == null and rhs .pre == null ) return .eq ;
if (lhs .pre == null and rhs .pre != null ) return .gt ;
var lhs_pre_it = std .mem .splitScalar (u8 , lhs .pre .?, '.' );
var rhs_pre_it = std .mem .splitScalar (u8 , rhs .pre .?, '.' );
while (true ) {
const next_lid = lhs_pre_it .next ();
const next_rid = rhs_pre_it .next ();
if (next_lid == null and next_rid != null ) return .lt ;
if (next_lid == null and next_rid == null ) return .eq ;
if (next_lid != null and next_rid == null ) return .gt ;
const lid = next_lid .?;
const rid = next_rid .?;
// Attempt to parse identifiers as numbers. Overflows are checked by parse.
const lnum : ?usize = std .fmt .parseUnsigned (usize , lid , 10 ) catch |err | switch (err ) {
error .InvalidCharacter => null ,
error .Overflow => unreachable ,
};
const rnum : ?usize = std .fmt .parseUnsigned (usize , rid , 10 ) catch |err | switch (err ) {
error .InvalidCharacter => null ,
error .Overflow => unreachable ,
};
if (lnum != null and rnum == null ) return .lt ;
if (lnum == null and rnum != null ) return .gt ;
// Identifiers with letters or hyphens are compared lexically in ASCII sort order.
if (lnum != null and rnum != null ) {
if (lnum .? < rnum .?) return .lt ;
if (lnum .? > rnum .?) return .gt ;
} else {
const ord = std .mem .order (u8 , lid , rid );
if (ord != .eq ) return ord ;
}
}
}