Skip to content

Commit 7541b68

Browse files
committed
feat!: Rename Color.toHexString to Color.toCssHex
1 parent 76831cd commit 7541b68

File tree

5 files changed

+32
-26
lines changed

5 files changed

+32
-26
lines changed

CHANGELOG.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ All notable changes to this project will be documented in this file.
1414
The format is based on https://keepachangelog.com/[Keep a Changelog], and this
1515
project adheres to https://semver.org/[Semantic Versioning].
1616

17+
== {compare-url}/v0.2.0\...HEAD[Unreleased]
18+
19+
=== Changed
20+
21+
* Rename `Color.toHexString` to `Color.toCssHex` ({pull-request-url}/18[#18])
22+
1723
== {compare-url}/v0.1.0\...v0.2.0[0.2.0] - 2025-08-22
1824

1925
=== Changed

examples/parse.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn main() !void {
3030
try stdout.print("Name: {s}\n", .{name});
3131
{
3232
var buf: [9]u8 = undefined;
33-
const hex = try color.toHexString(&buf);
33+
const hex = try color.toCssHex(&buf);
3434
try stdout.print("Hex: {s}\n", .{hex});
3535
}
3636
{

src/color.zig

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub fn Color(comptime T: type) type {
109109
const color = Color(f64).fromRgba8(165, 42, 42, 255);
110110
try testing.expectEqualStrings("brown", color.name().?);
111111
var buf: [7]u8 = undefined;
112-
const hex = try color.toHexString(&buf);
112+
const hex = try color.toCssHex(&buf);
113113
try testing.expectEqualStrings("#a52a2a", hex);
114114
}
115115

@@ -152,7 +152,7 @@ pub fn Color(comptime T: type) type {
152152
const color = Color(f64).fromHsl(248.0, 0.39, 0.392, 1.0);
153153
try testing.expectEqual(null, color.name());
154154
var buf: [7]u8 = undefined;
155-
const hex = try color.toHexString(&buf);
155+
const hex = try color.toCssHex(&buf);
156156
try testing.expectEqualStrings("#473d8b", hex);
157157
}
158158

@@ -186,7 +186,7 @@ pub fn Color(comptime T: type) type {
186186
const color = Color(f64).fromHwb(50.6, 0.0, 0.0, 1.0);
187187
try testing.expectEqualStrings("gold", color.name().?);
188188
var buf: [7]u8 = undefined;
189-
const hex = try color.toHexString(&buf);
189+
const hex = try color.toCssHex(&buf);
190190
try testing.expectEqualStrings("#ffd700", hex);
191191
}
192192

@@ -554,7 +554,7 @@ pub fn Color(comptime T: type) type {
554554
.{ color.red, color.green, color.blue, color.alpha },
555555
);
556556
try testing.expectEqual(.{ 255, 255, 0, 255 }, color.toRgba8());
557-
const hex = try color.toHexString(&buf);
557+
const hex = try color.toCssHex(&buf);
558558
try testing.expectEqualStrings("#ffff00", hex);
559559
}
560560

@@ -565,7 +565,7 @@ pub fn Color(comptime T: type) type {
565565
.{ color.red, color.green, color.blue, color.alpha },
566566
);
567567
try testing.expectEqual(.{ 255, 0, 0, 255 }, color.toRgba8());
568-
const hex = try color.toHexString(&buf);
568+
const hex = try color.toCssHex(&buf);
569569
try testing.expectEqualStrings("#ff0000", hex);
570570
}
571571

@@ -576,14 +576,14 @@ pub fn Color(comptime T: type) type {
576576
.{ color.red, color.green, color.blue, color.alpha },
577577
);
578578
try testing.expectEqual(.{ 255, 0, 0, 255 }, color.toRgba8());
579-
const hex = try color.toHexString(&buf);
579+
const hex = try color.toCssHex(&buf);
580580
try testing.expectEqualStrings("#ff0000", hex);
581581
}
582582

583583
{
584584
const color = try Color(f64).parse("#ff00007f");
585585
try testing.expectEqual(.{ 255, 0, 0, 127 }, color.toRgba8());
586-
const hex = try color.toHexString(&buf);
586+
const hex = try color.toCssHex(&buf);
587587
try testing.expectEqualStrings("#ff00007f", hex);
588588
}
589589
}
@@ -702,9 +702,9 @@ pub fn Color(comptime T: type) type {
702702
}
703703

