FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
zig-postgres/src/parser.zig at main · rofrol/zig-postgres · GitHub
rofrol
/
zig-postgres
Public
forked from
jane0009/zig-postgres
Notifications
You must be signed in to change notification settings
Fork
2
Star
20
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
zig-postgres
/
src
/
parser.zig
Copy path
More file actions
More file actions
Latest commit
History
History
History
85 lines (71 loc) · 2.34 KB
Breadcrumbs
zig-postgres
/
src
/
parser.zig
Copy path
File metadata and controls
85 lines (71 loc) · 2.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
84
85
const
std
=
@import
(
"std"
);
const
print
=
std
.
debug
.
print
;
const
Allocator
=
std
.
mem
.
Allocator
;
const
meta
=
std
.
meta
;
const
Utf8View
=
std
.
unicode
.
Utf8View
;
const
Self
=
@This
();
// allocator: *Allocator = allocator,
pub
fn
init
(
allocator
:
Allocator
)
Self
{
_
=
allocator
;
return
Self
{
// .allocator = allocator,
};
}
pub
fn
parseJson
(
self
:
*
const
Self
,
comptime
T
:
type
,
value
: []
const
u8
,
allocator
:
Allocator
)
!
T
{
_
=
self
;
var
stream
=
std
.
json
.
TokenStream
.
init
(
value
);
return
try
std
.
json
.
parse
(
T
,
&
stream
, .{ .
allocator
=
allocator
});
}
pub
fn
parseArray
(
self
:
*
const
Self
,
value
: []
const
u8
,
break_point
: []
const
u8
,
allocator
:
Allocator
)
!
[][]
const
u8
{
_
=
self
;
var
buffer
=
std
.
ArrayList
([]
const
u8
).
init
(
allocator
);
var
stop_point
:
usize
=
try
std
.
math
.
divCeil
(
usize
,
break_point
.
len
,
2
);
for
(
value
)
|
_
,
index
|
{
const
one_step
=
index
+
break_point
.
len
;
if
(
one_step
==
value
.
len
and
stop_point
<
index
) {
try
buffer
.
append
(
value
[
stop_point
..
index
]);
}
if
(
one_step
==
value
.
len
)
break
;
if
(
std
.
mem
.
eql
(
u8
,
value
[
index
..
one_step
],
break_point
)) {
try
buffer
.
append
(
value
[
stop_point
..
index
]);
stop_point
=
one_step
;
}
}
return
buffer
.
toOwnedSlice
();
}
// const testing = std.testing;
// test "Parser" {
// var gpa = std.heap.GeneralPurposeAllocator(.{}){};
// const allocator = &gpa.allocator;
// const test_string =
// \\{Ace,2,Queen}
// ;
// const test_string2 =
// \\{"Test string ?","I am long text!","Finishing words." }
// ;
// const parser = Self.init(allocator);
// var parsed1 = try parser.parseArray(test_string, ",");
// var parsed2 = try parser.parseArray(test_string2, "\x22,\x22");
// var results1 = [3][]const u8{
// "Ace",
// "2",
// "Queen",
// };
// var results2 = [3][]const u8{
// "Test string ?",
// "I am long text!",
// "Finishing words.",
// };
// // Todo finish test
// for (parsed1) |value, index| {
// print("{s} \n", .{value});
// }
// for (parsed2) |value, index| {
// print("{s} \n", .{value});
// }
// defer {
// allocator.free(parsed1);
// allocator.free(parsed2);
// std.debug.assert(!gpa.deinit());
// }
// }
Back
|
FazBrowse Home
|
New Git URL