-
Notifications
You must be signed in to change notification settings - Fork 19
/
util.v
84 lines (80 loc) · 1.38 KB
/
util.v
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
// Copyright (c) 2024 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license that can be found in the LICENSE file.
fn go2v_type(typ string) string {
match typ {
'byte' {
return 'u8'
}
'char' {
return 'u8'
}
'float32' {
return 'f32'
}
'float64' {
return 'f64'
}
'int' {
return 'isize'
}
'int8' {
return 'i8'
}
'int16' {
return 'i16'
}
'int32' {
return 'i32'
}
'int64' {
return 'i64'
}
'uint' {
return 'usize'
}
'uint8' {
return 'u8'
}
'uint16' {
return 'u16'
}
'uint32' {
return 'u32'
}
'uint64' {
return 'u64'
}
else {}
}
return typ
}
fn (mut app App) go2v_ident(ident string) string {
// println('ident=${ident} force_upper=${app.force_upper}')
if app.force_upper {
app.force_upper = false
if ident in v_keywords_which_are_not_go_keywords {
return ident + '_'
}
if ident in ['string', 'int', 'float64'] {
return ident
}
return ident.capitalize()
}
return go2v_ident2(ident)
/*
return if ident[0].is_capital() {
// println('is cap')
ident
} else {
go2v_ident2(ident)
}
*/
}
const v_keywords_which_are_not_go_keywords = ['match', 'lock', 'fn', 'enum']
fn go2v_ident2(ident string) string {
x := ident.camel_to_snake() // to_lower()) // TODO ?
if x in v_keywords_which_are_not_go_keywords {
return x + '_'
}
return x
}