-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheprefneutron.go
217 lines (181 loc) · 5.46 KB
/
eprefneutron.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package errpref
import (
"fmt"
"strings"
"sync"
)
type errPrefNeutron struct {
lock *sync.Mutex
}
// createNewEPrefInfo - Creates a single ErrorPrefixInfo object
// from an error prefix and an error context string. This method is
// only designed to operate on a single pair of pair of strings
// containing one error prefix and one error context.
//
// The error context string is optional and empty error strings
// will still result in the generation and return of a valid
// ErrorPrefixInfo object.
//
// If the input parameter, 'newErrPrefix' is an empty string, this
// method will generate an error.
//
//
// ----------------------------------------------------------------
//
// Input Parameters
//
// newErrPrefix string
// - This is the new error prefix string which will be
// configured in the ErrorPrefixInfo object returned by this
// method.
//
//
// newErrContext string
// - An optional error context description. This is the error
// context information associated with the new error prefix
// ('newErrPrefix'). Typically context descriptions might
// include variable names or input values. The text
// description is expected to help identify and explain any
// errors triggered in the immediate vicinity of the function
// documented by error prefix 'newErrPrefix'.
//
//
// ePrefixStr string
// - This is an error prefix which is included in all returned
// error messages. Usually, it contains the names of the calling
// method or methods. Note: Be sure to leave a space at the end
// of 'ePrefix'.
//
//
// -----------------------------------------------------------------
//
// Return Values
//
// errPrefixInfo ErrorPrefixInfo
// - This returned ErrorPrefixInfo will encapsulate the error
// prefix and error context strings passed through input
// parameters 'newErrPrefix' and 'newErrContext'.
//
//
// err error
// - If this method encounters a processing error during
// execution, a detailed error message will be
// returned identifying the invalid data item.
//
// If the current instance is valid, this error parameter
// will be set to nil.
//
func (ePrefNeutron *errPrefNeutron) createNewEPrefInfo(
newErrPrefix string,
newErrContext string,
ePrefixStr string) (
errPrefixInfo ErrorPrefixInfo,
err error) {
if ePrefNeutron.lock == nil {
ePrefNeutron.lock = new(sync.Mutex)
}
ePrefNeutron.lock.Lock()
defer ePrefNeutron.lock.Unlock()
ePrefixStr += "errPrefNeutron.createNewEPrefInfo()"
errPrefixInfo = ErrorPrefixInfo{}
var (
lenPrefixStr,
lenContextStr int
)
ePrefElectron := errPrefElectron{}
newErrPrefix,
lenPrefixStr = ePrefElectron.cleanErrorPrefixStr(newErrPrefix)
if lenPrefixStr == 0 {
err = fmt.Errorf("%v\n"+
"Error: Cleaned Error Prefix String is EMPTY!\n",
ePrefixStr)
return errPrefixInfo, err
}
newErrContext,
lenContextStr = ePrefElectron.cleanErrorContextStr(newErrContext)
errPrefixInfo.SetIsFirstIndex(false)
errPrefixInfo.SetIsLastIndex(false)
errPrefixInfo.SetErrPrefixStr(newErrPrefix)
if lenContextStr > 0 {
errPrefixInfo.SetErrPrefixHasContext(true)
errPrefixInfo.SetErrContextStr(newErrContext)
} else {
errPrefixInfo.SetErrPrefixHasContext(false)
}
return errPrefixInfo, err
}
// ptr() - Returns a pointer to a new instance of
// errPrefNeutron.
//
func (ePrefNeutron errPrefNeutron) ptr() *errPrefNeutron {
if ePrefNeutron.lock == nil {
ePrefNeutron.lock = new(sync.Mutex)
}
ePrefNeutron.lock.Lock()
defer ePrefNeutron.lock.Unlock()
return &errPrefNeutron{}
}
// writeCurrentLineStr - Writes the contents of a current
// line of error prefix and error context characters to
// a sting builder for text display output.
//
//
// ----------------------------------------------------------------
//
// Input Parameters
//
// strBuilder *strings.Builder
// - A pointer to a string builder. The contents of the current
// line of text will be written to this string builder.
//
//
// ePrefLineLenCalc *EPrefixLineLenCalc
// - A pointer to an instance of EPrefixLineLenCalc, the Error
// Prefix Line Length Calculator. This types encapsulates all
// the data necessary to perform line length calculations and
// format the error prefix and error context strings for
// text display output.
//
// type EPrefixLineLenCalc struct {
// ePrefDelimiters ErrPrefixDelimiters
// errorPrefixInfo *ErrorPrefixInfo
// currentLineStr string
// maxErrStringLength uint
// }
//
//
// -----------------------------------------------------------------
//
// Return Values
//
// --- NONE ---
//
func (ePrefNeutron *errPrefNeutron) writeCurrentLineStr(
strBuilder *strings.Builder,
ePrefLineLenCalc *EPrefixLineLenCalc) {
if ePrefNeutron.lock == nil {
ePrefNeutron.lock = new(sync.Mutex)
}
ePrefNeutron.lock.Lock()
defer ePrefNeutron.lock.Unlock()
if strBuilder == nil ||
ePrefLineLenCalc == nil ||
!ePrefLineLenCalc.IsValidInstance() {
return
}
if ePrefLineLenCalc.GetCurrLineStrLength() == 0 {
return
}
if strBuilder.Len() > 0 {
strBuilder.WriteString(
ePrefLineLenCalc.GetDelimiterNewLineErrPrefix())
}
strBuilder.WriteString(
ePrefLineLenCalc.GetCurrLineStr())
//if !ePrefLineLenCalc.IsErrPrefixLastIndex() {
// strBuilder.WriteString(
// ePrefLineLenCalc.GetDelimiterNewLineErrPrefix())
//}
ePrefLineLenCalc.SetCurrentLineStr("")
return
}