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 standard library.
std › SemanticVersion › order Public Function order Doc Source Public Function std.SemanticVersion.order
pub fn order (lhs : Version , rhs : Version ) std .math .Order Params File SemanticVersion.zig: 33
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 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 ;
// Iterate over pre-release identifiers until a difference is found.
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 ();
// A larger set of pre-release fields has a higher precedence than a smaller set.
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 .?; // Left identifier
const rid = next_rid .?; // Right identifier
// 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 ,
};
// Numeric identifiers always have lower precedence than non-numeric identifiers.
if (lnum != null and rnum == null ) return .lt ;
if (lnum == null and rnum != null ) return .gt ;
// Identifiers consisting of only digits are compared numerically.
// 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 ;
}
}
}