fmt: fix alignment of struct init fields (#22025)

This commit is contained in:
yuyi 2024-08-11 14:11:24 +08:00 committed by GitHub
parent 99da5726db
commit c51d30bf53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
671 changed files with 18817 additions and 18787 deletions

View file

@ -119,9 +119,9 @@ pub fn new_encoding_with_padding(alphabet []u8, padding_char u8) Encoding {
}
return Encoding{
alphabet: alphabet
alphabet: alphabet
padding_char: padding_char
decode_map: decode_map
decode_map: decode_map
}
}

View file

@ -259,7 +259,7 @@ import encoding.csv
fn main() {
file_path := 'big2.csv'
mut csvr := csv.csv_reader(
file_path: file_path // path to the file CSV
file_path: file_path // path to the file CSV
mem_buf_size: 1024 * 1024 * 64 // we set 64MByte of buffer for this file
end_line_len: csv.endline_crlf_len // we are using a windows text file
)!
@ -295,9 +295,9 @@ a,b,c
fn main() {
mut csvr := csv.csv_reader(
scr_buf: txt.str
scr_buf: txt.str
scr_buf_len: txt.len
comment: `#` // line starting with # will be ignored
comment: `#` // line starting with # will be ignored
)!
// scan all rows, csvr.csv_map.len contain the valid
// rows number in the CSV file.
@ -328,10 +328,10 @@ const txt = "
fn main() {
mut csvr := csv.csv_reader(
scr_buf: txt.str // string pointer
scr_buf_len: txt.len // string length
comment: `#` // line starting with # will be ignored
quote: `'` // char used for quotes
scr_buf: txt.str // string pointer
scr_buf_len: txt.len // string length
comment: `#` // line starting with # will be ignored
quote: `'` // char used for quotes
quote_remove: true // remove quotes from the cells
)!
@ -351,4 +351,4 @@ Output:
['4', '5', 'a,b,c', 'e']
```
## Performance
This module was tested with CSV files up to 4 GBs with 4 million rows
This module was tested with CSV files up to 4 GBs with 4 million rows

View file

@ -460,9 +460,9 @@ pub fn (mut cr RandomAccessReader) build_header_dict(cfg GetHeaderConf) ! {
// fill the base struct
label := cr.get_cell(x: col, y: cfg.header_row)!
mut h := HeaderItem{
label: label
label: label
column: col
htype: .string
htype: .string
}
// try to infer the type if we haev at least one more row

View file

@ -38,39 +38,39 @@ a,"b,c,d",0,#,3,"pippo"
const target_header_list = [
csv.HeaderItem{
label: 'a'
label: 'a'
column: 0
htype: .int
htype: .int
},
csv.HeaderItem{
label: 'b'
label: 'b'
column: 1
htype: .string
htype: .string
},
csv.HeaderItem{
label: 'c'
label: 'c'
column: 2
htype: .f32
htype: .f32
},
csv.HeaderItem{
label: 'd'
label: 'd'
column: 3
htype: .f32
htype: .f32
},
csv.HeaderItem{
label: 'e'
label: 'e'
column: 4
htype: .int
htype: .int
},
csv.HeaderItem{
label: 'f'
label: 'f'
column: 5
htype: .string
htype: .string
},
csv.HeaderItem{
label: 'g'
label: 'g'
column: 6
htype: .int
htype: .int
},
]
@ -146,7 +146,7 @@ fn test_csv_sequential() {
f.close()
csvr = csv.csv_sequential_reader(
file_path: file_path_str
file_path: file_path_str
mem_buf_size: 64
end_line_len: csv.endline_crlf_len
)!
@ -267,7 +267,7 @@ fn test_csv_string() {
// parse the temp file
csvr = csv.csv_reader(
file_path: file_path_str
file_path: file_path_str
mem_buf_size: 32
end_line_len: csv.endline_crlf_len
)!
@ -283,8 +283,8 @@ fn test_csv_string() {
// test crlf endline
csvr = csv.csv_reader(
scr_buf: txt3.str
scr_buf_len: txt3.len
scr_buf: txt3.str
scr_buf_len: txt3.len
end_line_len: csv.endline_crlf_len
)!
perform_test3(mut csvr)!
@ -321,7 +321,7 @@ fn test_coherence() {
// parse the temp file
mut csvr := csv.csv_reader(
file_path: file_path_str
file_path: file_path_str
mem_buf_size: 32
end_line_len: csv.endline_cr_len
)!

View file

@ -61,9 +61,9 @@ pub:
// optionally, a custom delimiter.
pub fn new_reader(data string, config ReaderConfig) &Reader {
return &Reader{
data: data
data: data
delimiter: config.delimiter
comment: config.comment
comment: config.comment
}
}

View file

@ -22,8 +22,8 @@ pub:
// new_writer returns a reference to a Writer
pub fn new_writer(config WriterConfig) &Writer {
return &Writer{
sb: strings.new_builder(200)
use_crlf: config.use_crlf
sb: strings.new_builder(200)
use_crlf: config.use_crlf
delimiter: config.delimiter
}
}

View file

@ -1150,7 +1150,7 @@ const white_space_table = RangeTable{
Range16{0x202f, 0x205f, 48},
Range16{0x3000, 0x3000, 1},
]
r32: []
r32: []
latin_offset: 2
}

View file

@ -5,14 +5,14 @@ import encoding.xml
fn test_node() {
nodes := [
xml.XMLNode{
name: 'test'
name: 'test'
attributes: {
'test:key': ' test_value '
'test:other': '123456'
}
children: [
xml.XMLNode{
name: 'child'
name: 'child'
attributes: {
'child:key': 'child_value'
}
@ -21,14 +21,14 @@ fn test_node() {
]
},
xml.XMLNode{
name: 's'
name: 's'
attributes: {
'k': 'v'
}
children: [
'Hello, world!',
xml.XMLNode{
name: 'c'
name: 'c'
attributes: {
'k2': 'v2'
}
@ -36,53 +36,53 @@ fn test_node() {
]
},
xml.XMLNode{
name: 'ext'
name: 'ext'
attributes: {
'uri': '{B58B0392-4F1F-4190-BB64-5DF3571DCE5F}'
'xmlns:xcalcf': 'http://schemas.microsoft.com/office/spreadsheetml/2018/calcfeatures'
}
children: [
xml.XMLNode{
name: 'xcalcf:calcFeatures'
name: 'xcalcf:calcFeatures'
children: [
xml.XMLNode{
name: 'xcalcf:feature'
name: 'xcalcf:feature'
attributes: {
'name': 'microsoft.com:RD'
}
},
xml.XMLNode{
name: 'xcalcf:feature'
name: 'xcalcf:feature'
attributes: {
'name': 'microsoft.com:Single'
}
},
xml.XMLNode{
name: 'xcalcf:feature'
name: 'xcalcf:feature'
attributes: {
'name': 'microsoft.com:FV'
}
},
xml.XMLNode{
name: 'xcalcf:feature'
name: 'xcalcf:feature'
attributes: {
'name': 'microsoft.com:CNMTM'
}
},
xml.XMLNode{
name: 'xcalcf:feature'
name: 'xcalcf:feature'
attributes: {
'name': 'microsoft.com:LET_WF'
}
},
xml.XMLNode{
name: 'xcalcf:feature'
name: 'xcalcf:feature'
attributes: {
'name': 'microsoft.com:LAMBDA_WF'
}
},
xml.XMLNode{
name: 'xcalcf:feature'
name: 'xcalcf:feature'
attributes: {
'name': 'microsoft.com:ARRAYTEXT_WF'
}
@ -125,14 +125,14 @@ fn test_doc() {
docs := [
xml.XMLDocument{
root: xml.XMLNode{
name: 'test'
name: 'test'
attributes: {
'test:key': ' test_value '
'test:other': '123456'
}
children: [
xml.XMLNode{
name: 'child'
name: 'child'
attributes: {
'child:key': 'child_value'
}
@ -143,14 +143,14 @@ fn test_doc() {
},
xml.XMLDocument{
root: xml.XMLNode{
name: 's'
name: 's'
attributes: {
'k': 'v'
}
children: [
'Hello, world!',
xml.XMLNode{
name: 'c'
name: 'c'
attributes: {
'k2': 'v2'
}

View file

@ -290,7 +290,7 @@ fn parse_doctype(mut reader io.Reader) !DocumentType {
return DocumentType{
name: name
dtd: DocumentTypeDefinition{
dtd: DocumentTypeDefinition{
list: items
}
}
@ -391,7 +391,7 @@ fn parse_prolog(mut reader io.Reader) !(Prolog, u8) {
mut comments := []XMLComment{}
mut doctype := DocumentType{
name: ''
dtd: ''
dtd: ''
}
mut found_doctype := false
for {
@ -445,9 +445,9 @@ fn parse_prolog(mut reader io.Reader) !(Prolog, u8) {
}
return Prolog{
version: version
version: version
encoding: encoding
doctype: doctype
doctype: doctype
comments: comments
}, ch
}
@ -509,9 +509,9 @@ fn parse_children(name string, attributes map[string]string, mut reader io.Reade
children << collected_contents.replace('\r\n', '\n')
}
return XMLNode{
name: name
name: name
attributes: attributes
children: children
children: children
}
}
else {
@ -566,7 +566,7 @@ pub fn parse_single_node(first_char u8, mut reader io.Reader) !XMLNode {
if tag_contents.ends_with('/') {
// We're not looking for children and inner text
return XMLNode{
name: name
name: name
attributes: parse_attributes(tag_contents[name.len..tag_contents.len - 1].trim_space())!
}
}
@ -608,10 +608,10 @@ pub fn XMLDocument.from_reader(mut reader io.Reader) !XMLDocument {
root := parse_single_node(first_char, mut reader)!
return XMLDocument{
version: prolog.version
version: prolog.version
encoding: prolog.encoding
comments: prolog.comments
doctype: prolog.doctype
root: root
doctype: prolog.doctype
root: root
}
}

View file

@ -21,13 +21,13 @@ const sample_doc = '
const xml_elements = [
XMLNode{
name: 'c'
name: 'c'
attributes: {
'id': 'c1'
}
},
XMLNode{
name: 'c'
name: 'c'
attributes: {
'id': 'c2'
}
@ -36,47 +36,47 @@ const xml_elements = [
]
},
XMLNode{
name: 'empty'
name: 'empty'
attributes: {}
},
XMLNode{
name: 'c'
name: 'c'
attributes: {
'id': 'c3'
}
},
XMLNode{
name: 'abc'
name: 'abc'
attributes: {
'id': 'c4'
}
},
XMLNode{
name: 'xyz'
name: 'xyz'
attributes: {
'id': 'c5'
}
},
XMLNode{
name: 'c'
name: 'c'
attributes: {
'id': 'c6'
}
},
XMLNode{
name: 'cx'
name: 'cx'
attributes: {
'id': 'c7'
}
},
XMLNode{
name: 'cd'
name: 'cd'
attributes: {
'id': 'c8'
}
},
XMLNode{
name: 'child'
name: 'child'
attributes: {
'id': 'c9'
}
@ -85,7 +85,7 @@ const xml_elements = [
]
},
XMLNode{
name: 'cz'
name: 'cz'
attributes: {
'id': 'c10'
}

View file

@ -31,14 +31,14 @@ fn test_large_gtk_file() ! {
for elm in actual.get_elements_by_tag('constructor') {
if 'c:identifier' in elm.attributes && elm.attributes['c:identifier'] == 'gtk_window_new' {
assert elm == xml.XMLNode{
name: 'constructor'
name: 'constructor'
attributes: {
'name': 'new'
'c:identifier': 'gtk_window_new'
}
children: [
xml.XMLNodeContents(xml.XMLNode{
name: 'doc'
name: 'doc'
attributes: {
'xml:space': 'preserve'
}
@ -58,20 +58,20 @@ To delete a `GtkWindow`, call [method@Gtk.Window.destroy].'),
]
}),
xml.XMLNodeContents(xml.XMLNode{
name: 'return-value'
name: 'return-value'
attributes: {
'transfer-ownership': 'none'
}
children: [
xml.XMLNodeContents(xml.XMLNode{
name: 'doc'
name: 'doc'
attributes: {
'xml:space': 'preserve'
}
children: [xml.XMLNodeContents('a new `GtkWindow`.')]
}),
xml.XMLNodeContents(xml.XMLNode{
name: 'type'
name: 'type'
attributes: {
'name': 'Widget'
'c:type': 'GtkWidget*'

View file

@ -6,10 +6,10 @@ fn test_valid_parsing() ! {
expected := xml.XMLDocument{
root: xml.XMLNode{
name: 'message'
name: 'message'
children: [
xml.XMLNode{
name: 'greeting'
name: 'greeting'
children: [
'Hello, World!',
]

View file

@ -6,28 +6,28 @@ fn test_valid_parsing() ! {
expected := xml.XMLDocument{
root: xml.XMLNode{
name: 'note'
name: 'note'
children: [
xml.XMLNode{
name: 'to'
name: 'to'
children: [
'Tove',
]
},
xml.XMLNode{
name: 'from'
name: 'from'
children: [
'Jani',
]
},
xml.XMLNode{
name: 'heading'
name: 'heading'
children: [
'Reminder',
]
},
xml.XMLNode{
name: 'body'
name: 'body'
children: [
"Don't forget me this weekend!",
]

View file

@ -6,43 +6,43 @@ fn test_valid_parsing() ! {
expected := xml.XMLDocument{
root: xml.XMLNode{
name: 'CATALOG'
name: 'CATALOG'
children: [
xml.XMLNode{
name: 'CD'
name: 'CD'
children: [
xml.XMLNode{
name: 'TITLE'
name: 'TITLE'
children: [
'Empire Burlesque',
]
},
xml.XMLNode{
name: 'ARTIST'
name: 'ARTIST'
children: [
'Bob Dylan',
]
},
xml.XMLNode{
name: 'COUNTRY'
name: 'COUNTRY'
children: [
'USA',
]
},
xml.XMLNode{
name: 'COMPANY'
name: 'COMPANY'
children: [
'Columbia',
]
},
xml.XMLNode{
name: 'PRICE'
name: 'PRICE'
children: [
'10.90',
]
},
xml.XMLNode{
name: 'YEAR'
name: 'YEAR'
children: [
'1985',
]
@ -50,40 +50,40 @@ fn test_valid_parsing() ! {
]
},
xml.XMLNode{
name: 'CD'
name: 'CD'
children: [
xml.XMLNode{
name: 'TITLE'
name: 'TITLE'
children: [
'Hide your heart',
]
},
xml.XMLNode{
name: 'ARTIST'
name: 'ARTIST'
children: [
'Bonnie Tyler',
]
},
xml.XMLNode{
name: 'COUNTRY'
name: 'COUNTRY'
children: [
'UK',
]
},
xml.XMLNode{
name: 'COMPANY'
name: 'COMPANY'
children: [
'CBS Records',
]
},
xml.XMLNode{
name: 'PRICE'
name: 'PRICE'
children: [
'9.90',
]
},
xml.XMLNode{
name: 'YEAR'
name: 'YEAR'
children: [
'1988',
]
@ -91,40 +91,40 @@ fn test_valid_parsing() ! {
]
},
xml.XMLNode{
name: 'CD'
name: 'CD'
children: [
xml.XMLNode{
name: 'TITLE'
name: 'TITLE'
children: [
'Greatest Hits',
]
},
xml.XMLNode{
name: 'ARTIST'
name: 'ARTIST'
children: [
'Dolly Parton',
]
},
xml.XMLNode{
name: 'COUNTRY'
name: 'COUNTRY'
children: [
'USA',
]
},
xml.XMLNode{
name: 'COMPANY'
name: 'COMPANY'
children: [
'RCA',
]
},
xml.XMLNode{
name: 'PRICE'
name: 'PRICE'
children: [
'9.90',
]
},
xml.XMLNode{
name: 'YEAR'
name: 'YEAR'
children: [
'1982',
]
@ -132,40 +132,40 @@ fn test_valid_parsing() ! {
]
},
xml.XMLNode{
name: 'CD'
name: 'CD'
children: [
xml.XMLNode{
name: 'TITLE'
name: 'TITLE'
children: [
'Still got the blues',
]
},
xml.XMLNode{
name: 'ARTIST'
name: 'ARTIST'
children: [
'Gary Moore',
]
},
xml.XMLNode{
name: 'COUNTRY'
name: 'COUNTRY'
children: [
'UK',
]
},
xml.XMLNode{
name: 'COMPANY'
name: 'COMPANY'
children: [
'Virgin records',
]
},
xml.XMLNode{
name: 'PRICE'
name: 'PRICE'
children: [
'10.20',
]
},
xml.XMLNode{
name: 'YEAR'
name: 'YEAR'
children: [
'1990',
]

View file

@ -6,7 +6,7 @@ fn test_valid_parsing() ! {
expected := xml.XMLDocument{
root: xml.XMLNode{
name: 'sample'
name: 'sample'
children: [
'Single root element.',
]

View file

@ -6,16 +6,16 @@ fn test_valid_parsing() ! {
expected := xml.XMLDocument{
root: xml.XMLNode{
name: 'level1'
name: 'level1'
children: [
xml.XMLNode{
name: 'level2'
name: 'level2'
children: [
xml.XMLNode{
name: 'level3'
name: 'level3'
children: [
xml.XMLNode{
name: 'level4'
name: 'level4'
children: [
'Deeply nested content.',
]
@ -25,10 +25,10 @@ fn test_valid_parsing() ! {
]
},
xml.XMLNode{
name: 'level2'
name: 'level2'
children: [
xml.XMLNode{
name: 'level3'
name: 'level3'
children: [
'Less deeply nested content.',
]

View file

@ -6,21 +6,21 @@ fn test_valid_parsing() ! {
expected := xml.XMLDocument{
root: xml.XMLNode{
name: 'letter'
name: 'letter'
children: [
'Dear Mr.',
xml.XMLNode{
name: 'name'
name: 'name'
children: ['John Smith']
},
'.\n Your order',
xml.XMLNode{
name: 'orderid'
name: 'orderid'
children: ['1032']
},
'will be shipped on',
xml.XMLNode{
name: 'shipdate'
name: 'shipdate'
children: ['2001-07-13']
},
'.',

View file

@ -11,24 +11,24 @@ fn test_valid_parsing() ! {
},
]
root: xml.XMLNode{
name: 'address'
name: 'address'
children: [
xml.XMLComment{
text: ' Full or first name '
},
xml.XMLNode{
name: 'name'
name: 'name'
children: ['Jones']
},
xml.XMLComment{
text: ' Registered name of the company -> '
},
xml.XMLNode{
name: 'company'
name: 'company'
children: ['ABSystems']
},
xml.XMLNode{
name: 'phone'
name: 'phone'
children: [xml.XMLComment{
text: ' Phone with country code -) '
}, '(046) 1233-44778']

View file

@ -8,14 +8,14 @@ fn test_valid_parsing() {
expected := xml.XMLDocument{
root: xml.XMLNode{
name: 'sample'
name: 'sample'
children: [
xml.XMLNode{
name: 'html'
name: 'html'
children: ['This is &lt;b&gt;bold&lt;/b&gt;']
},
xml.XMLNode{
name: 'html'
name: 'html'
children: [xml.XMLCData{
text: 'This is <b>bold</b>'
}]

View file

@ -9,55 +9,55 @@ fn test_valid_parsing() {
expected := xml.XMLDocument{
doctype: xml.DocumentType{
name: 'note'
dtd: xml.DocumentTypeDefinition{
dtd: xml.DocumentTypeDefinition{
name: ''
list: [
xml.DTDElement{
name: 'note'
name: 'note'
definition: ['to', 'from', 'heading', 'body']
},
xml.DTDElement{
name: 'to'
name: 'to'
definition: ['#PCDATA']
},
xml.DTDElement{
name: 'from'
name: 'from'
definition: ['#PCDATA']
},
xml.DTDElement{
name: 'heading'
name: 'heading'
definition: ['#PCDATA']
},
xml.DTDElement{
name: 'body'
name: 'body'
definition: ['#PCDATA']
},
]
}
}
root: xml.XMLNode{
name: 'note'
name: 'note'
children: [
xml.XMLNode{
name: 'to'
name: 'to'
children: [
'Tove',
]
},
xml.XMLNode{
name: 'from'
name: 'from'
children: [
'Jani',
]
},
xml.XMLNode{
name: 'heading'
name: 'heading'
children: [
'Reminder',
]
},
xml.XMLNode{
name: 'body'
name: 'body'
children: [
"Don't forget me this weekend!",
]

View file

@ -8,13 +8,13 @@ fn test_valid_parsing() {
expected := xml.XMLDocument{
root: xml.XMLNode{
name: 'book'
name: 'book'
attributes: {
'category': 'web'
}
children: [
xml.XMLNode{
name: 'title'
name: 'title'
attributes: {
'lang': 'en'
'code:type': 'const char*'
@ -22,18 +22,18 @@ fn test_valid_parsing() {
children: ['Learning XML']
},
xml.XMLNode{
name: 'author'
name: 'author'
attributes: {
'attr': ' surrounding spaces '
}
children: ['Erik T. Ray']
},
xml.XMLNode{
name: 'year'
name: 'year'
children: ['2003']
},
xml.XMLNode{
name: 'price'
name: 'price'
children: ['39.95']
},
]

View file

@ -8,17 +8,17 @@ fn test_valid_parsing() {
expected := xml.XMLDocument{
root: xml.XMLNode{
name: 'sst'
name: 'sst'
attributes: {
'count': '5'
'uniqueCount': '5'
}
children: [
xml.XMLNode{
name: 'si'
name: 'si'
children: [
xml.XMLNode{
name: 't'
name: 't'
attributes: {
'a': '1'
}
@ -27,37 +27,37 @@ fn test_valid_parsing() {
]
},
xml.XMLNode{
name: 'si'
name: 'si'
children: [
xml.XMLNode{
name: 't'
name: 't'
children: ['Item 2']
},
]
},
xml.XMLNode{
name: 'si'
name: 'si'
children: [
xml.XMLNode{
name: 't'
name: 't'
children: ['Item 3']
},
]
},
xml.XMLNode{
name: 'si'
name: 'si'
children: [
xml.XMLNode{
name: 't'
name: 't'
children: ['Item 4']
},
]
},
xml.XMLNode{
name: 'si'
name: 'si'
children: [
xml.XMLNode{
name: 't'
name: 't'
children: ['Item 5']
},
]

View file

@ -69,7 +69,7 @@ pub:
encoding string = 'UTF-8'
doctype DocumentType = DocumentType{
name: ''
dtd: ''
dtd: ''
}
comments []XMLComment
}

View file

@ -33,9 +33,9 @@ fn (node XMLNode) validate(elements map[string]DTDElement, entities map[string]s
}
return XMLNode{
name: node.name
name: node.name
attributes: node.attributes
children: children
children: children
}
}
@ -80,11 +80,11 @@ pub fn (doc XMLDocument) validate() !XMLDocument {
}
return XMLDocument{
version: doc.version
encoding: doc.encoding
doctype: doc.doctype
comments: doc.comments
root: new_root
version: doc.version
encoding: doc.encoding
doctype: doc.doctype
comments: doc.comments
root: new_root
parsed_reverse_entities: reverse_entities
}
}