704704
/// Returns the
705-
/// [RGB hexadecimal color string](https://www.w3.org/TR/css-color-4/#hex-notation)
705+
/// [CSS RGB hexadecimal color representation](https://www.w3.org/TR/css-color-4/#hex-notation)
706706
/// of this `Color` in lower case.
707-
pub fn toHexString(self: Self, buf: []u8) BufPrintError![]u8 {
707+
pub fn toCssHex(self: Self, buf: []u8) BufPrintError![]u8 {
708708
const r, const g, const b, const a = self.toRgba8();
709709

710710
return if (a < math.maxInt(u8))
@@ -713,15 +713,15 @@ pub fn Color(comptime T: type) type {
713713
fmt.bufPrint(buf, "#{x:0>2}{x:0>2}{x:0>2}", .{ r, g, b });
714714
}
715715

716-
test toHexString {
716+
test toCssHex {
717717
var buf: [9]u8 = undefined;
718718

719719
const color = try Color(f64).parse("mediumpurple");
720-
const hex = try color.toHexString(&buf);
720+
const hex = try color.toCssHex(&buf);
721721
try testing.expectEqualStrings("#9370db", hex);
722722

723723
const color_with_alpha = try Color(f64).parse("rgb(147 112 219 / 49.8%)");
724-
const hex_with_alpha = try color_with_alpha.toHexString(&buf);
724+
const hex_with_alpha = try color_with_alpha.toCssHex(&buf);
725725
try testing.expectEqualStrings("#9370db7f", hex_with_alpha);
726726
}
727727

tests/color.zig

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test "basic" {
1818
.{ color.red, color.green, color.blue, color.alpha },
1919
);
2020
try testing.expectEqual(.{ 255, 0, 0, 255 }, color.toRgba8());
21-
const hex = try color.toHexString(&buf);
21+
const hex = try color.toCssHex(&buf);
2222
try testing.expectEqualStrings("#ff0000", hex);
2323
try testing.expectEqual(.{ 0.0, 1.0, 0.5, 1.0 }, color.toHsl());
2424
try testing.expectEqual(.{ 0.0, 0.0, 0.0, 1.0 }, color.toHwb());
@@ -28,7 +28,7 @@ test "basic" {
2828
{
2929
const color = Color(ft).init(1.0, 0.0, 0.0, 0.5);
3030
try testing.expectEqual(.{ 255, 0, 0, 128 }, color.toRgba8());
31-
const hex = try color.toHexString(&buf);
31+
const hex = try color.toCssHex(&buf);
3232
try testing.expectEqualStrings("#ff000080", hex);
3333
}
3434

@@ -99,16 +99,16 @@ test "convert colors" {
9999
{
100100
const a, const b, const c, const d = col.toLinearRgb();
101101
const x = Color(ft).fromLinearRgb(a, b, c, d);
102-
const col_hex = try col.toHexString(&buf);
103-
const x_hex = try x.toHexString(&buf);
102+
const col_hex = try col.toCssHex(&buf);
103+
const x_hex = try x.toCssHex(&buf);
104104
try testing.expectEqualStrings(col_hex, x_hex);
105105
}
106106

107107
{
108108
const a, const b, const c, const d = col.toOklab();
109109
const x = Color(ft).fromOklab(a, b, c, d);
110-
const col_hex = try col.toHexString(&buf);
111-
const x_hex = try x.toHexString(&buf);
110+
const col_hex = try col.toCssHex(&buf);
111+
const x_hex = try x.toCssHex(&buf);
112112
try testing.expectEqualStrings(col_hex, x_hex);
113113
}
114114
}
@@ -139,41 +139,41 @@ test "convert colors" {
139139
inline for (float_types) |ft| {
140140
for (data) |s| {
141141
const col = try Color(ft).parse(s);
142-
const hex = try col.toHexString(&buf);
142+
const hex = try col.toCssHex(&buf);
143143
try testing.expectEqualStrings(s, hex);
144144

145145
{
146146
const a, const b, const c, const d = col.toRgba8();
147147
const x = Color(ft).fromRgba8(a, b, c, d);
148-
const x_hex = try x.toHexString(&buf);
148+
const x_hex = try x.toCssHex(&buf);
149149
try testing.expectEqualStrings(s, x_hex);
150150
}
151151

152152
{
153153
const a, const b, const c, const d = col.toHsl();
154154
const x = Color(ft).fromHsl(a, b, c, d);
155-
const x_hex = try x.toHexString(&buf);
155+
const x_hex = try x.toCssHex(&buf);
156156
try testing.expectEqualStrings(s, x_hex);
157157
}
158158

159159
{
160160
const a, const b, const c, const d = col.toHwb();
161161
const x = Color(ft).fromHwb(a, b, c, d);
162-
const x_hex = try x.toHexString(&buf);
162+
const x_hex = try x.toCssHex(&buf);
163163
try testing.expectEqualStrings(s, x_hex);
164164
}
165165

166166
{
167167
const a, const b, const c, const d = col.toLinearRgb();
168168
const x = Color(ft).fromLinearRgb(a, b, c, d);
169-
const x_hex = try x.toHexString(&buf);
169+
const x_hex = try x.toCssHex(&buf);
170170
try testing.expectEqualStrings(s, x_hex);
171171
}
172172

173173
{
174174
const a, const b, const c, const d = col.toOklab();
175175
const x = Color(ft).fromOklab(a, b, c, d);
176-
const x_hex = try x.toHexString(&buf);
176+
const x_hex = try x.toCssHex(&buf);
177177
try testing.expectEqualStrings(s, x_hex);
178178
}
179179
}

tests/named_colors.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ test "named_colors" {
197197
inline for (float_types) |ft| {
198198
outer: for (test_data) |td| {
199199
const c1 = try Color(ft).parse(td[0]);
200-
const hex = try c1.toHexString(&buf);
200+
const hex = try c1.toCssHex(&buf);
201201
try testing.expectEqualStrings(td[1], hex);
202202

203203
for (skip_list) |nc|

0 commit comments

Comments
 (0)