This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathde.go
88 lines (76 loc) · 3.07 KB
/
de.go
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
86
87
88
/*
The MIT License (MIT)
Copyright (c) 2014 Chris Grieger
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package countries
import (
"strconv"
s "strings"
)
/*
Describes the field width of the fixed width text file
which can be found at
http://www.bundesbank.de/Redaktion/DE/Standardartikel/Kerngeschaeftsfelder/Unbarer_Zahlungsverkehr/bankleitzahlen_download.html?searchArchive=0&submit=Suchen&searchIssued=0&templateQueryString=Bankleitzahlen
Example:
bankcodemname###### zip##city short##### pan##bic########z##id###cdnext####
100000001Bundesbank 10591Berlin BBk Berlin 20100MARKDEF110009011380U000000000
*/
type BundesbankFileEntry struct {
Bankcode string // 8
M int // 1
Name string // 58
Zip string // 5
City string // 35
ShortName string // 27
Pan int // 5
Bic string // 11
CheckAlgo string // 2 enumerates some checksum algorithms
// described in https://www.bundesbank.de/Redaktion/DE/Downloads/Aufgaben/Unbarer_Zahlungsverkehr/pruefzifferberechnungsmethoden.pdf?__blob=publicationFile
Id string // 5 internal id
Change string // 1
ToBeDeleted int // 1
NewBankCode string // 8
}
func BundesbankStringToEntry(val string) *BundesbankFileEntry {
runeVal := []rune(val)
m, _ := strconv.Atoi(string(runeVal[8:9]))
pan, _ := strconv.Atoi(string(runeVal[134:139]))
id := string(runeVal[152:157])
toBeDeleted, _ := strconv.Atoi(string(runeVal[159:160]))
return &BundesbankFileEntry{
toTrimmedString(runeVal[0:8]),
m,
toTrimmedString(runeVal[9:67]),
toTrimmedString(runeVal[67:72]),
toTrimmedString(runeVal[72:107]),
toTrimmedString(runeVal[107:134]),
pan,
toTrimmedString(runeVal[139:150]),
toTrimmedString(runeVal[150:152]),
id,
toTrimmedString(runeVal[158:159]),
toBeDeleted,
toTrimmedString(runeVal[160:168]),
}
}
/*
Converts an array of runes to a trimmed string
*/
func toTrimmedString(runes []rune) string {
return s.TrimSpace(string(runes))
}