summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar thisLight2021-10-19 13:28:32 +0800
committerGravatar Vincent Rischmann2021-10-19 08:40:36 +0200
commit4eac00ced666f43cca63309a2c8493bd1052e036 (patch)
tree2c87b815b943e863add6d0a705c94c43bf8e9f1a
parentBindMarker: idType to id_type (diff)
downloadzig-sqlite-4eac00ced666f43cca63309a2c8493bd1052e036.tar.gz
zig-sqlite-4eac00ced666f43cca63309a2c8493bd1052e036.tar.xz
zig-sqlite-4eac00ced666f43cca63309a2c8493bd1052e036.zip
query.zig: code format
Diffstat (limited to '')
-rw-r--r--query.zig44
1 files changed, 19 insertions, 25 deletions
diff --git a/query.zig b/query.zig
index 1ca6c59..33b2b1f 100644
--- a/query.zig
+++ b/query.zig
@@ -64,7 +64,7 @@ pub const ParsedQuery = struct {
64 state = .BindMarkerType; 64 state = .BindMarkerType;
65 }, 65 },
66 else => { 66 else => {
67 if (std.ascii.isAlpha(c) or std.ascii.isDigit(c)){ 67 if (std.ascii.isAlpha(c) or std.ascii.isDigit(c)) {
68 state = .BindMarkerIdentifier; 68 state = .BindMarkerIdentifier;
69 current_bind_marker_id[current_bind_marker_id_pos] = c; 69 current_bind_marker_id[current_bind_marker_id_pos] = c;
70 current_bind_marker_id_pos += 1; 70 current_bind_marker_id_pos += 1;
@@ -86,12 +86,12 @@ pub const ParsedQuery = struct {
86 current_bind_marker_type_pos = 0; 86 current_bind_marker_type_pos = 0;
87 87
88 // A bind marker with id and type: ?AAA{[]const u8}, we don't need move the pointer. 88 // A bind marker with id and type: ?AAA{[]const u8}, we don't need move the pointer.
89 if (current_bind_marker_id_pos > 0){ 89 if (current_bind_marker_id_pos > 0) {
90 parsed_query.bind_markers[parsed_query.nb_bind_markers].identifier = std.fmt.comptimePrint("{s}", .{current_bind_marker_id[0..current_bind_marker_id_pos]}); 90 parsed_query.bind_markers[parsed_query.nb_bind_markers].identifier = std.fmt.comptimePrint("{s}", .{current_bind_marker_id[0..current_bind_marker_id_pos]});
91 } 91 }
92 }, 92 },
93 else => { 93 else => {
94 if (std.ascii.isAlpha(c) or std.ascii.isDigit(c)){ 94 if (std.ascii.isAlpha(c) or std.ascii.isDigit(c)) {
95 current_bind_marker_id[current_bind_marker_id_pos] = c; 95 current_bind_marker_id[current_bind_marker_id_pos] = c;
96 current_bind_marker_id_pos += 1; 96 current_bind_marker_id_pos += 1;
97 } else { 97 } else {
@@ -313,28 +313,22 @@ test "parsed query: bind markers identifier type" {
313 expected_marker: BindMarker, 313 expected_marker: BindMarker,
314 }; 314 };
315 315
316 const testCases = &[_]testCase{ 316 const testCases = &[_]testCase{ .{
317 .{ 317 .query = "foobar @ABC{usize}",
318 .query = "foobar @ABC{usize}", 318 .expected_marker = .{ .id_type = .String },
319 .expected_marker = .{ .id_type = .String }, 319 }, .{
320 }, 320 .query = "foobar ?123{text}",
321 .{ 321 .expected_marker = .{ .id_type = .Integer },
322 .query = "foobar ?123{text}", 322 }, .{
323 .expected_marker = .{ .id_type = .Integer }, 323 .query = "foobar $abc{blob}",
324 }, 324 .expected_marker = .{ .id_type = .String },
325 .{ 325 }, .{
326 .query = "foobar $abc{blob}", 326 .query = "foobar ?123",
327 .expected_marker = .{ .id_type = .String }, 327 .expected_marker = .{ .id_type = .Integer },
328 }, 328 }, .{
329 .{ 329 .query = "foobar :abc",
330 .query = "foobar ?123", 330 .expected_marker = .{ .id_type = .String },
331 .expected_marker = .{ .id_type = .Integer }, 331 } };
332 },
333 .{
334 .query = "foobar :abc",
335 .expected_marker = .{ .id_type = .String },
336 }
337 };
338 332
339 inline for (testCases) |tc| { 333 inline for (testCases) |tc| {
340 comptime var parsed_query = ParsedQuery.from(tc.query); 334 comptime var parsed_query = ParsedQuery.from(tc.query);